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,52 +1,47 @@
|
|||||||
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";
|
||||||
|
|
||||||
const version = "1.10.1";
|
const version = "1.10.1";
|
||||||
|
|
||||||
export default async function migration() {
|
export default async function migration() {
|
||||||
console.log(`Running setup script ${version}...`);
|
console.log(`Running setup script ${version}...`);
|
||||||
|
|
||||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||||
const db = new Database(location);
|
const db = new Database(location);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
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,19 +54,16 @@ SELECT
|
|||||||
enabled,
|
enabled,
|
||||||
path,
|
path,
|
||||||
pathMatchType
|
pathMatchType
|
||||||
FROM targets_old;
|
FROM "targets_old";
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP TABLE "targets_old";`);
|
||||||
|
})();
|
||||||
|
|
||||||
-- 4. Drop the old table
|
db.pragma("foreign_keys = ON");
|
||||||
DROP TABLE targets_old;
|
|
||||||
|
|
||||||
PRAGMA foreign_keys = ON;`);
|
console.log(`Migrated database`);
|
||||||
});
|
} catch (e) {
|
||||||
|
console.log("Failed to migrate db:", e);
|
||||||
db.pragma("foreign_keys = ON");
|
throw e;
|
||||||
|
}
|
||||||
console.log(`Migrated database`);
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Failed to migrate db:", e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user