mirror of
https://github.com/usememos/memos.git
synced 2024-11-28 05:53:14 +03:00
fix: sort version (#914)
This commit is contained in:
parent
46c13a4b7f
commit
e2e8130f4c
@ -157,6 +157,9 @@ func (s *Server) createUserAuthSignInActivity(c echo.Context, user *api.User) er
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
s.Collector.Collect(ctx, &metric.Metric{
|
||||
Name: string(activity.Type),
|
||||
})
|
||||
@ -179,6 +182,9 @@ func (s *Server) createUserAuthSignUpActivity(c echo.Context, user *api.User) er
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
s.Collector.Collect(ctx, &metric.Metric{
|
||||
Name: string(activity.Type),
|
||||
})
|
||||
|
@ -583,6 +583,9 @@ func (s *Server) createMemoCreateActivity(c echo.Context, memo *api.Memo) error
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
s.Collector.Collect(ctx, &metric.Metric{
|
||||
Name: string(activity.Type),
|
||||
})
|
||||
|
@ -299,6 +299,9 @@ func (s *Server) createResourceCreateActivity(c echo.Context, resource *api.Reso
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
s.Collector.Collect(ctx, &metric.Metric{
|
||||
Name: string(activity.Type),
|
||||
})
|
||||
|
@ -146,6 +146,9 @@ func (s *Server) createServerStartActivity(ctx context.Context) error {
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
s.Collector.Collect(ctx, &metric.Metric{
|
||||
Name: string(activity.Type),
|
||||
})
|
||||
|
@ -175,11 +175,14 @@ func (s *Server) createShortcutCreateActivity(c echo.Context, shortcut *api.Shor
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal activity payload")
|
||||
}
|
||||
_, err = s.Store.CreateActivity(ctx, &api.ActivityCreate{
|
||||
activity, err := s.Store.CreateActivity(ctx, &api.ActivityCreate{
|
||||
CreatorID: shortcut.CreatorID,
|
||||
Type: api.ActivityShortcutCreate,
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -165,11 +165,14 @@ func (s *Server) createTagCreateActivity(c echo.Context, tag *api.Tag) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal activity payload")
|
||||
}
|
||||
_, err = s.Store.CreateActivity(ctx, &api.ActivityCreate{
|
||||
activity, err := s.Store.CreateActivity(ctx, &api.ActivityCreate{
|
||||
CreatorID: tag.CreatorID,
|
||||
Type: api.ActivityTagCreate,
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -296,6 +296,9 @@ func (s *Server) createUserCreateActivity(c echo.Context, user *api.User) error
|
||||
Level: api.ActivityInfo,
|
||||
Payload: string(payloadStr),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
s.Collector.Collect(ctx, &metric.Metric{
|
||||
Name: string(activity.Type),
|
||||
})
|
||||
|
@ -68,11 +68,11 @@ func (db *DB) Open(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
currentVersion := version.GetCurrentVersion(db.profile.Mode)
|
||||
migrationHistory, err := db.FindMigrationHistory(ctx, &MigrationHistoryFind{})
|
||||
migrationHistoryList, err := db.FindMigrationHistoryList(ctx, &MigrationHistoryFind{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find migration history, err: %w", err)
|
||||
}
|
||||
if migrationHistory == nil {
|
||||
if len(migrationHistoryList) == 0 {
|
||||
if _, err = db.UpsertMigrationHistory(ctx, &MigrationHistoryUpsert{
|
||||
Version: currentVersion,
|
||||
}); err != nil {
|
||||
@ -80,8 +80,14 @@ func (db *DB) Open(ctx context.Context) (err error) {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
migrationHistoryVersionList := []string{}
|
||||
for _, migrationHistory := range migrationHistoryList {
|
||||
migrationHistoryVersionList = append(migrationHistoryVersionList, migrationHistory.Version)
|
||||
}
|
||||
sort.Strings(migrationHistoryVersionList)
|
||||
latestMigrationHistoryVersion := migrationHistoryVersionList[0]
|
||||
|
||||
if version.IsVersionGreaterThan(version.GetSchemaVersion(currentVersion), migrationHistory.Version) {
|
||||
if version.IsVersionGreaterThan(version.GetSchemaVersion(currentVersion), latestMigrationHistoryVersion) {
|
||||
minorVersionList := getMinorVersionList()
|
||||
|
||||
// backup the raw database file before migration
|
||||
@ -98,7 +104,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
|
||||
println("start migrate")
|
||||
for _, minorVersion := range minorVersionList {
|
||||
normalizedVersion := minorVersion + ".0"
|
||||
if version.IsVersionGreaterThan(normalizedVersion, migrationHistory.Version) && version.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) {
|
||||
if version.IsVersionGreaterThan(normalizedVersion, latestMigrationHistoryVersion) && version.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) {
|
||||
println("applying migration for", normalizedVersion)
|
||||
if err := db.applyMigrationForMinorVersion(ctx, minorVersion); err != nil {
|
||||
return fmt.Errorf("failed to apply minor version migration: %w", err)
|
||||
|
@ -19,7 +19,7 @@ type MigrationHistoryFind struct {
|
||||
Version *string
|
||||
}
|
||||
|
||||
func (db *DB) FindMigrationHistory(ctx context.Context, find *MigrationHistoryFind) (*MigrationHistory, error) {
|
||||
func (db *DB) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*MigrationHistory, error) {
|
||||
tx, err := db.DBInstance.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -31,12 +31,7 @@ func (db *DB) FindMigrationHistory(ctx context.Context, find *MigrationHistoryFi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(list) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
migrationHistory := list[0]
|
||||
return migrationHistory, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (db *DB) UpsertMigrationHistory(ctx context.Context, upsert *MigrationHistoryUpsert) (*MigrationHistory, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user