Fix database schema: add group_id to CREATE TABLE instead of separate migration
This commit is contained in:
1 parent
ec9362e14f
commit
117f815e58
1 file changed
+4
-2
+4
-2
@@ -20,6 +20,7 @@ db.exec(`
|
|||||||
check_interval INTEGER DEFAULT 60000,
|
check_interval INTEGER DEFAULT 60000,
|
||||||
timeout INTEGER DEFAULT 5000,
|
timeout INTEGER DEFAULT 5000,
|
||||||
enabled INTEGER DEFAULT 1,
|
enabled INTEGER DEFAULT 1,
|
||||||
|
group_id INTEGER REFERENCES groups(id) ON DELETE SET NULL,
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ db.exec(`
|
|||||||
response_time INTEGER,
|
response_time INTEGER,
|
||||||
status_code INTEGER,
|
status_code INTEGER,
|
||||||
error_message TEXT,
|
error_message TEXT,
|
||||||
|
details TEXT,
|
||||||
checked_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
checked_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE
|
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);
|
CREATE INDEX IF NOT EXISTS idx_resources_group_id ON resources(group_id);
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Lightweight migrations
|
// Lightweight migrations - for existing databases
|
||||||
try {
|
try {
|
||||||
db.prepare("ALTER TABLE checks ADD COLUMN details TEXT").run();
|
db.prepare("ALTER TABLE checks ADD COLUMN details TEXT").run();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -57,7 +59,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
} catch (err) {
|
||||||
// Column already exists
|
// Column already exists
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user