Skip to content

Commit

Permalink
Update schema.sql with recent changes (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored Sep 17, 2024
1 parent e8881fc commit 1f88fdd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ public class Component extends PanacheEntityBase {
@Column(name = "ID")
private long id;

@Column(name = "AUTHOR", columnDefinition = "VARCHAR")
private String author;

@Column(name = "PUBLISHER", columnDefinition = "VARCHAR")
private String publisher;

@Column(name = "\"GROUP\"", columnDefinition = "VARCHAR")
private String group;

Expand Down Expand Up @@ -113,22 +107,6 @@ public void setId(long id) {
this.id = id;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getPublisher() {
return publisher;
}

public void setPublisher(String publisher) {
this.publisher = publisher;
}

public String getGroup() {
return group;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ public class Project implements Serializable {
@Column(name = "ID")
private long id;

@Column(name = "AUTHOR", columnDefinition = "VARCHAR")
private String author;

@Column(name = "PUBLISHER", columnDefinition = "VARCHAR")
private String publisher;

@Column(name = "\"GROUP\"", columnDefinition = "VARCHAR")
private String group;

Expand Down Expand Up @@ -133,22 +127,6 @@ public void setId(long id) {
this.id = id;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getPublisher() {
return publisher;
}

public void setPublisher(String publisher) {
this.publisher = publisher;
}

public String getGroup() {
return group;
}
Expand Down
70 changes: 53 additions & 17 deletions commons-persistence/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand Down Expand Up @@ -233,10 +234,15 @@ BEGIN
+ "v_policy_violations_security_audited";
"v_policy_violations_unaudited" = "v_policy_violations_total" - "v_policy_violations_audited";

WITH "CTE_LATEST_METRICS" AS (
SELECT *
FROM "DEPENDENCYMETRICS"
WHERE "COMPONENT_ID" = "v_component"."ID"
ORDER BY "LAST_OCCURRENCE" DESC
LIMIT 1)
SELECT "ID"
FROM "DEPENDENCYMETRICS"
WHERE "COMPONENT_ID" = "v_component"."ID"
AND "VULNERABILITIES" = "v_vulnerabilities"
FROM "CTE_LATEST_METRICS"
WHERE "VULNERABILITIES" = "v_vulnerabilities"
AND "CRITICAL" = "v_critical"
AND "HIGH" = "v_high"
AND "MEDIUM" = "v_medium"
Expand All @@ -262,7 +268,6 @@ BEGIN
AND "POLICYVIOLATIONS_SECURITY_TOTAL" = "v_policy_violations_security_total"
AND "POLICYVIOLATIONS_SECURITY_AUDITED" = "v_policy_violations_security_audited"
AND "POLICYVIOLATIONS_SECURITY_UNAUDITED" = "v_policy_violations_security_unaudited"
ORDER BY "LAST_OCCURRENCE" DESC
LIMIT 1
INTO "v_existing_id";

Expand Down Expand Up @@ -442,8 +447,13 @@ BEGIN

"v_risk_score" = "CALC_RISK_SCORE"("v_critical", "v_high", "v_medium", "v_low", "v_unassigned");

WITH "CTE_LATEST_METRICS" AS (
SELECT *
FROM "PORTFOLIOMETRICS"
ORDER BY "LAST_OCCURRENCE" DESC
LIMIT 1)
SELECT "ID"
FROM "PORTFOLIOMETRICS"
FROM "CTE_LATEST_METRICS"
WHERE "PROJECTS" = "v_projects"
AND "VULNERABLEPROJECTS" = "v_vulnerable_projects"
AND "COMPONENTS" = "v_components"
Expand Down Expand Up @@ -474,7 +484,6 @@ BEGIN
AND "POLICYVIOLATIONS_SECURITY_TOTAL" = "v_policy_violations_security_total"
AND "POLICYVIOLATIONS_SECURITY_AUDITED" = "v_policy_violations_security_audited"
AND "POLICYVIOLATIONS_SECURITY_UNAUDITED" = "v_policy_violations_security_unaudited"
ORDER BY "LAST_OCCURRENCE" DESC
LIMIT 1
INTO "v_existing_id";

Expand Down Expand Up @@ -660,10 +669,15 @@ BEGIN

"v_risk_score" = "CALC_RISK_SCORE"("v_critical", "v_high", "v_medium", "v_low", "v_unassigned");

WITH "CTE_LATEST_METRICS" AS (
SELECT *
FROM "PROJECTMETRICS"
WHERE "PROJECT_ID" = "v_project_id"
ORDER BY "LAST_OCCURRENCE" DESC
LIMIT 1)
SELECT "ID"
FROM "PROJECTMETRICS"
WHERE "PROJECT_ID" = "v_project_id"
AND "COMPONENTS" = "v_components"
FROM "CTE_LATEST_METRICS"
WHERE "COMPONENTS" = "v_components"
AND "VULNERABLECOMPONENTS" = "v_vulnerable_components"
AND "VULNERABILITIES" = "v_vulnerabilities"
AND "CRITICAL" = "v_critical"
Expand Down Expand Up @@ -691,7 +705,6 @@ BEGIN
AND "POLICYVIOLATIONS_SECURITY_TOTAL" = "v_policy_violations_security_total"
AND "POLICYVIOLATIONS_SECURITY_AUDITED" = "v_policy_violations_security_audited"
AND "POLICYVIOLATIONS_SECURITY_UNAUDITED" = "v_policy_violations_security_unaudited"
ORDER BY "LAST_OCCURRENCE" DESC
LIMIT 1
INTO "v_existing_id";

Expand Down Expand Up @@ -766,6 +779,30 @@ BEGIN
end;
$$;

CREATE FUNCTION public.jsonb_vuln_aliases(vuln_source text, vuln_id text) RETURNS jsonb
LANGUAGE sql STABLE PARALLEL SAFE
AS $$
SELECT JSONB_AGG(DISTINCT JSONB_STRIP_NULLS(JSONB_BUILD_OBJECT(
'cveId', "VA"."CVE_ID"
, 'ghsaId', "VA"."GHSA_ID"
, 'gsdId', "VA"."GSD_ID"
, 'internalId', "VA"."INTERNAL_ID"
, 'osvId', "VA"."OSV_ID"
, 'sonatypeId', "VA"."SONATYPE_ID"
, 'snykId', "VA"."SNYK_ID"
, 'vulnDbId', "VA"."VULNDB_ID"
)))
FROM "VULNERABILITYALIAS" AS "VA"
WHERE ("vuln_source" = 'NVD' AND "VA"."CVE_ID" = "vuln_id")
OR ("vuln_source" = 'GITHUB' AND "VA"."GHSA_ID" = "vuln_id")
OR ("vuln_source" = 'GSD' AND "VA"."GSD_ID" = "vuln_id")
OR ("vuln_source" = 'INTERNAL' AND "VA"."INTERNAL_ID" = "vuln_id")
OR ("vuln_source" = 'OSV' AND "VA"."OSV_ID" = "vuln_id")
OR ("vuln_source" = 'SONATYPE' AND "VA"."SONATYPE_ID" = "vuln_id")
OR ("vuln_source" = 'SNYK' AND "VA"."SNYK_ID" = "vuln_id")
OR ("vuln_source" = 'VULNDB' AND "VA"."VULNDB_ID" = "vuln_id")
$$;

SET default_tablespace = '';

SET default_with_oids = false;
Expand Down Expand Up @@ -880,7 +917,6 @@ ALTER TABLE public."BOM" ALTER COLUMN "ID" ADD GENERATED BY DEFAULT AS IDENTITY

CREATE TABLE public."COMPONENT" (
"ID" bigint NOT NULL,
"AUTHOR" text,
"BLAKE2B_256" character varying(64),
"BLAKE2B_384" character varying(96),
"BLAKE2B_512" character varying(128),
Expand Down Expand Up @@ -919,6 +955,7 @@ CREATE TABLE public."COMPONENT" (
"UUID" uuid NOT NULL,
"VERSION" character varying(255),
"SUPPLIER" text,
"AUTHORS" text,
CONSTRAINT "COMPONENT_CLASSIFIER_check" CHECK ((("CLASSIFIER" IS NULL) OR (("CLASSIFIER")::text = ANY (ARRAY['APPLICATION'::text, 'CONTAINER'::text, 'DEVICE'::text, 'FILE'::text, 'FIRMWARE'::text, 'FRAMEWORK'::text, 'LIBRARY'::text, 'OPERATING_SYSTEM'::text]))))
);

Expand Down Expand Up @@ -975,10 +1012,6 @@ ALTER TABLE public."CONFIGPROPERTY" ALTER COLUMN "ID" ADD GENERATED BY DEFAULT A
CACHE 1
);

-- Required for tests
INSERT INTO public."CONFIGPROPERTY" ("GROUPNAME", "PROPERTYNAME", "PROPERTYVALUE", "PROPERTYTYPE", "DESCRIPTION")
VALUES ('internal', 'cluster.id', '53b94f78-6e2f-4015-961a-0965ff1807a9', 'STRING', NULL);

CREATE TABLE public."DEPENDENCYMETRICS" (
"ID" bigint NOT NULL,
"COMPONENT_ID" bigint NOT NULL,
Expand Down Expand Up @@ -1494,7 +1527,6 @@ ALTER TABLE public."PORTFOLIOMETRICS" ALTER COLUMN "ID" ADD GENERATED BY DEFAULT
CREATE TABLE public."PROJECT" (
"ID" bigint NOT NULL,
"ACTIVE" boolean DEFAULT true NOT NULL,
"AUTHOR" character varying(255),
"CLASSIFIER" character varying(255),
"CPE" character varying(255),
"DESCRIPTION" character varying(255),
Expand All @@ -1513,6 +1545,7 @@ CREATE TABLE public."PROJECT" (
"VERSION" character varying(255),
"SUPPLIER" text,
"MANUFACTURER" text,
"AUTHORS" text,
CONSTRAINT "PROJECT_CLASSIFIER_check" CHECK ((("CLASSIFIER" IS NULL) OR (("CLASSIFIER")::text = ANY (ARRAY['APPLICATION'::text, 'CONTAINER'::text, 'DEVICE'::text, 'FILE'::text, 'FIRMWARE'::text, 'FRAMEWORK'::text, 'LIBRARY'::text, 'OPERATING_SYSTEM'::text]))))
);

Expand Down Expand Up @@ -1720,7 +1753,7 @@ ALTER TABLE public."TAG" ALTER COLUMN "ID" ADD GENERATED BY DEFAULT AS IDENTITY

CREATE TABLE public."TEAM" (
"ID" bigint NOT NULL,
"NAME" character varying(50) NOT NULL,
"NAME" character varying(255) NOT NULL,
"UUID" character varying(36) NOT NULL
);

Expand Down Expand Up @@ -2810,3 +2843,6 @@ ALTER TABLE ONLY public."VULNERABLESOFTWARE_VULNERABILITIES"
ALTER TABLE ONLY public."WORKFLOW_STATE"
ADD CONSTRAINT "WORKFLOW_STATE_WORKFLOW_STATE_FK" FOREIGN KEY ("PARENT_STEP_ID") REFERENCES public."WORKFLOW_STATE"("ID") DEFERRABLE INITIALLY DEFERRED;

-- Required for tests
INSERT INTO public."CONFIGPROPERTY" ("GROUPNAME", "PROPERTYNAME", "PROPERTYVALUE", "PROPERTYTYPE", "DESCRIPTION")
VALUES ('internal', 'cluster.id', '53b94f78-6e2f-4015-961a-0965ff1807a9', 'STRING', NULL);

0 comments on commit 1f88fdd

Please sign in to comment.