Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to segregate compliance checks resources #187

Merged
merged 10 commits into from
Jan 23, 2025
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
exports.up = async (knex) => {
await knex.schema.createTable('compliance_checks_resources', (table) => {
table.increments('id').primary() // Primary key
table.string('url').notNullable()
table.string('name')
table.text('description')
table.enum('type', ['mitre', 'how_to', 'sources']).notNullable().defaultTo('pending')

// Timestamps
table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable()
table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable()
})

await knex.raw(`
CREATE TRIGGER set_updated_at_compliance_checks_resources
BEFORE UPDATE ON compliance_checks_resources
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
`)
}

exports.down = async (knex) => {
// Drop trigger
await knex.raw(`DROP TRIGGER IF EXISTS set_updated_at_compliance_checks_resources
ON compliance_checks_resources;`)
// Drop table
await knex.schema.dropTableIfExists('compliance_checks_resources')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports.up = async (knex) => {
await knex.schema.createTable('resources_for_compliance_checks', table => {
table.increments()
table.integer('compliance_check_id')
.unsigned()
.notNullable()
.references('id').inTable('compliance_checks')
table.integer('compliance_check_resource_id')
.unsigned()
.notNullable()
.references('id').inTable('compliance_checks_resources')

table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable()
})
}

exports.down = async (knex) => {
await knex.schema.dropTableIfExists('resources_for_compliance_checks')
}
Loading
Loading