restrict migrate function to the right schema, and not the entire database

This commit is contained in:
Arnaud Delcasse 2023-05-02 20:00:34 +02:00
parent c6ba00b74f
commit bac60f049f
1 changed files with 3 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import (
type PostgresqlStorage struct { type PostgresqlStorage struct {
DbConnection *sql.DB DbConnection *sql.DB
Schema string
Tables map[string]string Tables map[string]string
} }
@ -47,6 +48,7 @@ func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error) {
} }
return PostgresqlStorage{ return PostgresqlStorage{
DbConnection: db, DbConnection: db,
Schema: pg_schema,
Tables: map[string]string{ Tables: map[string]string{
"accounts": fmt.Sprintf("%s.%s", pg_schema, pgtables_accounts), "accounts": fmt.Sprintf("%s.%s", pg_schema, pgtables_accounts),
"accounts_auth_local": fmt.Sprintf("%s.%s", pg_schema, pgtables_accounts_auth_local), "accounts_auth_local": fmt.Sprintf("%s.%s", pg_schema, pgtables_accounts_auth_local),
@ -426,7 +428,7 @@ func (psql PostgresqlStorage) Migrate() error {
return err return err
} }
existing, err := driver.InspectRealm(ctx, nil) existing, err := driver.InspectRealm(ctx, &schema.InspectRealmOption{Schemas: []string{psql.Schema}})
if err != nil { if err != nil {
return err return err
} }