Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create compliance_checks_tasks table #41

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}
75 changes: 75 additions & 0 deletions src/database/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,43 @@ CREATE SEQUENCE public.compliance_checks_id_seq
ALTER SEQUENCE public.compliance_checks_id_seq OWNED BY public.compliance_checks.id;


--
-- Name: compliance_checks_tasks; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.compliance_checks_tasks (
id integer NOT NULL,
title text NOT NULL,
description text NOT NULL,
severity text NOT NULL,
compliance_check_id integer NOT NULL,
project_id integer NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
CONSTRAINT compliance_checks_tasks_severity_check CHECK ((severity = ANY (ARRAY['critical'::text, 'high'::text, 'medium'::text, 'low'::text, 'info'::text])))
);


--
-- Name: compliance_checks_tasks_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.compliance_checks_tasks_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: compliance_checks_tasks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.compliance_checks_tasks_id_seq OWNED BY public.compliance_checks_tasks.id;


--
-- Name: github_organizations; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -416,6 +453,13 @@ ALTER TABLE ONLY public.compliance_checks ALTER COLUMN id SET DEFAULT nextval('p
ALTER TABLE ONLY public.compliance_checks_alerts ALTER COLUMN id SET DEFAULT nextval('public.compliance_checks_alerts_id_seq'::regclass);


--
-- Name: compliance_checks_tasks id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.compliance_checks_tasks ALTER COLUMN id SET DEFAULT nextval('public.compliance_checks_tasks_id_seq'::regclass);


--
-- Name: github_organizations id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -475,6 +519,14 @@ ALTER TABLE ONLY public.compliance_checks
ADD CONSTRAINT compliance_checks_pkey PRIMARY KEY (id);


--
-- Name: compliance_checks_tasks compliance_checks_tasks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.compliance_checks_tasks
ADD CONSTRAINT compliance_checks_tasks_pkey PRIMARY KEY (id);


--
-- Name: github_organizations github_organizations_github_org_id_unique; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -561,6 +613,13 @@ CREATE TRIGGER set_updated_at_compliance_checks BEFORE UPDATE ON public.complian
CREATE TRIGGER set_updated_at_compliance_checks_alerts BEFORE UPDATE ON public.compliance_checks_alerts FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: compliance_checks_tasks set_updated_at_compliance_checks_tasks; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER set_updated_at_compliance_checks_tasks BEFORE UPDATE ON public.compliance_checks_tasks FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: github_organizations set_updated_at_github_organizations; Type: TRIGGER; Schema: public; Owner: -
--
Expand Down Expand Up @@ -598,6 +657,22 @@ ALTER TABLE ONLY public.compliance_checks_alerts
ADD CONSTRAINT compliance_checks_alerts_project_id_foreign FOREIGN KEY (project_id) REFERENCES public.projects(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: compliance_checks_tasks compliance_checks_tasks_compliance_check_id_foreign; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.compliance_checks_tasks
ADD CONSTRAINT compliance_checks_tasks_compliance_check_id_foreign FOREIGN KEY (compliance_check_id) REFERENCES public.compliance_checks(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: compliance_checks_tasks compliance_checks_tasks_project_id_foreign; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.compliance_checks_tasks
ADD CONSTRAINT compliance_checks_tasks_project_id_foreign FOREIGN KEY (project_id) REFERENCES public.projects(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: github_organizations github_organizations_project_id_foreign; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down
Loading