add time_setting table with seed and migration

This commit is contained in:
Sorrel Bri 2020-01-20 22:39:28 -08:00 committed by sorrelbri
parent d6c850cae1
commit 76cfbf54c3
3 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,15 @@
const timeTypes = ['untimed','game', 'byoYomi', 'move'];
exports.up = function(knex) {
return knex.schema.createTable("time_setting", table => {
table.increments('id').primary();
table.enu('main_time', timeTypes).notNullable();
table.integer('time_period').notNullable(); // number of periods
table.integer('period_length').notNullable(); // length in seconds
table.enu('overtime', timeTypes).notNullable();
table.integer('overtime_period').notNullable(); // number of periods
table.integer('overtime_length').notNullable(); // length in seconds
})
};
exports.down = knex => knex.schema.dropTableIfExists("time_setting");

View file

@ -0,0 +1,19 @@
const knex = require('../db')
const findTimeSetting = async (timeSetting) => {
const timeQuery = {
main_time: timeSetting.mainTime,
time_period: timeSetting.timePeriod,
period_length: timeSetting.periodLength,
overtime: timeSetting.overtime,
overtime_period: timeSetting.overtimePeriod,
overtime_length: timeSetting.overtimeLength
}
return await knex('time_setting')
.where({...timeSetting})
.select('id');
}
module.exports = {
findTimeSetting
}

View file

@ -0,0 +1,11 @@
exports.seed = function(knex) {
// Deletes ALL existing entries
return knex('time_setting').del()
.then(function () {
// Inserts seed entries
return knex('time_setting').insert([
{id: 1, main_time: 'untimed', time_period: 1, period_length: 0, overtime: 'untimed', overtime_period: 0, overtime_length: 0},
]);
});
};