backend/data/migrations/0_initial-migration.js

98 lines
2.0 KiB
JavaScript

const { PgLiteral } = require('node-pg-migrate');
exports.shorthands = {
id: { type: 'serial', primaryKey: true },
varchar: { type: 'varchar(128)' },
varchar_req: { type: 'varchar(128)', notNull: true },
created_at: {
type: 'timestamp',
notNull: true,
default: PgLiteral.create('CURRENT_TIMESTAMP'),
},
};
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: 'created_at',
});
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: 'created_at',
});
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: 'created_at',
});
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: 'created_at',
});
};
// exports.down = (pgm) => {
// pgm.dropTable('accounts', { ifExists: true });
// };