Clean up if project creation fails

This commit is contained in:
D. Berge
2023-08-30 13:41:28 +02:00
parent ddbcb90c1f
commit 1e593e6d75

View File

@@ -99,6 +99,17 @@ async function createProjectSchema (projectDefinition) {
}
}
async function dropProjectSchema (projectDefinition) {
const sql = `
DROP SCHEMA ${projectDefinition.schema} CASCADE;
`;
try {
return await pool.query(sql);
} catch (err) {
console.error("dropProjectSchema", err);
}
}
async function addProjectToList (projectDefinition) {
const sql = `
INSERT INTO public.projects (pid, name, schema, meta) VALUES (LOWER($1), $2, $3, $4);
@@ -135,6 +146,7 @@ async function create (projectDefinition) {
await addProjectToList(projectDefinition);
} catch (err) {
DEBUG(err);
await dropProjectSchema(projectDefinition);
throw { status: 500, message: err.message ?? "Failed to create database for new project", detail: err.detail }
}
}