Skip to content

Commit

Permalink
Move migrations out of a deep function
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Aug 29, 2024
1 parent b5e99ed commit 036ed30
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/soroban-rpc/internal/db/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const (
eventsMigrationName = "EventsTable"
)

// Add new migrations here:
var CurrentMigrations = map[string]migrationApplierF{

Check failure on line 18 in cmd/soroban-rpc/internal/db/migration.go

View workflow job for this annotation

GitHub Actions / golangci-lint

CurrentMigrations is a global variable (gochecknoglobals)
transactionsMigrationName: newTransactionTableMigration,
eventsMigrationName: newEventTableMigration,
}

type LedgerSeqRange struct {
First uint32
Last uint32
Expand Down Expand Up @@ -199,6 +205,7 @@ func BuildMigrations(
ctx context.Context, logger *log.Entry, db *DB, networkPassphrase string,
ledgerSeqRange LedgerSeqRange,
) (MultiMigration, LedgerSeqRange, error) {
// Track ranges for which migrations are actually necessary
applicableRange := LedgerSeqRange{}

// Start a common db transaction for the entire migration duration
Expand All @@ -207,14 +214,8 @@ func BuildMigrations(
return MultiMigration{}, applicableRange, errors.Join(err, db.Rollback())
}

migrationNameToFunc := map[string]migrationApplierF{
transactionsMigrationName: newTransactionTableMigration,
eventsMigrationName: newEventTableMigration,
}

migrations := make([]Migration, 0, len(migrationNameToFunc))

for migrationName, migrationFunc := range migrationNameToFunc {
migrations := make([]Migration, 0, len(CurrentMigrations))
for migrationName, migrationFunc := range CurrentMigrations {
migrationLogger := logger.WithField("migration", migrationName)
factory := migrationFunc(
ctx,
Expand Down

0 comments on commit 036ed30

Please sign in to comment.