Skip to content

Commit

Permalink
Tweak names in migration
Browse files Browse the repository at this point in the history
Pass the type instead of the whole field object.
Prettier and eslint nonsense.
  • Loading branch information
fwextensions committed Jul 21, 2022
1 parent b3c9c54 commit 6ffd9fb
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions migrations/20220721055200-add-gcs-treatments-to-patient.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
/* eslint-disable no-await-in-loop, no-restricted-syntax */
const patient = require('../src/metadata/patient');
const convertToSequelizeField = require('../src/metadata/convertToSequelizeField');

const fields = patient.getFieldHash(convertToSequelizeField);
const newFields = ['treatmentNotes', 'glasgowComaScale'];
const newFieldNames = ['treatmentNotes', 'glasgowComaScale'];
const { tableName } = patient;

module.exports = {
up: async (queryInterface, Sequelize) => {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (transaction) => {
for (const fieldName of newFields) {
const newField = fields[fieldName];
for (const name of newFieldNames) {
const { field, type } = fields[name];

await queryInterface.addColumn(
tableName,
newField.field,
newField,
{ transaction }
);
await queryInterface.addColumn(tableName, field, type, { transaction });
}
});
},

down: async (queryInterface) => {
async down(queryInterface) {
await queryInterface.sequelize.transaction(async (transaction) => {
for (const fieldName of newFields) {
const newField = fields[fieldName];
for (const name of newFieldNames) {
const { field } = fields[name];

await queryInterface.removeColumn(tableName, newField.field, { transaction });
await queryInterface.removeColumn(tableName, field, { transaction });
}
});
},
Expand Down

0 comments on commit 6ffd9fb

Please sign in to comment.