v0.1.15 — self-healing sunset_config migration: check schema each boot, not just setting flag

This commit is contained in:
Hendrik 2026-05-01 19:36:08 +02:00
parent 4bd76c9eda
commit 63df0fe8d6
2 changed files with 12 additions and 1 deletions

View file

@ -103,6 +103,11 @@ function setSettingDirect(db: Database.Database, key: string, value: string) {
db.prepare("INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value").run(key, value);
}
function hasColumn(db: Database.Database, table: string, col: string): boolean {
const cols = db.prepare(`PRAGMA table_info(${table})`).all() as { name: string }[];
return cols.some((c) => c.name === col);
}
function runMigrations(db: Database.Database) {
// m_301_to_302: switch existing 301-redirects to 302 so browser-cache stops eating hits.
if (getSettingDirect(db, "m_301_to_302") !== "done") {
@ -110,6 +115,12 @@ function runMigrations(db: Database.Database) {
db.prepare("UPDATE domain_groups SET redirect_code = 302 WHERE redirect_code = 301").run();
setSettingDirect(db, "m_301_to_302", "done");
}
// sunset_config column: self-healing — always check schema regardless of setting flag.
if (!hasColumn(db, "domains", "sunset_config")) {
db.exec("ALTER TABLE domains ADD COLUMN sunset_config TEXT");
}
setSettingDirect(db, "m_sunset_column", "done");
}
export function getSetting(key: string): string | null {

View file

@ -1,6 +1,6 @@
{
"name": "corex-nexredirect",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"overrides": {
"postcss": "^8.5.13",