All files / framework/src/api/db/migrations 001_init_user.js

100% Statements 18/18
100% Branches 0/0
100% Functions 7/7
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x 1x   48x 48x 48x 48x 48x 48x 48x   48x     48x   48x   48x     1x 1x  
const TABLES = require('../../../constants/tables');
const { initPublicModelTable } = require('../../../constants/migrations');
 
const up = (kn) => kn.transaction(knex => {
    const initUserTable = () => knex.schema.createTable(TABLES.USER_TABLE_NAME, table => {
        initPublicModelTable(table);
        table.string('name');
        table.string('email');
        table.string('password');
        table.string('salt');
    });
    return initUserTable();
});
 
const down = (kn, Promise) => kn.transaction(knex => {
    function dropTableIfExistsCascade(table) {
        return knex.raw(`DROP TABLE IF EXISTS "${table}" CASCADE;`);
    }
    return Promise.all([TABLES.USER_TABLE_NAME].map(dropTableIfExistsCascade));
});
 
module.exports.up = up;
module.exports.down = down;