diff --git a/db/migrations/20230526063604_collections-types.js b/db/migrations/20230526063604_collections-types.js index 6c14c94..f805ada 100644 --- a/db/migrations/20230526063604_collections-types.js +++ b/db/migrations/20230526063604_collections-types.js @@ -15,7 +15,7 @@ exports.up = function (knex) { useNative: true, enumName: FLAVORS_ENUM_NAME, }); - table.timestamps(false, true, true); + table.timestamps(false, true, false); }); }; diff --git a/db/migrations/20230526065020_user-roles.js b/db/migrations/20230526065020_user-roles.js index d1280f9..652f43f 100644 --- a/db/migrations/20230526065020_user-roles.js +++ b/db/migrations/20230526065020_user-roles.js @@ -10,7 +10,7 @@ exports.up = function (knex) { table.string('slug', NAME_LENGTH).unique(); table.string('label', NAME_LENGTH); table.jsonb('permissions').nullable(); - table.timestamps(false, true, true); + table.timestamps(false, true, false); }); }; diff --git a/db/migrations/20230526070609_users.js b/db/migrations/20230526070609_users.js index adb86fc..bcd0626 100644 --- a/db/migrations/20230526070609_users.js +++ b/db/migrations/20230526070609_users.js @@ -14,13 +14,13 @@ exports.up = function (knex) { return knex.schema.createTable(USERS_TABLE, (table) => { table.increments('id'); table.string('password', PASSWORD_LENGTH).nullable(); - table.string('firstName', NAME_LENGTH); - table.string('lastName', NAME_LENGTH); - table.integer('roleId', FOREIGN_KEY_LENGTH).unsigned().index(); - table.timestamps(false, true, true); + table.string('first_name', NAME_LENGTH); + table.string('last_name', NAME_LENGTH); + table.integer('role_id', FOREIGN_KEY_LENGTH).unsigned().index(); + table.timestamps(false, true, false); table - .foreign('roleId', 'fk_roleId') + .foreign('role_id', 'fk_role_id') .references('id') .inTable(USER_ROLES_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526071428_user-api-tokens.js b/db/migrations/20230526071428_user-api-tokens.js index 72407fe..5d67845 100644 --- a/db/migrations/20230526071428_user-api-tokens.js +++ b/db/migrations/20230526071428_user-api-tokens.js @@ -7,13 +7,13 @@ const { USERS_TABLE, USER_API_TOKENS_TABLE, FOREIGN_KEY_LENGTH } = require('../. exports.up = function (knex) { return knex.schema.createTable(USER_API_TOKENS_TABLE, (table) => { table.increments('id'); - table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('user_id', FOREIGN_KEY_LENGTH).unsigned().index(); table.string('token').unique(); - table.timestamps(false, true, true); + table.timestamps(false, true, false); table.primary('id', { constraintName: 'pk_user_api_token' }); table - .foreign('userId', 'fk_userId') + .foreign('user_id', 'fk_user_id') .references('id') .inTable(USERS_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526071911_users-emails.js b/db/migrations/20230526071911_users-emails.js index 97860f7..a33cd27 100644 --- a/db/migrations/20230526071911_users-emails.js +++ b/db/migrations/20230526071911_users-emails.js @@ -12,15 +12,15 @@ const { */ exports.up = function (knex) { return knex.schema.createTable(USERS_EMAILS_TABLE, (table) => { - table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('user_id', FOREIGN_KEY_LENGTH).unsigned().index(); table.string('email', EMAIL_LENGTH).unique().index(); table.string('code', PASSWORD_LENGTH).unique().index(); table.boolean('verified').defaultTo(false); - table.timestamps(false, true, true); + table.timestamps(false, true, false); - table.primary(['userId', 'email'], { constraintName: 'pk_user_email' }); + table.primary(['user_id', 'email'], { constraintName: 'pk_user_email' }); table - .foreign('userId', 'fk_userId') + .foreign('user_id', 'fk_user_id') .references('id') .inTable(USERS_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526072327_users-oauths.js b/db/migrations/20230526072327_users-oauths.js index 85d0711..05957dc 100644 --- a/db/migrations/20230526072327_users-oauths.js +++ b/db/migrations/20230526072327_users-oauths.js @@ -13,20 +13,20 @@ const OAUTH_PROVIDERS_ENUM_NAME = 'oauth_providers'; */ exports.up = function (knex) { return knex.schema.createTable(USERS_OAUTHS_TABLE, (table) => { - table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('user_id', FOREIGN_KEY_LENGTH).unsigned().index(); table.enu('provider', OAUTH_PROVIDERS_ENUM, { useNative: true, enumName: OAUTH_PROVIDERS_ENUM_NAME, }); - table.string('providerId').unique(); + table.string('provider_id').unique(); table.jsonb('profile').nullable(); - table.timestamps(false, true, true); + table.timestamps(false, true, false); - table.primary(['userId', 'provider'], { + table.primary(['user_id', 'provider'], { constraintName: 'pk_user_provider', }); table - .foreign('userId', 'fk_userId') + .foreign('user_id', 'fk_user_id') .references('id') .inTable(USERS_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526072716_user-calculations.js b/db/migrations/20230526072716_user-calculations.js index 3d2170c..5205e3f 100644 --- a/db/migrations/20230526072716_user-calculations.js +++ b/db/migrations/20230526072716_user-calculations.js @@ -7,12 +7,12 @@ const { USERS_TABLE, USER_CALCULATIONS_TABLE, FOREIGN_KEY_LENGTH } = require('.. exports.up = function (knex) { return knex.schema.createTable(USER_CALCULATIONS_TABLE, (table) => { table.increments('id'); - table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('user_id', FOREIGN_KEY_LENGTH).unsigned().index(); table.uuid('uuid').unique(); - table.timestamps(false, true, true); + table.timestamps(false, true, false); table - .foreign('userId', 'fk_userId') + .foreign('user_id', 'fk_user_id') .references('id') .inTable(USERS_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526073013_user-datasources.js b/db/migrations/20230526073013_user-datasources.js index d363a7c..c2a48dc 100644 --- a/db/migrations/20230526073013_user-datasources.js +++ b/db/migrations/20230526073013_user-datasources.js @@ -7,12 +7,12 @@ const { USERS_TABLE, USER_DATASOURCES_TABLE, FOREIGN_KEY_LENGTH } = require('../ exports.up = function (knex) { return knex.schema.createTable(USER_DATASOURCES_TABLE, (table) => { table.increments('id'); - table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('user_id', FOREIGN_KEY_LENGTH).unsigned().index(); table.uuid('uuid').unique(); - table.timestamps(false, true, true); + table.timestamps(false, true, false); table - .foreign('userId', 'fk_userId') + .foreign('user_id', 'fk_user_id') .references('id') .inTable(USERS_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526073335_user-collections.js b/db/migrations/20230526073335_user-collections.js index 903c387..9357899 100644 --- a/db/migrations/20230526073335_user-collections.js +++ b/db/migrations/20230526073335_user-collections.js @@ -15,8 +15,8 @@ const VISIBILITY_ENUM_NAME = 'collection_visibility'; exports.up = function (knex) { return knex.schema.createTable(USER_COLLECTIONS_TABLE, (table) => { table.increments('id'); - table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); - table.integer('typeId', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('user_id', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('type_id', FOREIGN_KEY_LENGTH).unsigned().index(); table.string('title', 32); table.string('description', 64); table @@ -25,15 +25,15 @@ exports.up = function (knex) { enumName: VISIBILITY_ENUM_NAME, }) .defaultTo(VISIBILITY_ENUM[0]); - table.timestamps(false, true, true); + table.timestamps(false, true, false); table - .foreign('userId', 'fk_userId') + .foreign('user_id', 'fk_user_id') .references('id') .inTable(USERS_TABLE) .onDelete('CASCADE'); table - .foreign('typeId', 'fk_typeId') + .foreign('type_id', 'fk_type_id') .references('id') .inTable(COLLECTIONS_TYPES_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526073811_user-shared-collections.js b/db/migrations/20230526073811_user-shared-collections.js index fa2ed66..a3e06de 100644 --- a/db/migrations/20230526073811_user-shared-collections.js +++ b/db/migrations/20230526073811_user-shared-collections.js @@ -11,21 +11,21 @@ const { */ exports.up = function (knex) { return knex.schema.createTable(USER_SHARED_COLLECTIONS_TABLE, (table) => { - table.integer('collectionId', FOREIGN_KEY_LENGTH).unsigned().index(); - table.integer('userId', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('collection_id', FOREIGN_KEY_LENGTH).unsigned().index(); + table.integer('user_id', FOREIGN_KEY_LENGTH).unsigned().index(); table.jsonb('permissions').nullable(); - table.timestamps(false, true, true); + table.timestamps(false, true, false); - table.primary(['userId', 'collectionId'], { + table.primary(['user_id', 'collection_id'], { constraintName: 'pk_user_collection', }); table - .foreign('userId', 'fk_userId') + .foreign('user_id', 'fk_user_id') .references('id') .inTable(USERS_TABLE) .onDelete('CASCADE'); table - .foreign('collectionId', 'fk_collectionId') + .foreign('collection_id', 'fk_collection_id') .references('id') .inTable(USER_COLLECTIONS_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526074155_user-collections-datasources.js b/db/migrations/20230526074155_user-collections-datasources.js index 8f0a083..62a154e 100644 --- a/db/migrations/20230526074155_user-collections-datasources.js +++ b/db/migrations/20230526074155_user-collections-datasources.js @@ -10,20 +10,20 @@ const { */ exports.up = function (knex) { return knex.schema.createTable(USER_COLLECTIONS_DATASOURCES_TABLE, (table) => { - table.integer('collectionId').unsigned().index(); - table.integer('dataSourceId').unsigned().index(); - table.timestamps(false, true, true); + table.integer('collection_id').unsigned().index(); + table.integer('data_source_id').unsigned().index(); + table.timestamps(false, true, false); - table.primary(['collectionId', 'dataSourceId'], { - constraintName: 'pk_collection_dataSource', + table.primary(['collection_id', 'data_source_id'], { + constraintName: 'pk_collection_data_source', }); table - .foreign('collectionId', 'fk_collectionId') + .foreign('collection_id', 'fk_collection_id') .references('id') .inTable(USER_COLLECTIONS_TABLE) .onDelete('CASCADE'); table - .foreign('dataSourceId', 'fk_dataSourceId') + .foreign('data_source_id', 'fk_data_source_id') .references('id') .inTable(USER_DATASOURCES_TABLE) .onDelete('CASCADE'); diff --git a/db/migrations/20230526074529_logs.js b/db/migrations/20230526074529_logs.js index 2d417e8..d274cd5 100644 --- a/db/migrations/20230526074529_logs.js +++ b/db/migrations/20230526074529_logs.js @@ -24,10 +24,10 @@ exports.up = function (knex) { return knex.schema .createTable(LOGS_TABLE, (table) => { table.increments('id'); - table.integer('userId').unsigned().index(); + table.integer('user_id').unsigned().index(); table.string('type'); table.jsonb('value'); - table.timestamp('createdAt').defaultTo(knex.fn.now()).index(); + table.timestamp('created_at').defaultTo(knex.fn.now()).index(); table.primary('id', { constraintName: 'pk_logs' }); }) @@ -36,15 +36,15 @@ exports.up = function (knex) { const query = ` create or replace function ${LOG_FUNCTION} () returns trigger as $$ declare - userId integer; + user_id integer; type varchar := lower(tg_table_name); begin if type = lower('${USERS_TABLE}') then - userId := new.id; + user_id := new.id; else - userId := new."userId"; + user_id := new."user_id"; end if; - insert into "${LOGS_TABLE}" ("userId", "type", "value") values (userId, type, to_jsonb(new)); + insert into "${LOGS_TABLE}" ("user_id", "type", "value") values (user_id, type, to_jsonb(new)); return new; end; $$ language plpgsql; diff --git a/db/seeds/030-users.js b/db/seeds/030-users.js index 3bd6ead..9f92855 100644 --- a/db/seeds/030-users.js +++ b/db/seeds/030-users.js @@ -23,21 +23,21 @@ exports.seed = async function (knex) { const [member, admin, test] = await knex(USERS_TABLE).insert( [ { - firstName: 'Test', - lastName: 'Member', - roleId: memberRole.id, + first_name: 'Test', + last_name: 'Member', + role_id: memberRole.id, password, }, { - firstName: 'Test', - lastName: 'Admin', - roleId: adminRole.id, + first_name: 'Test', + last_name: 'Admin', + role_id: adminRole.id, password, }, { - firstName: 'Test', - lastName: 'Test', - roleId: memberRole.id, + first_name: 'Test', + last_name: 'Test', + role_id: memberRole.id, password, }, ], @@ -57,17 +57,17 @@ exports.seed = async function (knex) { await knex(USERS_EMAILS_TABLE).insert([ { - userId: member.id, + user_id: member.id, email: memberEmail, code: code1, }, { - userId: admin.id, + user_id: admin.id, email: adminEmail, code: code2, }, { - userId: test.id, + user_id: test.id, email: testEmail, code: code3, }, diff --git a/db/seeds/040-user-api-tokens.js b/db/seeds/040-user-api-tokens.js index 410d724..f991e36 100644 --- a/db/seeds/040-user-api-tokens.js +++ b/db/seeds/040-user-api-tokens.js @@ -10,8 +10,8 @@ exports.seed = async function (knex) { // Deletes ALL existing entries await knex(USER_API_TOKENS_TABLE).del(); await knex(USER_API_TOKENS_TABLE).insert( - emails.map(({ userId, email }) => ({ - userId, + emails.map(({ user_id, email }) => ({ + user_id, token: email, // inserting email as token just for test })) );