Skip to content

Commit

Permalink
Merge pull request #104 from basf/logs_fk
Browse files Browse the repository at this point in the history
Link FK to the users table
  • Loading branch information
blokhin authored Sep 18, 2023
2 parents 31c165c + 33f7161 commit 44fa985
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion db/migrations/20230526074529_logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(() => {
Expand Down

0 comments on commit 44fa985

Please sign in to comment.