mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-12 02:47:46 +00:00
Version correctly
This commit is contained in:
@@ -2,7 +2,7 @@ import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
// This is a placeholder value replaced by the build process
|
||||
export const APP_VERSION = "1.10.1";
|
||||
export const APP_VERSION = "1.10.2";
|
||||
|
||||
export const __FILENAME = fileURLToPath(import.meta.url);
|
||||
export const __DIRNAME = path.dirname(__FILENAME);
|
||||
|
||||
@@ -10,7 +10,7 @@ import m2 from "./scriptsPg/1.7.0";
|
||||
import m3 from "./scriptsPg/1.8.0";
|
||||
import m4 from "./scriptsPg/1.9.0";
|
||||
import m5 from "./scriptsPg/1.10.0";
|
||||
import m6 from "./scriptsPg/1.10.1";
|
||||
import m6 from "./scriptsPg/1.10.2";
|
||||
|
||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||
@@ -22,7 +22,7 @@ const migrations = [
|
||||
{ version: "1.8.0", run: m3 },
|
||||
{ version: "1.9.0", run: m4 },
|
||||
{ version: "1.10.0", run: m5 },
|
||||
{ version: "1.10.1", run: m6 },
|
||||
{ version: "1.10.2", run: m6 },
|
||||
// Add new migrations here as they are created
|
||||
] as {
|
||||
version: string;
|
||||
|
||||
@@ -28,6 +28,7 @@ import m23 from "./scriptsSqlite/1.8.0";
|
||||
import m24 from "./scriptsSqlite/1.9.0";
|
||||
import m25 from "./scriptsSqlite/1.10.0";
|
||||
import m26 from "./scriptsSqlite/1.10.1";
|
||||
import m27 from "./scriptsSqlite/1.10.2";
|
||||
|
||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||
@@ -55,6 +56,7 @@ const migrations = [
|
||||
{ version: "1.9.0", run: m24 },
|
||||
{ version: "1.10.0", run: m25 },
|
||||
{ version: "1.10.1", run: m26 },
|
||||
{ version: "1.10.2", run: m27 },
|
||||
// Add new migrations here as they are created
|
||||
] as const;
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { db } from "@server/db/pg/driver";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { __DIRNAME, APP_PATH } from "@server/lib/consts";
|
||||
import { readFileSync } from "fs";
|
||||
import path, { join } from "path";
|
||||
|
||||
const version = "1.10.1";
|
||||
const version = "1.10.2";
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
@@ -5,16 +5,16 @@ import path from "path";
|
||||
const version = "1.10.1";
|
||||
|
||||
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 db = new Database(location);
|
||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||
const db = new Database(location);
|
||||
|
||||
try {
|
||||
db.pragma("foreign_keys = OFF");
|
||||
try {
|
||||
db.pragma("foreign_keys = OFF");
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`ALTER TABLE "targets" RENAME TO "targets_old";
|
||||
db.transaction(() => {
|
||||
db.exec(`ALTER TABLE "targets" RENAME TO "targets_old";
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "targets" (
|
||||
"targetId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -57,43 +57,13 @@ SELECT
|
||||
FROM "targets_old";
|
||||
--> statement-breakpoint
|
||||
DROP TABLE "targets_old";`);
|
||||
})();
|
||||
})();
|
||||
|
||||
db.pragma("foreign_keys = ON");
|
||||
db.pragma("foreign_keys = ON");
|
||||
|
||||
const resources = db.prepare("SELECT * FROM resources").all() as Array<{
|
||||
resourceId: number;
|
||||
headers: string | null;
|
||||
}>;
|
||||
|
||||
for (const resource of resources) {
|
||||
const headers = resource.headers;
|
||||
if (headers && headers !== "") {
|
||||
// lets convert it to json
|
||||
// fist split at commas
|
||||
const headersArray = headers
|
||||
.split(",")
|
||||
.map((header: string) => {
|
||||
const [name, ...valueParts] = header.split(":");
|
||||
const value = valueParts.join(":").trim();
|
||||
return { name: name.trim(), value };
|
||||
});
|
||||
|
||||
db.prepare(
|
||||
`
|
||||
UPDATE "resources" SET "headers" = ? WHERE "resourceId" = ?
|
||||
`
|
||||
).run(JSON.stringify(headersArray), resource.resourceId);
|
||||
|
||||
console.log(
|
||||
`Updated resource ${resource.resourceId} headers to JSON format`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Migrated database`);
|
||||
} catch (e) {
|
||||
console.log("Failed to migrate db:", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
console.log(`Migrated database`);
|
||||
} catch (e) {
|
||||
console.log("Failed to migrate db:", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
54
server/setup/scriptsSqlite/1.10.2.ts
Normal file
54
server/setup/scriptsSqlite/1.10.2.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { APP_PATH } from "@server/lib/consts";
|
||||
import Database from "better-sqlite3";
|
||||
import path from "path";
|
||||
|
||||
const version = "1.10.2";
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||
const db = new Database(location);
|
||||
|
||||
const resources = db.prepare("SELECT * FROM resources").all() as Array<{
|
||||
resourceId: number;
|
||||
headers: string | null;
|
||||
}>;
|
||||
|
||||
try {
|
||||
db.pragma("foreign_keys = OFF");
|
||||
|
||||
db.transaction(() => {
|
||||
for (const resource of resources) {
|
||||
const headers = resource.headers;
|
||||
if (headers && headers !== "") {
|
||||
// lets convert it to json
|
||||
// fist split at commas
|
||||
const headersArray = headers
|
||||
.split(",")
|
||||
.map((header: string) => {
|
||||
const [name, ...valueParts] = header.split(":");
|
||||
const value = valueParts.join(":").trim();
|
||||
return { name: name.trim(), value };
|
||||
});
|
||||
|
||||
db.prepare(
|
||||
`
|
||||
UPDATE "resources" SET "headers" = ? WHERE "resourceId" = ?`
|
||||
).run(JSON.stringify(headersArray), resource.resourceId);
|
||||
|
||||
console.log(
|
||||
`Updated resource ${resource.resourceId} headers to JSON format`
|
||||
);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
db.pragma("foreign_keys = ON");
|
||||
|
||||
console.log(`Migrated database`);
|
||||
} catch (e) {
|
||||
console.log("Failed to migrate db:", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user