feat(migration): settings migration from old app all is now in the new app

This commit is contained in:
2025-11-24 15:22:12 -06:00
parent 90920e8fba
commit 40bc19aa6f
6 changed files with 248 additions and 110 deletions

View File

@@ -1,5 +1,8 @@
import { Client } from "pg";
import { db } from "../../../pkg/db/db.js";
import { type NewSetting, settings } from "../../../pkg/db/schema/settings.js";
import { createLogger } from "../../../pkg/logger/logger.js";
import { tryCatch } from "../../../pkg/utils/tryCatch.js";
export const addListeners = async () => {
const log = createLogger({ module: "utils", subModule: "listeners" });
@@ -60,6 +63,7 @@ export const addListeners = async () => {
}
};
// all the migration stuff that will need to be moved later build 230 and above will need to remove
export const manualFixes = async () => {
const fixQuery = `ALTER TABLE "serverData" ADD CONSTRAINT "serverData_name_unique" UNIQUE("name");`;
@@ -77,3 +81,48 @@ export const manualFixes = async () => {
log.info({ error: e }, "Fix was not completed");
}
};
export const settingsMigrate = async () => {
const log = createLogger({ module: "utils", subModule: "v1Migration" });
const client = new Client({
connectionString: process.env.DATABASE_URL_V1,
});
await client.connect();
let settingsV1: NewSetting[] = [];
try {
log.info({}, "Running the manual fix");
const s = await client.query("SELECT * FROM settings");
settingsV1 = s.rows.map((i) => {
return {
name: i.name,
value: i.value,
description: i.description,
moduleName: i.moduleName,
};
});
} catch (e) {
log.error({ error: e }, "There was an error getting the settings.");
}
const { data, error } = await tryCatch(
db
.insert(settings)
.values(settingsV1)
.onConflictDoNothing()
.returning({ name: settings.name }),
);
if (error) {
log.error({ error }, "There was an error adding new settings");
}
if (data) {
log.info({ newSettingsAdded: data }, "New settings added");
}
};
// migrations after 230 go below here so we can keep this inline.