add move table with migration
This commit is contained in:
parent
d0f26d9a6c
commit
a10453a848
2 changed files with 28 additions and 0 deletions
17
server/data/migrations/20200120230921_move.js
Normal file
17
server/data/migrations/20200120230921_move.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
const players = ['white', 'black']
|
||||
|
||||
exports.up = knex => {
|
||||
return knex.schema.createTable("move", table => {
|
||||
table.increments('id').primary();
|
||||
table.enu('player', players).notNullable();
|
||||
table.integer('point_x').notNullable();
|
||||
table.integer('point_y').notNullable();
|
||||
table.integer('number').notNullable();
|
||||
table.boolean('game_record').notNullable().default(true);
|
||||
|
||||
table.integer('game').references('id').inTable('game').notNullable();
|
||||
table.integer('prior_move').references('id').inTable('move');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = knex => knex.schema.dropTableIfExists("move");
|
11
server/data/queries/move.js
Normal file
11
server/data/queries/move.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const knex = require('../db');
|
||||
|
||||
const findGameRecord = async (gameId) => {
|
||||
return await knex('move')
|
||||
.where({'game': gameId, 'game_record': true})
|
||||
.select('*');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
findGameRecord
|
||||
}
|
Loading…
Reference in a new issue