Skip to content

Commit

Permalink
Added initialization of update_id field with latest value on TokenMet…
Browse files Browse the repository at this point in the history
…adata
  • Loading branch information
k-karuna committed Sep 10, 2024
1 parent 74f2c26 commit 31197c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/storage/postgres/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func initDatabase(ctx context.Context, conn *database.Bun) error {
return err
}

return createIndices(ctx, conn)
if err := createIndices(ctx, conn); err != nil {
return err
}

return setTokenMetadataLastUpdateID(ctx, conn)
}

func createIndices(ctx context.Context, conn *database.Bun) error {
Expand Down Expand Up @@ -157,3 +161,15 @@ func applyMigrations(ctx context.Context, conn *database.Bun) error {
_, err := migrator.Migrate(ctx)
return err
}

func setTokenMetadataLastUpdateID(ctx context.Context, conn *database.Bun) error {
tokenMetadata := new(models.TokenMetadata)
err := conn.DB().NewSelect().
Model(tokenMetadata).
Order("update_id desc").
Limit(1).
Scan(ctx)

models.SetLastUpdateID(tokenMetadata.UpdateID)
return err
}
4 changes: 4 additions & 0 deletions internal/storage/token_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ func (tm *TokenMetadata) BeforeAppendModel(ctx context.Context, query bun.Query)
}
return nil
}

func SetLastUpdateID(value int64) {
TokenUpdateID.Set(value)
}

0 comments on commit 31197c2

Please sign in to comment.