backend/migrations/0_initial-migration.js
2020-05-01 11:49:09 +02:00

109 lines
2.2 KiB
JavaScript

/* 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 });
// };