diff --git a/postgresql/resource_postgresql_schema.go b/postgresql/resource_postgresql_schema.go index 508fbc33..a8e4d510 100644 --- a/postgresql/resource_postgresql_schema.go +++ b/postgresql/resource_postgresql_schema.go @@ -118,6 +118,27 @@ func resourcePostgreSQLSchema() *schema.Resource { func resourcePostgreSQLSchemaCreate(db *DBConnection, d *schema.ResourceData) error { database := getDatabase(d, db.client.databaseName) + + // Try without roles workaround first + txn1, err := startTransaction(db.client, database) + if err != nil { + return err + } + attemptErr := createSchema(db, txn1, d) + if attemptErr == nil { + if err := txn1.Commit(); err == nil { + // Creating worked so we return here + d.SetId(generateSchemaID(d, database)) + + return resourcePostgreSQLSchemaReadImpl(db, d) + } + } + + if err := txn1.Rollback(); err != nil && err != sql.ErrTxDone { + return fmt.Errorf("error rolling back initial schema transaction: %w", err) + } + + // Creating without workaround failed so we fallback to use it. txn, err := startTransaction(db.client, database) if err != nil { return err