Skip to content

Commit

Permalink
add missing columns
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Jan 9, 2025
1 parent fba7c90 commit 9205eca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
30 changes: 16 additions & 14 deletions src/database/migrations/20250109185855_add_owasp_training.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
exports.up = async (knex) => {
await knex.schema.createTable('owasp_training', (table) => {
table.increments('id').primary() // Primary key
table.text('description').notNullable()
table.enum('implementation_status', ['unknown', 'pending', 'completed']).notNullable().defaultTo('pending')
table.string('training_date').defaultTo(knex.fn.now()).notNullable()

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

// Foreign key to 'projects' table
table.integer('project_id')
.notNullable()
.unsigned()
.references('id')
.inTable('projects')
.onDelete('CASCADE') // Deletes organization if the project is deleted
.onUpdate('CASCADE') // Updates organization if the project ID is updated
// Foreign key to 'projects' table
table.integer('project_id')
.notNullable()
.unsigned()
.references('id')
.inTable('projects')
.onDelete('CASCADE') // Deletes organization if the project is deleted
.onUpdate('CASCADE') // Updates organization if the project ID is updated
})

// Add trigger to automatically update the 'updated_at' column
Expand All @@ -24,11 +26,11 @@ exports.up = async (knex) => {
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_owasp_training ON owasp_training;')
// Drop table
await knex.schema.dropTableIfExists('owasp_training')
};
// Drop trigger
await knex.raw('DROP TRIGGER IF EXISTS set_updated_at_owasp_training ON owasp_training;')
// Drop table
await knex.schema.dropTableIfExists('owasp_training')
}
5 changes: 4 additions & 1 deletion src/database/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,13 @@ ALTER SEQUENCE public.ossf_scorecard_results_id_seq OWNED BY public.ossf_scoreca

CREATE TABLE public.owasp_training (
id integer NOT NULL,
description text NOT NULL,
implementation_status text DEFAULT 'pending'::text NOT NULL,
training_date character varying(255) DEFAULT CURRENT_TIMESTAMP NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
project_id integer NOT NULL
project_id integer NOT NULL,
CONSTRAINT owasp_training_implementation_status_check CHECK ((implementation_status = ANY (ARRAY['unknown'::text, 'pending'::text, 'completed'::text])))
);


Expand Down

0 comments on commit 9205eca

Please sign in to comment.