Skip to content

Commit 6c5f6de

Browse files
committed
infra: keep shared-cluster database ownership on admin
Create or reuse lane-scoped databases on the managed cluster without transferring ownership to lane-specific roles, and grant access instead so dev deploys stay compatible with DigitalOcean Postgres. Made-with: Cursor
1 parent 0300ea8 commit 6c5f6de

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

infra/global/helpers/datastore/SharedClusterPostgres.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,16 @@ async function ensureDatabase(inputs: SharedClusterDatabaseInputs): Promise<void
109109
await withClient(inputs, async (client) => {
110110
const existingDatabase = await client.query("select 1 from pg_database where datname = $1", [inputs.databaseName]);
111111

112-
if (existingDatabase.rowCount && existingDatabase.rowCount > 0) {
112+
if (!existingDatabase.rowCount || existingDatabase.rowCount === 0) {
113113
await client.query(
114-
`ALTER DATABASE ${quoteIdentifier(inputs.databaseName)} OWNER TO ${quoteIdentifier(inputs.ownerRole)}`,
114+
`CREATE DATABASE ${quoteIdentifier(inputs.databaseName)}`,
115115
);
116-
return;
117116
}
118117

118+
// Managed Postgres roles cannot reliably take ownership transfers from the admin login,
119+
// so keep the database owned by the bootstrap user and grant the lane-scoped role access.
119120
await client.query(
120-
`CREATE DATABASE ${quoteIdentifier(inputs.databaseName)} OWNER ${quoteIdentifier(inputs.ownerRole)}`,
121+
`GRANT ALL PRIVILEGES ON DATABASE ${quoteIdentifier(inputs.databaseName)} TO ${quoteIdentifier(inputs.ownerRole)}`,
121122
);
122123
});
123124
}

0 commit comments

Comments
 (0)