From 5205035d7c2b476b4699e2328ff5ff9b5c7d6349 Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Mon, 20 Jan 2020 23:36:52 -0800 Subject: [PATCH] add message table with migration --- server/data/migrations/20200120224032_game.js | 1 + server/data/migrations/20200120232142_message.js | 13 +++++++++++++ server/data/queries/message.js | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 server/data/migrations/20200120232142_message.js create mode 100644 server/data/queries/message.js 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