mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 10:37:07 +00:00
Clean up if project creation fails
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user