added a new sitetype for sites that need access to the pool outside of requests
Dieser Commit ist enthalten in:
Ursprung
1b64551582
Commit
0f9fded567
|
@ -132,23 +132,26 @@ func (m *Middleware) PostSetup(sites []any) (err error) {
|
|||
db *pgxpool.Pool
|
||||
)
|
||||
for _, s := range sites {
|
||||
site, ok := s.(MigrationSite)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
db, ok = m.databases[site.Database()]
|
||||
if !ok {
|
||||
return fmt.Errorf("Failed to get the database. The Databasepool %s does not exist", site.Database())
|
||||
}
|
||||
conn, err = db.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer conn.Release()
|
||||
mig, err = site.Migrations(conn.Conn())
|
||||
err = mig.Migrate(context.TODO())
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
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())
|
||||
}
|
||||
conn, err = db.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer conn.Release()
|
||||
mig, err = site.Migrations(conn.Conn())
|
||||
err = mig.Migrate(context.TODO())
|
||||
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(
|
||||
|
|
Laden…
In neuem Issue referenzieren