CREATE SCHEMA covscanrest;

GRANT USAGE ON SCHEMA covscanrest TO postgres;

CREATE TABLE IF NOT EXISTS covscanrest.products(
    productID VARCHAR(100),
    description VARCHAR(200),
    repository VARCHAR (150),
    PRIMARY KEY (productID)
);


CREATE TABLE IF NOT EXISTS covscanrest.scans (
    scanID SERIAL,
    productID VARCHAR(100),
    eventID VARCHAR(100) NOT NULL,
    isManagedService BOOLEAN NOT NULL,
    componentList VARCHAR(100),
    datetime TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc') NOT NULL,
    PRIMARY KEY(scanID),
    FOREIGN KEY (productID) REFERENCES covscanrest.products(productID)
);

CREATE TABLE IF NOT EXISTS covscanrest.archive (
    scanID SERIAL,
    productID VARCHAR(100),
    eventID VARCHAR(100) NOT NULL,
    isManagedService BOOLEAN NOT NULL,
    componentList VARCHAR(100),
    datetime TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc') NOT NULL,
    PRIMARY KEY(scanID),
    FOREIGN KEY (productID) REFERENCES covscanrest.products(productID)
);

CREATE TABLE IF NOT EXISTS covscanrest.gitscans (
    id SERIAL,
    buildSystemType VARCHAR(80),
    repository VARCHAR(150),
    reference VARCHAR(100),
    commitId VARCHAR(100),
    PRIMARY KEY(id)
);

CREATE TABLE IF NOT EXISTS covscanrest.pncscans(
    id SERIAL,
    buildSystemType VARCHAR(80),
    buildId VARCHAR(100),
    reference VARCHAR(100),
    commitId VARCHAR(100),
    PRIMARY KEY(id)
);

CREATE TABLE IF NOT EXISTS covscanrest.brewscans(
    id SERIAL,
    buildSystemType VARCHAR(80),
    brewId VARCHAR(100),
    brewNVR VARCHAR(100),
    pncId VARCHAR(100),
    artifactType VARCHAR(100),
    fileName VARCHAR(100),
    builtfromSource BOOLEAN,
    PRIMARY KEY(id)
);