From ac7dad7557a5f192374c1a7c117a729508ff0fa1 Mon Sep 17 00:00:00 2001 From: Ulises Gascon Date: Tue, 24 Dec 2024 16:58:04 +0100 Subject: [PATCH] feat: alter `compliance_checks` table to support checklists Related #163 --- .../1735041299955_alter_compliance_checks.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/database/migrations/1735041299955_alter_compliance_checks.js diff --git a/src/database/migrations/1735041299955_alter_compliance_checks.js b/src/database/migrations/1735041299955_alter_compliance_checks.js new file mode 100644 index 0000000..7caf383 --- /dev/null +++ b/src/database/migrations/1735041299955_alter_compliance_checks.js @@ -0,0 +1,29 @@ +const statusLevels = ['n/a', 'deferrable', 'expected', 'recommended'] + +exports.up = async (knex) => { + await knex.schema.alterTable('compliance_checks', (table) => { + // Drop old fields + table.dropColumn('level_incubating_status') + table.dropColumn('level_active_status') + table.dropColumn('level_retiring_status') + + // Rename fields + table.renameColumn('priority_group', 'default_priority_group') + table.renameColumn('section_number', 'default_section_number') + table.renameColumn('section_name', 'default_section_name') + }) +} + +exports.down = async (knex) => { + await knex.schema.alterTable('compliance_checks', (table) => { + // IMPORTANT: Re-add dropped fields but without the original values and nullable. + table.enum('level_incubating_status', statusLevels).nullable() + table.enum('level_active_status', statusLevels).nullable() + table.enum('level_retiring_status', statusLevels).nullable() + + // Rename fields back + table.renameColumn('default_priority_group', 'priority_group') + table.renameColumn('default_section_number', 'section_number') + table.renameColumn('default_section_name', 'section_name') + }) +}