add game table with seed and migration

This commit is contained in:
Sorrel Bri 2020-01-20 23:05:55 -08:00 committed by sorrelbri
parent 99a616fe37
commit 3f8d898f43
4 changed files with 62 additions and 3 deletions

View file

@ -0,0 +1,37 @@
const winType = [
'B+R', 'B+', 'B+T',
'W+R', 'W+', 'W+T',
'0', 'Void', '?'
]
exports.up = function(knex) {
return knex.schema.createTable("game", table => {
table.increments('id').primary();
table.datetime('date');
table.float('komi').default(6.5);
table.integer('handicap').default(0);
table.integer('board_size').default(19);
table.string('application');
table.string('application_version');
table.string('player_black');
table.string('player_white');
table.string('event');
table.string('name');
table.string('description');
table.integer('round');
table.enu('win_type', winType);
table.float('score');
table.integer('black_captures');
table.integer('white_captures');
table.integer('user_black').references('id').inTable('user');
table.integer('user_white').references('id').inTable('user');
table.integer('room').references('id').inTable('room');
table.integer('time_setting').references('id').inTable('time_setting');
})
};
exports.down = knex => knex.schema.dropTableIfExists("game");

View file

@ -0,0 +1,23 @@
const knex = require('../db');
const findGameById = async (gameId) => {
return await knex('game')
.where({'id': gameId})
.select('*');
}
const findGameByRoom = async (roomId) => {
return await knex('game')
.where({'id': roomId})
.select('*');
}
const insertGame = async (game) => {
}
module.exports = {
findGameById,
findGameByRoom,
insertGame
}

View file

@ -1,9 +1,9 @@
const knex = require('../db')
const knex = require('../db');
const findPublicRooms = async () => {
return await knex('room')
.where('private', false)
.select(['id', 'name', 'description', 'language'])
.select(['id', 'name', 'description', 'language']);
}
module.exports = {

View file

@ -15,7 +15,6 @@ const apiRoomSpec = require('./room/api.room.spec');
chai.use(chaiHttp);
// ! to run tests from other testing modules
// import someTest from './endpoint/someTest';
const setupDb = () => {
beforeEach(done => {