Skip to content

Commit 868e362

Browse files
committed
feat: add migration script to create compliance_checks_tasks table
1 parent 1cfc73f commit 868e362

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const severityLevels = ['critical', 'high', 'medium', 'low', 'info']
2+
3+
exports.up = async (knex) => {
4+
await knex.schema.createTable('compliance_checks_tasks', (table) => {
5+
table.increments('id').primary() // Primary key
6+
table.text('title').notNullable()
7+
table.text('description').notNullable()
8+
table.enum('severity', severityLevels).notNullable()
9+
10+
// Foreign key to 'compliance_checks' table
11+
table
12+
.integer('compliance_check_id')
13+
.unsigned()
14+
.references('id')
15+
.inTable('compliance_checks')
16+
.onDelete('CASCADE') // Deletes repository if the organization is deleted
17+
.onUpdate('CASCADE') // Updates repository if the organization ID is updated
18+
.notNullable()
19+
20+
// Foreign key to 'projects' table
21+
table
22+
.integer('project_id')
23+
.unsigned()
24+
.references('id')
25+
.inTable('projects')
26+
.onDelete('CASCADE') // Deletes repository if the organization is deleted
27+
.onUpdate('CASCADE') // Updates repository if the organization ID is updated
28+
.notNullable()
29+
30+
// Timestamps
31+
table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable()
32+
table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable()
33+
})
34+
35+
// Add trigger to automatically update the 'updated_at' column
36+
await knex.raw(`
37+
CREATE TRIGGER set_updated_at_compliance_checks_tasks
38+
BEFORE UPDATE ON compliance_checks_tasks
39+
FOR EACH ROW
40+
EXECUTE FUNCTION update_updated_at_column();
41+
`)
42+
}
43+
44+
exports.down = async (knex) => {
45+
// Drop trigger
46+
await knex.raw('DROP TRIGGER IF EXISTS set_updated_at_compliance_checks_tasks ON compliance_checks_tasks;')
47+
// Drop table
48+
await knex.schema.dropTableIfExists('compliance_checks_tasks')
49+
}

0 commit comments

Comments
 (0)