Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
9628d3de
Commit
9628d3de
authored
Mar 01, 2026
by
Johnny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: detect legacy installations with empty schema version
parent
7c1defba
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
31 deletions
+31
-31
migrator.go
store/migrator.go
+31
-31
No files found.
store/migrator.go
View file @
9628d3de
...
...
@@ -84,14 +84,10 @@ func shouldApplyMigration(fileVersion, currentDBVersion, targetVersion string) b
// validateMigrationFileName checks if a migration file follows the expected naming convention.
// Expected format: "NN__description.sql" where NN is a zero-padded number.
func
validateMigrationFileName
(
filename
string
)
error
{
if
!
strings
.
Contains
(
filename
,
MigrateFileNameSplit
)
{
return
errors
.
Errorf
(
"invalid migration filename format (missing %s): %s"
,
MigrateFileNameSplit
,
filename
)
}
parts
:=
strings
.
Split
(
filename
,
MigrateFileNameSplit
)
parts
:=
strings
.
SplitN
(
filename
,
MigrateFileNameSplit
,
2
)
if
len
(
parts
)
<
2
{
return
errors
.
Errorf
(
"invalid migration filename format
: %s"
,
filename
)
return
errors
.
Errorf
(
"invalid migration filename format
(missing %s): %s"
,
MigrateFileNameSplit
,
filename
)
}
// Check if first part is a number
if
_
,
err
:=
strconv
.
Atoi
(
parts
[
0
]);
err
!=
nil
{
return
errors
.
Errorf
(
"migration filename must start with a number: %s"
,
filename
)
}
...
...
@@ -122,7 +118,7 @@ func (s *Store) Migrate(ctx context.Context) error {
)
return
errors
.
Errorf
(
"cannot downgrade schema version from %s to %s"
,
instanceBasicSetting
.
SchemaVersion
,
currentSchemaVersion
)
}
// Apply migrations if needed
(including when schema version is empty)
// Apply migrations if needed
.
if
isVersionEmpty
(
instanceBasicSetting
.
SchemaVersion
)
||
version
.
IsVersionGreaterThan
(
currentSchemaVersion
,
instanceBasicSetting
.
SchemaVersion
)
{
if
err
:=
s
.
applyMigrations
(
ctx
,
instanceBasicSetting
.
SchemaVersion
,
currentSchemaVersion
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to apply migrations"
)
...
...
@@ -254,6 +250,7 @@ func (s *Store) preMigrate(ctx context.Context) error {
}
return
nil
}
func
(
s
*
Store
)
getMigrationBasePath
()
string
{
return
fmt
.
Sprintf
(
"migration/%s/"
,
s
.
profile
.
Driver
)
}
...
...
@@ -370,18 +367,27 @@ func (s *Store) checkMinimumUpgradeVersion(ctx context.Context) error {
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get instance basic setting"
)
}
schemaVersion
:=
instanceBasicSetting
.
SchemaVersion
//
If schema version is >= 0.22.0, the installation is up-to-date
//
Modern installation: nothing to check.
if
!
isVersionEmpty
(
schemaVersion
)
&&
version
.
IsVersionGreaterOrEqualThan
(
schemaVersion
,
"0.22.0"
)
{
return
nil
}
// If schema version is set but < 0.22.0, this is an old installation
if
!
isVersionEmpty
(
schemaVersion
)
&&
!
version
.
IsVersionGreaterOrEqualThan
(
schemaVersion
,
"0.22.0"
)
{
currentVersion
,
_
:=
s
.
GetCurrentSchemaVersion
()
// Schema version is empty for fresh installs too, but preMigrate sets it before we get here.
// So empty schema version on an initialized DB means a pre-v0.22 legacy installation.
if
isVersionEmpty
(
schemaVersion
)
{
initialized
,
err
:=
s
.
driver
.
IsInitialized
(
ctx
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to check if database is initialized"
)
}
if
!
initialized
{
return
nil
}
}
// schemaVersion is either set but < 0.22.0, or empty on an initialized (legacy) DB.
currentVersion
,
_
:=
s
.
GetCurrentSchemaVersion
()
return
errors
.
Errorf
(
"Your Memos installation is too old to upgrade directly.
\n\n
"
+
"Your current version: %s
\n
"
+
...
...
@@ -396,10 +402,4 @@ func (s *Store) checkMinimumUpgradeVersion(ctx context.Context) error {
schemaVersion
,
currentVersion
,
)
}
// Schema version is empty - this is either a fresh install or corrupted installation
// Fresh installs will have schema version set immediately after LATEST.sql is applied
// So this should not be an issue in normal operation
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment