packages/optimise-core/src/db/clinical_events_data.table.js
import { tableMove, tableCopyBack } from '../utils/db-mover';
export const TABLE_NAME = 'CLINICAL_EVENTS_DATA';
export const PRIORITY = 4;
export default async (dbcon, version) => {
switch (version) {
case 1:
case 2:
case 3:
await tableMove(TABLE_NAME, version);
await dbcon().schema.createTable(TABLE_NAME, (table) => {
table.increments('id').primary();
table.integer('clinicalEvent').notNullable().references('id').inTable('CLINICAL_EVENTS').onDelete('CASCADE');
table.integer('field').notNullable().references('id').inTable('AVAILABLE_FIELDS_CE');
table.text('value').notNullable();
table.text('createdTime').notNullable().defaultTo(dbcon().fn.now());
table.integer('createdByUser').notNullable().references('id').inTable('USERS');
table.text('deleted').notNullable().defaultTo('-');
table.unique(['clinicalEvent', 'field', 'deleted'], `UNIQUE_${Date.now()}_${TABLE_NAME}`);
});
await tableCopyBack(TABLE_NAME);
break;
default:
break;
}
};