sqldb: separate migration execution from construction

This commit separates the execution of SQL and in-code migrations
from their construction. This change is necessary because,
currently, the SQL schema is migrated during the construction
phase in the lncfg package. However, migrations are typically
executed when individual stores are constructed within the
configuration builder.
This commit is contained in:
Andras Banki-Horvath
2024-11-25 20:29:08 +01:00
parent b789fb2db3
commit 91c3e1496f
8 changed files with 137 additions and 57 deletions

View File

@@ -355,6 +355,18 @@ func (t *TransactionExecutor[Q]) ExecTx(ctx context.Context,
)
}
// DB is an interface that represents a generic SQL database. It provides
// methods to apply migrations and access the underlying database connection.
type DB interface {
// GetBaseDB returns the underlying BaseDB instance.
GetBaseDB() *BaseDB
// ApplyAllMigrations applies all migrations to the database including
// both sqlc and custom in-code migrations.
ApplyAllMigrations(ctx context.Context,
customMigrations []MigrationConfig) error
}
// BaseDB is the base database struct that each implementation can embed to
// gain some common functionality.
type BaseDB struct {