File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ exports . up = async ( knex ) => {
2
+ await knex . schema . createTable ( 'compliance_checklists' , ( table ) => {
3
+ table . increments ( 'id' ) . primary ( ) // Primary key
4
+ table . text ( 'author' ) . notNullable ( )
5
+ table . string ( 'title' ) . notNullable ( )
6
+ table . text ( 'description' ) . notNullable ( )
7
+ table . string ( 'code_name' ) . notNullable ( )
8
+ table . text ( 'url' ) . notNullable ( )
9
+
10
+ // Timestamps
11
+ table . timestamp ( 'created_at' ) . defaultTo ( knex . fn . now ( ) ) . notNullable ( )
12
+ table . timestamp ( 'updated_at' ) . defaultTo ( knex . fn . now ( ) ) . notNullable ( )
13
+ } )
14
+
15
+ // Add trigger to automatically update the 'updated_at' column
16
+ await knex . raw ( `
17
+ CREATE TRIGGER set_updated_at_compliance_checklists
18
+ BEFORE UPDATE ON compliance_checklists
19
+ FOR EACH ROW
20
+ EXECUTE FUNCTION update_updated_at_column();
21
+ ` )
22
+ }
23
+
24
+ exports . down = async ( knex ) => {
25
+ // Drop trigger
26
+ await knex . raw ( 'DROP TRIGGER IF EXISTS set_updated_at_compliance_checklists ON compliance_checklists;' )
27
+ // Drop table
28
+ await knex . schema . dropTableIfExists ( 'compliance_checklists' )
29
+ }
You can’t perform that action at this time.
0 commit comments