Fix database schema: add group_id to CREATE TABLE instead of separate migration

This commit is contained in:
nmemmert committed 2025-12-10 12:15:44 -05:00
1 parent ec9362e14f
commit 117f815e58
1 file changed
+4 -2
+4 -2
View File
@@ -20,6 +20,7 @@ db.exec(`
check_interval INTEGER DEFAULT 60000,
timeout INTEGER DEFAULT 5000,
enabled INTEGER DEFAULT 1,
group_id INTEGER REFERENCES groups(id) ON DELETE SET NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
@@ -30,6 +31,7 @@ db.exec(`
response_time INTEGER,
status_code INTEGER,
error_message TEXT,
details TEXT,
checked_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE
);
@@ -49,7 +51,7 @@ db.exec(`
CREATE INDEX IF NOT EXISTS idx_resources_group_id ON resources(group_id);
`);
// Lightweight migrations
// Lightweight migrations - for existing databases
try {
db.prepare("ALTER TABLE checks ADD COLUMN details TEXT").run();
} catch (err) {
@@ -57,7 +59,7 @@ try {
}
try {
db.prepare("ALTER TABLE resources ADD COLUMN group_id INTEGER REFERENCES groups(id) ON DELETE SET NULL").run();
db.prepare("ALTER TABLE resources ADD COLUMN group_id INTEGER").run();
} catch (err) {
// Column already exists
}