mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-12 10:58:06 +00:00
Add transaction
This commit is contained in:
@@ -7,7 +7,9 @@ export default async function migration() {
|
|||||||
console.log(`Running setup script ${version}...`);
|
console.log(`Running setup script ${version}...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.execute(sql`
|
await db.execute(sql`
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
CREATE TABLE "clientSites" (
|
CREATE TABLE "clientSites" (
|
||||||
"clientId" integer NOT NULL,
|
"clientId" integer NOT NULL,
|
||||||
"siteId" integer NOT NULL,
|
"siteId" integer NOT NULL,
|
||||||
@@ -106,6 +108,8 @@ export default async function migration() {
|
|||||||
ALTER TABLE "userClients" ADD CONSTRAINT "userClients_clientId_clients_id_fk" FOREIGN KEY ("clientId") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;
|
ALTER TABLE "userClients" ADD CONSTRAINT "userClients_clientId_clients_id_fk" FOREIGN KEY ("clientId") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;
|
||||||
ALTER TABLE "webauthnChallenge" ADD CONSTRAINT "webauthnChallenge_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
|
ALTER TABLE "webauthnChallenge" ADD CONSTRAINT "webauthnChallenge_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
|
||||||
ALTER TABLE "resources" DROP COLUMN "isBaseDomain";
|
ALTER TABLE "resources" DROP COLUMN "isBaseDomain";
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
`);
|
`);
|
||||||
|
|
||||||
console.log(`Migrated database schema`);
|
console.log(`Migrated database schema`);
|
||||||
@@ -116,6 +120,8 @@ export default async function migration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await db.execute(sql`BEGIN`);
|
||||||
|
|
||||||
// Update all existing orgs to have the default subnet
|
// Update all existing orgs to have the default subnet
|
||||||
await db.execute(sql`UPDATE "orgs" SET "subnet" = '100.90.128.0/24'`);
|
await db.execute(sql`UPDATE "orgs" SET "subnet" = '100.90.128.0/24'`);
|
||||||
|
|
||||||
@@ -144,8 +150,10 @@ export default async function migration() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await db.execute(sql`COMMIT`);
|
||||||
console.log(`Updated org subnets and site addresses`);
|
console.log(`Updated org subnets and site addresses`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
await db.execute(sql`ROLLBACK`);
|
||||||
console.log("Unable to update org subnets");
|
console.log("Unable to update org subnets");
|
||||||
console.log(e);
|
console.log(e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
Reference in New Issue
Block a user