Version correctly

This commit is contained in:
Owen
2025-09-21 20:48:13 -04:00
parent dadd1e3101
commit 0da95cbdb8
6 changed files with 75 additions and 51 deletions

View File

@@ -2,7 +2,7 @@ import path from "path";
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
// This is a placeholder value replaced by the build process // 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 __FILENAME = fileURLToPath(import.meta.url);
export const __DIRNAME = path.dirname(__FILENAME); export const __DIRNAME = path.dirname(__FILENAME);

View File

@@ -10,7 +10,7 @@ import m2 from "./scriptsPg/1.7.0";
import m3 from "./scriptsPg/1.8.0"; import m3 from "./scriptsPg/1.8.0";
import m4 from "./scriptsPg/1.9.0"; import m4 from "./scriptsPg/1.9.0";
import m5 from "./scriptsPg/1.10.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 // THIS CANNOT IMPORT ANYTHING FROM THE SERVER
// EXCEPT FOR THE DATABASE AND THE SCHEMA // EXCEPT FOR THE DATABASE AND THE SCHEMA
@@ -22,7 +22,7 @@ const migrations = [
{ version: "1.8.0", run: m3 }, { version: "1.8.0", run: m3 },
{ version: "1.9.0", run: m4 }, { version: "1.9.0", run: m4 },
{ version: "1.10.0", run: m5 }, { 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 // Add new migrations here as they are created
] as { ] as {
version: string; version: string;

View File

@@ -28,6 +28,7 @@ import m23 from "./scriptsSqlite/1.8.0";
import m24 from "./scriptsSqlite/1.9.0"; import m24 from "./scriptsSqlite/1.9.0";
import m25 from "./scriptsSqlite/1.10.0"; import m25 from "./scriptsSqlite/1.10.0";
import m26 from "./scriptsSqlite/1.10.1"; import m26 from "./scriptsSqlite/1.10.1";
import m27 from "./scriptsSqlite/1.10.2";
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER // THIS CANNOT IMPORT ANYTHING FROM THE SERVER
// EXCEPT FOR THE DATABASE AND THE SCHEMA // EXCEPT FOR THE DATABASE AND THE SCHEMA
@@ -55,6 +56,7 @@ const migrations = [
{ version: "1.9.0", run: m24 }, { version: "1.9.0", run: m24 },
{ version: "1.10.0", run: m25 }, { version: "1.10.0", run: m25 },
{ version: "1.10.1", run: m26 }, { version: "1.10.1", run: m26 },
{ version: "1.10.2", run: m27 },
// Add new migrations here as they are created // Add new migrations here as they are created
] as const; ] as const;

View File

@@ -1,10 +1,8 @@
import { db } from "@server/db/pg/driver"; import { db } from "@server/db/pg/driver";
import { sql } from "drizzle-orm"; import { sql } from "drizzle-orm";
import { __DIRNAME, APP_PATH } from "@server/lib/consts"; 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() { export default async function migration() {
console.log(`Running setup script ${version}...`); console.log(`Running setup script ${version}...`);

View File

@@ -61,36 +61,6 @@ 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`); console.log(`Migrated database`);
} catch (e) { } catch (e) {
console.log("Failed to migrate db:", e); console.log("Failed to migrate db:", e);

View 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;
}
}