|
| 1 | +/* eslint-disable no-await-in-loop, no-restricted-syntax */ |
1 | 2 | const patient = require('../src/metadata/patient'); |
2 | 3 | const convertToSequelizeField = require('../src/metadata/convertToSequelizeField'); |
3 | 4 |
|
4 | 5 | const fields = patient.getFieldHash(convertToSequelizeField); |
5 | | -const newFields = ['treatmentNotes', 'glasgowComaScale']; |
| 6 | +const newFieldNames = ['treatmentNotes', 'glasgowComaScale']; |
6 | 7 | const { tableName } = patient; |
7 | 8 |
|
8 | 9 | module.exports = { |
9 | | - up: async (queryInterface, Sequelize) => { |
| 10 | + async up(queryInterface, Sequelize) { |
10 | 11 | await queryInterface.sequelize.transaction(async (transaction) => { |
11 | | - for (const fieldName of newFields) { |
12 | | - const newField = fields[fieldName]; |
| 12 | + for (const name of newFieldNames) { |
| 13 | + const { field, type } = fields[name]; |
13 | 14 |
|
14 | | - await queryInterface.addColumn( |
15 | | - tableName, |
16 | | - newField.field, |
17 | | - newField, |
18 | | - { transaction } |
19 | | - ); |
| 15 | + await queryInterface.addColumn(tableName, field, type, { transaction }); |
20 | 16 | } |
21 | 17 | }); |
22 | 18 | }, |
23 | 19 |
|
24 | | - down: async (queryInterface) => { |
| 20 | + async down(queryInterface) { |
25 | 21 | await queryInterface.sequelize.transaction(async (transaction) => { |
26 | | - for (const fieldName of newFields) { |
27 | | - const newField = fields[fieldName]; |
| 22 | + for (const name of newFieldNames) { |
| 23 | + const { field } = fields[name]; |
28 | 24 |
|
29 | | - await queryInterface.removeColumn(tableName, newField.field, { transaction }); |
| 25 | + await queryInterface.removeColumn(tableName, field, { transaction }); |
30 | 26 | } |
31 | 27 | }); |
32 | 28 | }, |
|
0 commit comments