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,10 +132,9 @@ func (m *Middleware) PostSetup(sites []any) (err error) {
|
||||||
db *pgxpool.Pool
|
db *pgxpool.Pool
|
||||||
)
|
)
|
||||||
for _, s := range sites {
|
for _, s := range sites {
|
||||||
site, ok := s.(MigrationSite)
|
|
||||||
if !ok {
|
if site, ok := s.(MigrationSite); ok {
|
||||||
continue
|
|
||||||
}
|
|
||||||
db, ok = m.databases[site.Database()]
|
db, ok = m.databases[site.Database()]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Failed to get the database. The Databasepool %s does not exist", site.Database())
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if poolsite, ok := s.(PoolSite); ok {
|
||||||
|
poolsite.Pool(m.databases[site.Database()])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -165,6 +168,12 @@ type MigrationSite interface {
|
||||||
Migrations(*pgx.Conn) (*migrate.Migrator, error)
|
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.
|
// SetupMigrator sets up the migrator to migrate the database.
|
||||||
func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *migrate.Migrator, err error) {
|
func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *migrate.Migrator, err error) {
|
||||||
mig, err = migrate.NewMigratorEx(
|
mig, err = migrate.NewMigratorEx(
|
||||||
|
|
Laden…
In neuem Issue referenzieren