Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/provision-managed-postgres.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@monashcoding/db": patch
---

`mac-db provision` works on a managed Postgres whose administrator is not a superuser.
2 changes: 2 additions & 0 deletions packages/db/src/provision.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ describe("provisionStatements", () => {

expect(statements).toEqual([
`CREATE ROLE "monmap" LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION CONNECTION LIMIT 20 PASSWORD 'pw'`,
`GRANT "monmap" TO CURRENT_USER`,
`CREATE DATABASE "monmap" OWNER "monmap"`,
`REVOKE "monmap" FROM CURRENT_USER`,
`REVOKE ALL ON DATABASE "monmap" FROM PUBLIC`,
`GRANT CONNECT, TEMPORARY ON DATABASE "monmap" TO "monmap"`,
]);
Expand Down
4 changes: 4 additions & 0 deletions packages/db/src/provision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export function provisionStatements(options: ProvisionOptions): string[] {

return [
`CREATE ROLE "${app}" LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION CONNECTION LIMIT ${limit} PASSWORD ${quoteLiteral(password)}`,
// A managed server's administrator is not a superuser, and may only hand
// a database to a role it is a member of. It joins for that one statement.
`GRANT "${app}" TO CURRENT_USER`,
`CREATE DATABASE "${app}" OWNER "${app}"`,
`REVOKE "${app}" FROM CURRENT_USER`,
`REVOKE ALL ON DATABASE "${app}" FROM PUBLIC`,
`GRANT CONNECT, TEMPORARY ON DATABASE "${app}" TO "${app}"`,
];
Expand Down
Loading