Skip to content

Commit

Permalink
Fix: Add missing FK for monitor-tls-info table (#4632)
Browse files Browse the repository at this point in the history
  • Loading branch information
chakflying authored Mar 31, 2024
1 parent 0923d05 commit 08f75b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion db/knex_init_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ async function createTables() {
// monitor_tls_info
await knex.schema.createTable("monitor_tls_info", (table) => {
table.increments("id");
table.integer("monitor_id").unsigned().notNullable(); //TODO: no fk ?
table.integer("monitor_id").unsigned().notNullable()
.references("id").inTable("monitor")
.onDelete("CASCADE")
.onUpdate("CASCADE");
table.text("info_json");
});

Expand Down
18 changes: 18 additions & 0 deletions db/old_migrations/patch-monitor-tls-info-add-fk.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BEGIN TRANSACTION;

PRAGMA writable_schema = TRUE;

UPDATE
SQLITE_MASTER
SET
sql = replace(sql,
'monitor_id INTEGER NOT NULL',
'monitor_id INTEGER NOT NULL REFERENCES [monitor] ([id]) ON DELETE CASCADE ON UPDATE CASCADE'
)
WHERE
name = 'monitor_tls_info'
AND type = 'table';

PRAGMA writable_schema = RESET;

COMMIT;
3 changes: 2 additions & 1 deletion server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class Database {
"patch-add-gamedig-given-port.sql": true,
"patch-notification-config.sql": true,
"patch-fix-kafka-producer-booleans.sql": true,
"patch-timeout.sql": true, // The last file so far converted to a knex migration file
"patch-timeout.sql": true,
"patch-monitor-tls-info-add-fk.sql": true, // The last file so far converted to a knex migration file
};

/**
Expand Down

0 comments on commit 08f75b0

Please sign in to comment.