Skip to content

Commit

Permalink
Wrap schema names with quotes in Postgres
Browse files Browse the repository at this point in the history
When schemas are being created, they should be also wrapped with quotes,
like databases and extensions, to make it possible to give them names
containing dashes

Issue: #94
  • Loading branch information
allanger committed Jan 17, 2024
1 parent c8ae829 commit dcfde65
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/utils/database/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (p Postgres) dropPublicSchema(admin *DatabaseUser) error {

func (p Postgres) createSchemas(ac4tor *DatabaseUser) error {
for _, s := range p.Schemas {
createSchema := fmt.Sprintf("CREATE SCHEMA IF NOT EXISTS %s", s)
createSchema := fmt.Sprintf("CREATE SCHEMA IF NOT EXISTS \"%s\";", s)
if err := p.executeExec(p.Database, createSchema, ac4tor); err != nil {
logrus.Errorf("failed to create schema %s, %s", s, err)
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/database/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func TestPostgresNoSchemas(t *testing.T) {
func TestPostgresSchemas(t *testing.T) {
admin := getPostgresAdmin()
p, dbu := testPostgres()
p.Schemas = []string{"schema_1", "schema_2"}
p.Schemas = []string{"schema_1", "schema_2", "schema-3"}

assert.Error(t, p.checkSchemas(dbu))
assert.NoError(t, p.createSchemas(admin))
Expand Down

0 comments on commit dcfde65

Please sign in to comment.