Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/postgres/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

const (
CREATE_DB = `CREATE DATABASE "%s"`
CREATE_SCHEMA = `CREATE SCHEMA IF NOT EXISTS "%s" AUTHORIZATION "%s"`
CREATE_SCHEMA = `CREATE SCHEMA IF NOT EXISTS "%s"`
CREATE_EXTENSION = `CREATE EXTENSION IF NOT EXISTS "%s"`
ALTER_DB_OWNER = `ALTER DATABASE "%s" OWNER TO "%s"`
ALTER_SCHEMA_OWNER = `ALTER SCHEMA "%s" OWNER TO "%s"`
DROP_DATABASE = `DROP DATABASE "%s"`
GRANT_USAGE_SCHEMA = `GRANT USAGE ON SCHEMA "%s" TO "%s"`
GRANT_ALL_TABLES = `GRANT %s ON ALL TABLES IN SCHEMA "%s" TO "%s"`
Expand Down Expand Up @@ -50,10 +51,19 @@ func (c *pg) CreateSchema(db, role, schema string, logger logr.Logger) error {
}
defer tmpDb.Close()

_, err = tmpDb.Exec(fmt.Sprintf(CREATE_SCHEMA, schema, role))
_, err = tmpDb.Exec(fmt.Sprintf(CREATE_SCHEMA, schema))
if err != nil {
return err
}

// Set the schema owner in a separate step, because AWS RDS breaks if
// you try to create a schema and set the owner in a single command.
// See: https://github.com/movetokube/postgres-operator/issues/91
_, err = c.db.Exec(fmt.Sprintf(ALTER_SCHEMA_OWNER, schema, role))
if err != nil {
return err
}

return nil
}

Expand Down