mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-12 10:58:06 +00:00
Merge branch 'dev' of github.com:fosrl/pangolin into dev
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { __DIRNAME, APP_PATH } from "@server/lib/consts";
|
import { APP_PATH } from "@server/lib/consts";
|
||||||
import Database from "better-sqlite3";
|
import Database from "better-sqlite3";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
@@ -14,39 +14,34 @@ export default async function migration() {
|
|||||||
db.pragma("foreign_keys = OFF");
|
db.pragma("foreign_keys = OFF");
|
||||||
|
|
||||||
db.transaction(() => {
|
db.transaction(() => {
|
||||||
db.exec(`PRAGMA foreign_keys = OFF;
|
db.exec(`ALTER TABLE "targets" RENAME TO "targets_old";
|
||||||
|
--> statement-breakpoint
|
||||||
-- 1. Rename the old table
|
CREATE TABLE "targets" (
|
||||||
ALTER TABLE targets RENAME TO targets_old;
|
"targetId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"resourceId" INTEGER NOT NULL,
|
||||||
-- 2. Create the new table
|
"siteId" INTEGER NOT NULL,
|
||||||
CREATE TABLE targets (
|
"ip" TEXT NOT NULL,
|
||||||
targetId INTEGER PRIMARY KEY AUTOINCREMENT,
|
"method" TEXT,
|
||||||
resourceId INTEGER NOT NULL,
|
"port" INTEGER NOT NULL,
|
||||||
siteId INTEGER NOT NULL,
|
"internalPort" INTEGER,
|
||||||
ip TEXT NOT NULL,
|
"enabled" INTEGER NOT NULL DEFAULT 1,
|
||||||
method TEXT,
|
"path" TEXT,
|
||||||
port INTEGER NOT NULL,
|
"pathMatchType" TEXT,
|
||||||
internalPort INTEGER,
|
FOREIGN KEY ("resourceId") REFERENCES "resources"("resourceId") ON UPDATE no action ON DELETE cascade,
|
||||||
enabled INTEGER NOT NULL DEFAULT 1,
|
FOREIGN KEY ("siteId") REFERENCES "sites"("siteId") ON UPDATE no action ON DELETE cascade
|
||||||
path TEXT,
|
|
||||||
pathMatchType TEXT,
|
|
||||||
FOREIGN KEY (resourceId) REFERENCES resources(resourceId) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (siteId) REFERENCES sites(siteId) ON DELETE CASCADE
|
|
||||||
);
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
-- 3. Copy data *from the old table*
|
INSERT INTO "targets" (
|
||||||
INSERT INTO targets (
|
"targetId",
|
||||||
targetId,
|
"resourceId",
|
||||||
resourceId,
|
"siteId",
|
||||||
siteId,
|
"ip",
|
||||||
ip,
|
"method",
|
||||||
method,
|
"port",
|
||||||
port,
|
"internalPort",
|
||||||
internalPort,
|
"enabled",
|
||||||
enabled,
|
"path",
|
||||||
path,
|
"pathMatchType"
|
||||||
pathMatchType
|
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
targetId,
|
targetId,
|
||||||
@@ -59,13 +54,10 @@ SELECT
|
|||||||
enabled,
|
enabled,
|
||||||
path,
|
path,
|
||||||
pathMatchType
|
pathMatchType
|
||||||
FROM targets_old;
|
FROM "targets_old";
|
||||||
|
--> statement-breakpoint
|
||||||
-- 4. Drop the old table
|
DROP TABLE "targets_old";`);
|
||||||
DROP TABLE targets_old;
|
})();
|
||||||
|
|
||||||
PRAGMA foreign_keys = ON;`);
|
|
||||||
});
|
|
||||||
|
|
||||||
db.pragma("foreign_keys = ON");
|
db.pragma("foreign_keys = ON");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user