All files / framework/src/api/db/migrations 002_init_account.js

100% Statements 20/20
100% Branches 0/0
100% Functions 7/7
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 281x 1x   48x 48x 48x 48x 48x 48x 48x 48x 48x     48x     48x   48x     48x     1x 1x  
const TABLES = require('../../../constants/tables');
const { initBasicModelTable } = require('../../../constants/migrations');
 
const up = (kn) => kn.transaction(knex => {
    const initAccountTable = () => knex.schema.createTable(TABLES.ACCOUNT_TABLE_NAME, table => {
        initBasicModelTable(table);
        table.string('accessToken');
        table.string('refreshToken');
        table.string('email');
        table.string('provider');
        table.string('subject');
        table.integer('userId').references('id').inTable(TABLES.USER_TABLE_NAME).onDelete('CASCADE');
    });
 
    return initAccountTable();
});
 
const down = (kn, Promise) => kn.transaction(knex => {
    function dropTableIfExistsCascade(table) {
        return knex.raw(`DROP TABLE IF EXISTS "${table}" CASCADE;`);
    }
 
    return Promise.all([TABLES.ACCOUNT_TABLE_NAME].map(dropTableIfExistsCascade));
});
 
module.exports.up = up;
module.exports.down = down;