mirror of
https://github.com/usememos/memos.git
synced 2025-03-04 01:04:38 +08:00
chore: move version
pkg to server/version
This commit is contained in:
parent
76801dfa4f
commit
707d1a96eb
3 changed files with 8 additions and 8 deletions
|
@ -7,7 +7,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/usememos/memos/common"
|
"github.com/usememos/memos/server/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Profile is the configuration to start main server.
|
// Profile is the configuration to start main server.
|
||||||
|
@ -68,7 +68,7 @@ func GetProfile() (*Profile, error) {
|
||||||
|
|
||||||
profile.Data = dataDir
|
profile.Data = dataDir
|
||||||
profile.DSN = fmt.Sprintf("%s/memos_%s.db", dataDir, profile.Mode)
|
profile.DSN = fmt.Sprintf("%s/memos_%s.db", dataDir, profile.Mode)
|
||||||
profile.Version = common.GetCurrentVersion(profile.Mode)
|
profile.Version = version.GetCurrentVersion(profile.Mode)
|
||||||
|
|
||||||
return &profile, nil
|
return &profile, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
||||||
var Version = "0.4.3"
|
var Version = "0.4.3"
|
||||||
|
|
||||||
// DevVersion is the service current development version.
|
// DevVersion is the service current development version.
|
||||||
var DevVersion = "0.4.3"
|
var DevVersion = "0.5.0"
|
||||||
|
|
||||||
func GetCurrentVersion(mode string) string {
|
func GetCurrentVersion(mode string) string {
|
||||||
if mode == "dev" {
|
if mode == "dev" {
|
|
@ -12,8 +12,8 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/usememos/memos/common"
|
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/server/profile"
|
||||||
|
"github.com/usememos/memos/server/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed migration
|
//go:embed migration
|
||||||
|
@ -70,7 +70,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
|
||||||
return fmt.Errorf("failed to create migration_history table: %w", err)
|
return fmt.Errorf("failed to create migration_history table: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentVersion := common.GetCurrentVersion(db.profile.Mode)
|
currentVersion := version.GetCurrentVersion(db.profile.Mode)
|
||||||
migrationHistory, err := db.FindMigrationHistory(ctx, &MigrationHistoryFind{})
|
migrationHistory, err := db.FindMigrationHistory(ctx, &MigrationHistoryFind{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -84,7 +84,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.IsVersionGreaterThan(common.GetSchemaVersion(currentVersion), migrationHistory.Version) {
|
if version.IsVersionGreaterThan(version.GetSchemaVersion(currentVersion), migrationHistory.Version) {
|
||||||
minorVersionList := getMinorVersionList()
|
minorVersionList := getMinorVersionList()
|
||||||
|
|
||||||
// backup the raw database file before migration
|
// backup the raw database file before migration
|
||||||
|
@ -101,7 +101,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
|
||||||
println("start migrate")
|
println("start migrate")
|
||||||
for _, minorVersion := range minorVersionList {
|
for _, minorVersion := range minorVersionList {
|
||||||
normalizedVersion := minorVersion + ".0"
|
normalizedVersion := minorVersion + ".0"
|
||||||
if common.IsVersionGreaterThan(normalizedVersion, migrationHistory.Version) && common.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) {
|
if version.IsVersionGreaterThan(normalizedVersion, migrationHistory.Version) && version.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) {
|
||||||
println("applying migration for", normalizedVersion)
|
println("applying migration for", normalizedVersion)
|
||||||
if err := db.applyMigrationForMinorVersion(ctx, minorVersion); err != nil {
|
if err := db.applyMigrationForMinorVersion(ctx, minorVersion); err != nil {
|
||||||
return fmt.Errorf("failed to apply minor version migration: %w", err)
|
return fmt.Errorf("failed to apply minor version migration: %w", err)
|
||||||
|
|
Loading…
Reference in a new issue