diff --git a/server/data/migrations/20200120224032_game.js b/server/data/migrations/20200120224032_game.js index 2f293da..16449c9 100644 --- a/server/data/migrations/20200120224032_game.js +++ b/server/data/migrations/20200120224032_game.js @@ -14,6 +14,7 @@ exports.up = function(knex) { table.string('application'); table.string('application_version'); + table.timestamps(true, true); table.string('player_black'); table.string('player_white'); diff --git a/server/data/migrations/20200120232142_message.js b/server/data/migrations/20200120232142_message.js new file mode 100644 index 0000000..97734d4 --- /dev/null +++ b/server/data/migrations/20200120232142_message.js @@ -0,0 +1,13 @@ +exports.up = knex => { + return knex.schema.createTable("message", table => { + table.increments('id').primary(); + table.timestamps(true, true) + table.text('content').notNullable(); + + table.integer('move').references('id').inTable('move'); + table.integer('room').references('id').inTable('room'); + table.integer('user').references('id').inTable('user').notNullable(); + }); +}; + +exports.down = knex => knex.schema.dropTableIfExists("message"); diff --git a/server/data/queries/message.js b/server/data/queries/message.js new file mode 100644 index 0000000..3a20e12 --- /dev/null +++ b/server/data/queries/message.js @@ -0,0 +1,13 @@ +const knex = require('../db'); + +// TODO timestamps + +const findMessageByRoom = async (roomId) => { + return await knex('message') + .where({'id': roomId}) + .select('*'); +} + +module.exports = { + findMessageByRoom +} \ No newline at end of file