From 33f716198b4bc41c63dd542cf0afa06d0475fb44 Mon Sep 17 00:00:00 2001 From: Evgeny Blokhin Date: Tue, 5 Sep 2023 15:30:04 +0200 Subject: [PATCH] Link FK to the users table --- db/migrations/20230526074529_logs.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/migrations/20230526074529_logs.js b/db/migrations/20230526074529_logs.js index 2d417e8..fc56c2c 100644 --- a/db/migrations/20230526074529_logs.js +++ b/db/migrations/20230526074529_logs.js @@ -4,6 +4,7 @@ const { USER_CALCULATIONS_TABLE, USER_COLLECTIONS_TABLE, USER_DATASOURCES_TABLE, + FOREIGN_KEY_LENGTH, } = require('../../services/db'); const LOG_FUNCTION = 'custom_log'; @@ -24,12 +25,17 @@ exports.up = function (knex) { return knex.schema .createTable(LOGS_TABLE, (table) => { table.increments('id'); - table.integer('userId').unsigned().index(); + table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); table.string('type'); table.jsonb('value'); table.timestamp('createdAt').defaultTo(knex.fn.now()).index(); table.primary('id', { constraintName: 'pk_logs' }); + table + .foreign('userId', 'fk_userId') + .references('id') + .inTable(USERS_TABLE) + .onDelete('CASCADE'); }) .then(() => {