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
95de5cc7
Commit
95de5cc7
authored
Oct 20, 2025
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: update migration history methods
parent
bc7decf6
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
208 additions
and
49 deletions
+208
-49
version.go
internal/version/version.go
+5
-1
migration_history.go
store/db/mysql/migration_history.go
+7
-0
migration_history.go
store/db/postgres/migration_history.go
+4
-0
migration_history.go
store/db/sqlite/migration_history.go
+4
-0
driver.go
store/driver.go
+3
-0
migration_history.go
store/migration_history.go
+8
-0
migrator.go
store/migrator.go
+177
-48
No files found.
internal/version/version.go
View file @
95de5cc7
...
...
@@ -21,11 +21,15 @@ func GetCurrentVersion(mode string) string {
return
Version
}
// GetMinorVersion extracts the minor version (e.g., "0.25") from a full version string (e.g., "0.25.1").
// Returns the minor version string or empty string if the version format is invalid.
// Version format should be "major.minor.patch" (e.g., "0.25.1").
func
GetMinorVersion
(
version
string
)
string
{
versionList
:=
strings
.
Split
(
version
,
"."
)
if
len
(
versionList
)
<
3
{
if
len
(
versionList
)
<
2
{
return
""
}
// Return major.minor only (first two components)
return
versionList
[
0
]
+
"."
+
versionList
[
1
]
}
...
...
store/db/mysql/migration_history.go
View file @
95de5cc7
...
...
@@ -6,6 +6,8 @@ import (
"github.com/usememos/memos/store"
)
// FindMigrationHistoryList retrieves all migration history records.
// NOTE: This method is deprecated along with the migration_history table.
func
(
d
*
DB
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
_
*
store
.
FindMigrationHistory
)
([]
*
store
.
MigrationHistory
,
error
)
{
query
:=
"SELECT `version`, UNIX_TIMESTAMP(`created_ts`) FROM `migration_history` ORDER BY `created_ts` DESC"
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
)
...
...
@@ -34,6 +36,11 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio
return
list
,
nil
}
// UpsertMigrationHistory inserts or updates a migration history record.
// NOTE: This method is deprecated along with the migration_history table.
// This uses separate INSERT and SELECT queries instead of INSERT...RETURNING because
// MySQL doesn't support RETURNING clause in the same way as PostgreSQL/SQLite.
// This could have race conditions but is acceptable for deprecated transition code.
func
(
d
*
DB
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
store
.
UpsertMigrationHistory
)
(
*
store
.
MigrationHistory
,
error
)
{
stmt
:=
"INSERT INTO `migration_history` (`version`) VALUES (?) ON DUPLICATE KEY UPDATE `version` = ?"
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
upsert
.
Version
,
upsert
.
Version
)
...
...
store/db/postgres/migration_history.go
View file @
95de5cc7
...
...
@@ -6,6 +6,8 @@ import (
"github.com/usememos/memos/store"
)
// FindMigrationHistoryList retrieves all migration history records.
// NOTE: This method is deprecated along with the migration_history table.
func
(
d
*
DB
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
_
*
store
.
FindMigrationHistory
)
([]
*
store
.
MigrationHistory
,
error
)
{
query
:=
"SELECT version, created_ts FROM migration_history ORDER BY created_ts DESC"
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
)
...
...
@@ -34,6 +36,8 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio
return
list
,
nil
}
// UpsertMigrationHistory inserts or updates a migration history record.
// NOTE: This method is deprecated along with the migration_history table.
func
(
d
*
DB
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
store
.
UpsertMigrationHistory
)
(
*
store
.
MigrationHistory
,
error
)
{
stmt
:=
`
INSERT INTO migration_history (
...
...
store/db/sqlite/migration_history.go
View file @
95de5cc7
...
...
@@ -6,6 +6,8 @@ import (
"github.com/usememos/memos/store"
)
// FindMigrationHistoryList retrieves all migration history records.
// NOTE: This method is deprecated along with the migration_history table.
func
(
d
*
DB
)
FindMigrationHistoryList
(
ctx
context
.
Context
,
_
*
store
.
FindMigrationHistory
)
([]
*
store
.
MigrationHistory
,
error
)
{
query
:=
"SELECT `version`, `created_ts` FROM `migration_history` ORDER BY `created_ts` DESC"
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
)
...
...
@@ -34,6 +36,8 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio
return
list
,
nil
}
// UpsertMigrationHistory inserts or updates a migration history record.
// NOTE: This method is deprecated along with the migration_history table.
func
(
d
*
DB
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
store
.
UpsertMigrationHistory
)
(
*
store
.
MigrationHistory
,
error
)
{
stmt
:=
`
INSERT INTO migration_history (
...
...
store/driver.go
View file @
95de5cc7
...
...
@@ -14,6 +14,9 @@ type Driver interface {
IsInitialized
(
ctx
context
.
Context
)
(
bool
,
error
)
// MigrationHistory model related methods.
// NOTE: These methods are deprecated. The migration_history table is no longer used
// for tracking schema versions. Schema version is now stored in workspace_setting.
// These methods are kept for backward compatibility to migrate existing installations.
FindMigrationHistoryList
(
ctx
context
.
Context
,
find
*
FindMigrationHistory
)
([]
*
MigrationHistory
,
error
)
UpsertMigrationHistory
(
ctx
context
.
Context
,
upsert
*
UpsertMigrationHistory
)
(
*
MigrationHistory
,
error
)
...
...
store/migration_history.go
View file @
95de5cc7
package
store
// MigrationHistory represents a record in the migration_history table.
// NOTE: The migration_history table is deprecated in favor of storing schema version
// in workspace_setting (BASIC setting). This is kept for backward compatibility only.
// Migration from migration_history to workspace_setting happens automatically during startup.
type
MigrationHistory
struct
{
Version
string
CreatedTs
int64
}
// UpsertMigrationHistory is used to insert or update a migration history record.
// NOTE: This is deprecated along with the migration_history table.
type
UpsertMigrationHistory
struct
{
Version
string
}
// FindMigrationHistory is used to query migration history records.
// NOTE: This is deprecated along with the migration_history table.
type
FindMigrationHistory
struct
{
}
store/migrator.go
View file @
95de5cc7
This diff is collapsed.
Click to expand it.
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