packages/optimise-core/src/db/patient_immunisation.table.js
import { tableMove, tableCopyBack } from '../utils/db-mover';
export const TABLE_NAME = 'PATIENT_IMMUNISATION';
export const PRIORITY = 2;
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('patient').notNullable().references('id').inTable('PATIENTS').onDelete('CASCADE');
table.text('vaccineName').notNullable();
table.text('immunisationDate').notNullable();
table.text('createdTime').notNullable().defaultTo(dbcon().fn.now());
table.integer('createdByUser').notNullable().references('id').inTable('USERS');
table.text('deleted').notNullable().defaultTo('-');
table.unique(['patient', 'vaccineName', 'immunisationDate', 'deleted'], `UNIQUE_${Date.now()}_${TABLE_NAME}`);
});
await tableCopyBack(TABLE_NAME);
break;
case 16:
await dbcon().schema.table(TABLE_NAME, (table) => {
table.dropForeign('patient');
table.foreign('patient').references('id').inTable('PATIENTS').onDelete('CASCADE');
});
break;
case 17:
await dbcon().schema.table(TABLE_NAME, (table) => {
table.dropForeign('patient');
table.foreign('patient').references('id').inTable('PATIENTS').onDelete('CASCADE');
});
break;
case 18:
await dbcon().schema.table(TABLE_NAME, (table) => {
table.dropForeign('patient');
table.foreign('patient').references('id').inTable('PATIENTS').onDelete('CASCADE');
});
break;
default:
break;
}
};