Commit 95de5cc7 authored by Steven's avatar Steven

refactor: update migration history methods

parent bc7decf6
...@@ -21,11 +21,15 @@ func GetCurrentVersion(mode string) string { ...@@ -21,11 +21,15 @@ func GetCurrentVersion(mode string) string {
return Version 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 { func GetMinorVersion(version string) string {
versionList := strings.Split(version, ".") versionList := strings.Split(version, ".")
if len(versionList) < 3 { if len(versionList) < 2 {
return "" return ""
} }
// Return major.minor only (first two components)
return versionList[0] + "." + versionList[1] return versionList[0] + "." + versionList[1]
} }
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"github.com/usememos/memos/store" "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) { 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" query := "SELECT `version`, UNIX_TIMESTAMP(`created_ts`) FROM `migration_history` ORDER BY `created_ts` DESC"
rows, err := d.db.QueryContext(ctx, query) rows, err := d.db.QueryContext(ctx, query)
...@@ -34,6 +36,11 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio ...@@ -34,6 +36,11 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio
return list, nil 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) { 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` = ?" stmt := "INSERT INTO `migration_history` (`version`) VALUES (?) ON DUPLICATE KEY UPDATE `version` = ?"
_, err := d.db.ExecContext(ctx, stmt, upsert.Version, upsert.Version) _, err := d.db.ExecContext(ctx, stmt, upsert.Version, upsert.Version)
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"github.com/usememos/memos/store" "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) { 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" query := "SELECT version, created_ts FROM migration_history ORDER BY created_ts DESC"
rows, err := d.db.QueryContext(ctx, query) rows, err := d.db.QueryContext(ctx, query)
...@@ -34,6 +36,8 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio ...@@ -34,6 +36,8 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio
return list, nil 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) { func (d *DB) UpsertMigrationHistory(ctx context.Context, upsert *store.UpsertMigrationHistory) (*store.MigrationHistory, error) {
stmt := ` stmt := `
INSERT INTO migration_history ( INSERT INTO migration_history (
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"github.com/usememos/memos/store" "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) { 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" query := "SELECT `version`, `created_ts` FROM `migration_history` ORDER BY `created_ts` DESC"
rows, err := d.db.QueryContext(ctx, query) rows, err := d.db.QueryContext(ctx, query)
...@@ -34,6 +36,8 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio ...@@ -34,6 +36,8 @@ func (d *DB) FindMigrationHistoryList(ctx context.Context, _ *store.FindMigratio
return list, nil 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) { func (d *DB) UpsertMigrationHistory(ctx context.Context, upsert *store.UpsertMigrationHistory) (*store.MigrationHistory, error) {
stmt := ` stmt := `
INSERT INTO migration_history ( INSERT INTO migration_history (
......
...@@ -14,6 +14,9 @@ type Driver interface { ...@@ -14,6 +14,9 @@ type Driver interface {
IsInitialized(ctx context.Context) (bool, error) IsInitialized(ctx context.Context) (bool, error)
// MigrationHistory model related methods. // 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) FindMigrationHistoryList(ctx context.Context, find *FindMigrationHistory) ([]*MigrationHistory, error)
UpsertMigrationHistory(ctx context.Context, upsert *UpsertMigrationHistory) (*MigrationHistory, error) UpsertMigrationHistory(ctx context.Context, upsert *UpsertMigrationHistory) (*MigrationHistory, error)
......
package store 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 { type MigrationHistory struct {
Version string Version string
CreatedTs int64 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 { type UpsertMigrationHistory struct {
Version string Version string
} }
// FindMigrationHistory is used to query migration history records.
// NOTE: This is deprecated along with the migration_history table.
type FindMigrationHistory struct { type FindMigrationHistory struct {
} }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment