Browse Source

Server: removed unique constraint on HealthCheckDataEntry table; repaired .sql file migrations

Christian Kahlau 2 years ago
parent
commit
60be64e9ad

+ 1 - 2
server/src/ctrl/db-migration.class.ts

@@ -36,7 +36,7 @@ export class DBMigration extends SQLiteController {
         const id = Number(m[1]);
         if (id <= lastID) continue;
 
-        if (m[2] === 'sql') {
+        if (m[3] === 'sql') {
           const migFilepath = path.join(migrationsDir, file);
           const migration = await fsp.readFile(migFilepath, { encoding: 'utf-8' });
 
@@ -57,7 +57,6 @@ export class DBMigration extends SQLiteController {
           const migFilepath = path.join(migrationsDir, file.substring(0, file.length - 3));
           const imp = require(migFilepath).default;
           if (typeof imp !== 'function') {
-            console.log('TYPE', typeof imp, 'KEYS', Object.keys(imp));
             throw new MigrationException(`File ${file} is not a valid <MigrationRunner> implementation!`);
           }
           const mig = imp as MigrationRunner;

+ 15 - 0
server/src/migrations/202302131250_website_healthcheck_fix2.sql

@@ -0,0 +1,15 @@
+ALTER TABLE HealthCheckDataEntry RENAME TO HealthCheckDataEntry_OLD;
+CREATE TABLE HealthCheckDataEntry(
+  ID INTEGER PRIMARY KEY AUTOINCREMENT,
+  ConfigID INTEGER NOT NULL,
+  Timestamp INTEGER NOT NULL,
+  Status INTEGER NOT NULL,
+  Message TEXT,
+  CONSTRAINT FK_HealthCheckDataEntry_HealthCheckConfig
+    FOREIGN KEY(ConfigID) 
+    REFERENCES HealthCheckConfig(ID)
+    ON DELETE CASCADE
+    /* REMOVED: UNIQUE(ConfigID, Timestamp) */
+);
+INSERT INTO HealthCheckDataEntry SELECT * FROM HealthCheckDataEntry_OLD;
+DROP TABLE HealthCheckDataEntry_OLD;