Skip to content

create compliance_checks_results table #42

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

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,50 @@
const severityLevels = ['critical', 'high', 'medium', 'low', 'info']
const statusLevels = ['unknown', 'passed', 'failed']

exports.up = async (knex) => {
await knex.schema.createTable('compliance_checks_results', (table) => {
table.increments('id').primary() // Primary key
table.enum('severity', severityLevels).notNullable()
table.enum('status', statusLevels).notNullable()
table.text('rationale').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_results
BEFORE UPDATE ON compliance_checks_results
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_results ON compliance_checks_results;')
// Drop table
await knex.schema.dropTableIfExists('compliance_checks_results')
}
76 changes: 76 additions & 0 deletions src/database/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,44 @@ CREATE SEQUENCE public.compliance_checks_id_seq
ALTER SEQUENCE public.compliance_checks_id_seq OWNED BY public.compliance_checks.id;


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

CREATE TABLE public.compliance_checks_results (
id integer NOT NULL,
severity text NOT NULL,
status text NOT NULL,
rationale 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_results_severity_check CHECK ((severity = ANY (ARRAY['critical'::text, 'high'::text, 'medium'::text, 'low'::text, 'info'::text]))),
CONSTRAINT compliance_checks_results_status_check CHECK ((status = ANY (ARRAY['unknown'::text, 'passed'::text, 'failed'::text])))
);


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

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


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

ALTER SEQUENCE public.compliance_checks_results_id_seq OWNED BY public.compliance_checks_results.id;


--
-- Name: compliance_checks_tasks; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -453,6 +491,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_results id; Type: DEFAULT; Schema: public; Owner: -
--

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


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


--
-- Name: compliance_checks_results compliance_checks_results_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.compliance_checks_results
ADD CONSTRAINT compliance_checks_results_pkey PRIMARY KEY (id);


--
-- Name: compliance_checks_tasks compliance_checks_tasks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -613,6 +666,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_results set_updated_at_compliance_checks_results; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER set_updated_at_compliance_checks_results BEFORE UPDATE ON public.compliance_checks_results 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: -
--
Expand Down Expand Up @@ -657,6 +717,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_results compliance_checks_results_compliance_check_id_foreign; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: compliance_checks_results compliance_checks_results_project_id_foreign; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.compliance_checks_results
ADD CONSTRAINT compliance_checks_results_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: -
--
Expand Down
Loading