diff --git a/src/database/migrations/20250109185855_add_owasp_training.js b/src/database/migrations/20250109185855_add_owasp_training.js index 942e302..19c4f00 100644 --- a/src/database/migrations/20250109185855_add_owasp_training.js +++ b/src/database/migrations/20250109185855_add_owasp_training.js @@ -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 @@ -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') +} diff --git a/src/database/schema/schema.sql b/src/database/schema/schema.sql index 6c58b45..f4cf019 100644 --- a/src/database/schema/schema.sql +++ b/src/database/schema/schema.sql @@ -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]))) );