-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add migration script to create
compliance_checks_tasks
table
- Loading branch information
1 parent
1cfc73f
commit 868e362
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/database/migrations/1733523338663_add_compliance_checks_tasks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const severityLevels = ['critical', 'high', 'medium', 'low', 'info'] | ||
|
||
exports.up = async (knex) => { | ||
await knex.schema.createTable('compliance_checks_tasks', (table) => { | ||
table.increments('id').primary() // Primary key | ||
table.text('title').notNullable() | ||
table.text('description').notNullable() | ||
table.enum('severity', severityLevels).notNullable() | ||
|
||
// Foreign key to 'compliance_checks' table | ||
table | ||
.integer('compliance_check_id') | ||
.unsigned() | ||
.references('id') | ||
.inTable('compliance_checks') | ||
.onDelete('CASCADE') // Deletes repository if the organization is deleted | ||
.onUpdate('CASCADE') // Updates repository if the organization ID is updated | ||
.notNullable() | ||
|
||
// Foreign key to 'projects' table | ||
table | ||
.integer('project_id') | ||
.unsigned() | ||
.references('id') | ||
.inTable('projects') | ||
.onDelete('CASCADE') // Deletes repository if the organization is deleted | ||
.onUpdate('CASCADE') // Updates repository if the organization ID is updated | ||
.notNullable() | ||
|
||
// Timestamps | ||
table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable() | ||
table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable() | ||
}) | ||
|
||
// Add trigger to automatically update the 'updated_at' column | ||
await knex.raw(` | ||
CREATE TRIGGER set_updated_at_compliance_checks_tasks | ||
BEFORE UPDATE ON compliance_checks_tasks | ||
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_tasks ON compliance_checks_tasks;') | ||
// Drop table | ||
await knex.schema.dropTableIfExists('compliance_checks_tasks') | ||
} |