Skip to content

Commit

Permalink
Disable migrations in API
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Nov 4, 2024
1 parent 6c0b40f commit 2742ef0
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func initDispatcher(ctx context.Context, db postgres.Storage) {
func initDatabase(cfg config.Database, viewsDir string) postgres.Storage {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
db, err := postgres.Create(ctx, cfg, viewsDir)
db, err := postgres.Create(ctx, cfg, viewsDir, false)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/quotes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
return
}

pg, err := postgres.Create(ctx, cfg.Database, cfg.Indexer.ScriptsDir)
pg, err := postgres.Create(ctx, cfg.Database, cfg.Indexer.ScriptsDir, false)
if err != nil {
log.Panic().Err(err).Msg("can't create database connection")
return
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/postgres/block_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *BlockStatsTestSuite) SetupSuite() {
Password: s.psqlContainer.Config.Password,
Host: s.psqlContainer.Config.Host,
Port: s.psqlContainer.MappedPort().Int(),
}, "../../../database")
}, "../../../database", false)
s.Require().NoError(err)
s.storage = strg

Expand Down
15 changes: 11 additions & 4 deletions internal/storage/postgres/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ type Storage struct {
}

// Create -
func Create(ctx context.Context, cfg config.Database, scriptsDir string) (Storage, error) {
strg, err := postgres.Create(ctx, cfg, initDatabase)
func Create(ctx context.Context, cfg config.Database, scriptsDir string, withMigrations bool) (Storage, error) {
init := initDatabase
if withMigrations {
init = initDatabaseWithMigrations
}
strg, err := postgres.Create(ctx, cfg, init)
if err != nil {
return Storage{}, err
}
Expand Down Expand Up @@ -145,10 +149,13 @@ func initDatabase(ctx context.Context, conn *database.Bun) error {
return errors.Wrap(err, "create hypertables")
}

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

func initDatabaseWithMigrations(ctx context.Context, conn *database.Bun) error {
if err := initDatabase(ctx, conn); err != nil {
return err
}

return migrateDatabase(ctx, conn)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/storage/postgres/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *StatsTestSuite) SetupSuite() {
Password: s.psqlContainer.Config.Password,
Host: s.psqlContainer.Config.Host,
Port: s.psqlContainer.MappedPort().Int(),
}, "../../../database")
}, "../../../database", false)
s.Require().NoError(err)
s.storage = strg

Expand Down
2 changes: 1 addition & 1 deletion internal/storage/postgres/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *StorageTestSuite) SetupSuite() {
Password: s.psqlContainer.Config.Password,
Host: s.psqlContainer.Config.Host,
Port: s.psqlContainer.MappedPort().Int(),
}, "../../../database")
}, "../../../database", false)
s.Require().NoError(err)
s.storage = strg

Expand Down
2 changes: 1 addition & 1 deletion internal/storage/postgres/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *TransactionTestSuite) SetupSuite() {
Password: s.psqlContainer.Config.Password,
Host: s.psqlContainer.Config.Host,
Port: s.psqlContainer.MappedPort().Int(),
}, "../../../database")
}, "../../../database", false)
s.Require().NoError(err)
s.storage = strg
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Indexer struct {
}

func New(ctx context.Context, cfg config.Config, stopperModule modules.Module) (Indexer, error) {
pg, err := postgres.Create(ctx, cfg.Database, cfg.Indexer.ScriptsDir)
pg, err := postgres.Create(ctx, cfg.Database, cfg.Indexer.ScriptsDir, true)
if err != nil {
return Indexer{}, errors.Wrap(err, "while creating pg context")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/indexer/rollback/rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *ModuleTestSuite) SetupSuite() {
Password: s.psqlContainer.Config.Password,
Host: s.psqlContainer.Config.Host,
Port: s.psqlContainer.MappedPort().Int(),
}, "../../../database")
}, "../../../database", false)
s.Require().NoError(err)
s.storage = st
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/indexer/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *ModuleTestSuite) SetupSuite() {
Password: s.psqlContainer.Config.Password,
Host: s.psqlContainer.Config.Host,
Port: s.psqlContainer.MappedPort().Int(),
}, "../../../database")
}, "../../../database", false)
s.Require().NoError(err)
s.storage = strg
}
Expand Down

0 comments on commit 2742ef0

Please sign in to comment.