add game table with seed and migration
This commit is contained in:
parent
63f1b335e9
commit
d0f26d9a6c
4 changed files with 62 additions and 3 deletions
37
server/data/migrations/20200120224032_game.js
Normal file
37
server/data/migrations/20200120224032_game.js
Normal 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");
|
23
server/data/queries/game.js
Normal file
23
server/data/queries/game.js
Normal 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
|
||||
}
|
|
@ -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 = {
|
||||
|
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in a new issue