1
0
Fork 0

added a new sitetype for sites that need access to the pool outside of requests

Dieser Commit ist enthalten in:
Sebastian Tobie 2022-11-14 10:37:23 +01:00
Ursprung 1b64551582
Commit 0f9fded567
1 geänderte Dateien mit 26 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -132,10 +132,9 @@ func (m *Middleware) PostSetup(sites []any) (err error) {
db *pgxpool.Pool
)
for _, s := range sites {
site, ok := s.(MigrationSite)
if !ok {
continue
}
if site, ok := s.(MigrationSite); ok {
db, ok = m.databases[site.Database()]
if !ok {
return fmt.Errorf("Failed to get the database. The Databasepool %s does not exist", site.Database())
@ -150,6 +149,10 @@ func (m *Middleware) PostSetup(sites []any) (err error) {
if err != nil {
return
}
if poolsite, ok := s.(PoolSite); ok {
poolsite.Pool(m.databases[site.Database()])
}
}
}
return
}
@ -165,6 +168,12 @@ type MigrationSite interface {
Migrations(*pgx.Conn) (*migrate.Migrator, error)
}
// PoolSite is an interface for site that need access to the pool outside of requests
type PoolSite interface {
MigrationSite
Pool(*pgxpool.Pool)
}
// SetupMigrator sets up the migrator to migrate the database.
func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *migrate.Migrator, err error) {
mig, err = migrate.NewMigratorEx(