From 8af2a70f008909916a328040593f16d1a3f1817e Mon Sep 17 00:00:00 2001 From: rui hildt Date: Fri, 1 May 2020 11:49:09 +0200 Subject: [PATCH] Complete migrations --- migrations/0_initial-migration.js | 108 ++++++++++++++++++++++++++++++ migrations/1_initial-migration.js | 28 -------- 2 files changed, 108 insertions(+), 28 deletions(-) create mode 100644 migrations/0_initial-migration.js delete mode 100644 migrations/1_initial-migration.js diff --git a/migrations/0_initial-migration.js b/migrations/0_initial-migration.js new file mode 100644 index 0000000..cc04465 --- /dev/null +++ b/migrations/0_initial-migration.js @@ -0,0 +1,108 @@ +/* eslint-disable camelcase */ + +exports.shorthands = { + id: { type: 'serial', primaryKey: true }, + varchar: { type: 'varchar(128)' }, + varchar_req: { type: 'varchar(128)', notNull: true } +}; + +exports.up = (pgm) => { + pgm.createTable('account', { + id: 'id', + username: 'varchar_req', + email: 'varchar_req', + password: 'varchar_req', + timezone: 'varchar', + earliest_time: 'time', + latest_time: 'time', + createdAt: { + type: 'timestamp', + notNull: true, + default: pgm.func('current_timestamp'), + }, + }); + + pgm.createTable('meeting', { + id: { type: 'uuid', primaryKey: true }, + title: 'varchar_req', + description: 'varchar', + start_time: 'time', + timezone: 'varchar', + duration: 'int', + status: 'boolean', + password: 'varchar', + createdAt: { + type: 'timestamp', + notNull: true, + default: pgm.func('current_timestamp'), + }, + }); + + pgm.createTable('possible_date', { + id: 'id', + meeting_id: { + type: 'uuid', + references: 'meeting(id)', + notNull: true, + onDelete: 'cascade', + }, + possible_date: { type: 'date', notNull: true }, + }); + + pgm.createTable('participant', { + id: 'id', + account_id: { + type: 'int', + references: 'account(id)', + notNull: true, + onDelete: 'cascade', + }, + meeting_id: { + type: 'uuid', + references: 'meeting(id)', + notNull: true, + onDelete: 'cascade', + }, + earliest_time: 'time', + latest_time: 'time', + quorum: 'boolean', + mandatory: 'boolean', + host: 'boolean', + answered: 'boolean', + timezone: 'varchar', + createdAt: { + type: 'timestamp', + notNull: true, + default: pgm.func('current_timestamp'), + }, + }); + + pgm.createTable('availibility', { + id: 'id', + participant_id: { + type: 'id', + references: 'participant(id)', + notNull: true, + onDelete: 'cascade', + }, + possible_date_id: { + type: 'id', + references: 'possible_date(id)', + notNull: true, + onDelete: 'cascade', + }, + preference: { type: 'boolean', notNull: true }, + start_time: { type: 'timestamp', notNull: true }, + end_time: { type: 'timestamp', notNull: true }, + timezone: 'varchar_req', + createdAt: { + type: 'timestamp', + notNull: true, + default: pgm.func('current_timestamp'), + }, + }); +}; + +// exports.down = (pgm) => { +// pgm.dropTable('accounts', { ifExists: true }); +// }; diff --git a/migrations/1_initial-migration.js b/migrations/1_initial-migration.js deleted file mode 100644 index 0053ccd..0000000 --- a/migrations/1_initial-migration.js +++ /dev/null @@ -1,28 +0,0 @@ -/* eslint-disable camelcase */ - -exports.shorthands = { - uuid: { type: 'uuid', primaryKey: true }, - id: { type: 'serial', primaryKey: true }, - timezone: { type: 'varchar(128)' }, -}; - -exports.up = (pgm) => { - pgm.createTable('accounts', { - id: 'id', - username: { type: 'varchar(128)', notNull: true }, - email: { type: 'varchar(128)', notNull: true }, - password: { type: 'varchar(128)', notNull: true }, - timezone: 'timezone', - earliest_time: { type: 'time' }, - latest_time: { type: 'time' }, - createdAt: { - type: 'timestamp', - notNull: true, - default: pgm.func('current_timestamp'), - }, - }); -}; - -exports.down = (pgm) => { - pgm.dropTable('accounts', { ifExists: true }); -};