|
| 1 | +const statusLevels = ['n/a', 'deferrable', 'expected', 'recommended'] |
| 2 | + |
| 3 | +exports.up = async (knex) => { |
| 4 | + await knex.schema.createTable('compliance_checks', (table) => { |
| 5 | + table.increments('id').primary() // Primary key |
| 6 | + table.string('title').notNullable() |
| 7 | + table.text('description').notNullable() |
| 8 | + table.string('section_number').notNullable() |
| 9 | + table.string('section_name').notNullable() |
| 10 | + table.string('code_name').unique().notNullable() |
| 11 | + table.string('priority_group').notNullable() |
| 12 | + table.boolean('is_c_scrm').notNullable().defaultTo(false) |
| 13 | + table.enum('level_incubating_status', statusLevels).notNullable() |
| 14 | + table.enum('level_active_status', statusLevels).notNullable() |
| 15 | + table.enum('level_retiring_status', statusLevels).notNullable() |
| 16 | + table.string('mitre_url') |
| 17 | + table.string('mitre_description') |
| 18 | + table.string('how_to_url') |
| 19 | + table.text('how_to_description') |
| 20 | + table.string('sources_url') |
| 21 | + table.text('sources_description') |
| 22 | + table.enum('implementation_status', ['pending', 'completed']).notNullable().defaultTo('pending') |
| 23 | + table.enum('implementation_type', ['manual', 'computed']) |
| 24 | + table.text('implementation_details_reference') |
| 25 | + table.text('details_url').notNullable() |
| 26 | + |
| 27 | + // Timestamps |
| 28 | + table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable() |
| 29 | + table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable() |
| 30 | + }) |
| 31 | + |
| 32 | + // Add trigger to automatically update the 'updated_at' column |
| 33 | + await knex.raw(` |
| 34 | + CREATE TRIGGER set_updated_at_compliance_checks |
| 35 | + BEFORE UPDATE ON compliance_checks |
| 36 | + FOR EACH ROW |
| 37 | + EXECUTE FUNCTION update_updated_at_column(); |
| 38 | + `) |
| 39 | +} |
| 40 | + |
| 41 | +exports.down = async (knex) => { |
| 42 | + // Drop trigger |
| 43 | + await knex.raw('DROP TRIGGER IF EXISTS set_updated_at_compliance_checks ON compliance_checks;') |
| 44 | + // Drop table |
| 45 | + await knex.schema.dropTableIfExists('compliance_checks') |
| 46 | +} |
0 commit comments