fix: skip teardownCustomerDatabase if database no longer exists
Some checks failed
Build & Release / build (push) Has been cancelled
Some checks failed
Build & Release / build (push) Has been cancelled
This commit is contained in:
@@ -27,10 +27,12 @@ export async function setupCustomerDatabase(dbName: string, username: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function teardownCustomerDatabase(dbName: string, username: string) {
|
export async function teardownCustomerDatabase(dbName: string, username: string) {
|
||||||
// Reassign ownership back to doadmin before dropping
|
// Reassign ownership back to doadmin before dropping; skip if DB no longer exists
|
||||||
const sql = postgres(config.doadminDbUrl.replace(/\/\w+(\?|$)/, `/${dbName}$1`), { max: 1 });
|
const sql = postgres(config.doadminDbUrl.replace(/\/\w+(\?|$)/, `/${dbName}$1`), { max: 1 });
|
||||||
try {
|
try {
|
||||||
await sql.unsafe(`REASSIGN OWNED BY "${username}" TO doadmin;`);
|
await sql.unsafe(`REASSIGN OWNED BY "${username}" TO doadmin;`);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err?.code !== "3D000") throw err; // 3D000 = database does not exist
|
||||||
} finally {
|
} finally {
|
||||||
await sql.end();
|
await sql.end();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user