-- File written by ace2sql.py
-- 
PRAGMA foreign_keys = off;
BEGIN TRANSACTION;

-- Category -------------------------
CREATE TABLE IF NOT EXISTS Category (
    CatName TEXT PRIMARY KEY
);

INSERT INTO Category ( CatName )
    VALUES
        ("BIRCH - Administration"),
        ("Database"),
        ("Gel Electrophoresis"),
        ("Gene Expression"),
        ("Genetics"),
        ("Laboratory Information Management"),
        ("Molecular Markers"),
        ("Phylogeny"),
        ("Programming Tools"),
        ("Sequence"),
        ("Sequence - Annotation and Gene Discovery"),
        ("Sequence - Database Similarity Search"),
        ("Sequence - DNA Sequencing"),
        ("Sequence - File Formatting"),
        ("Sequence - Multiple Alignment"),
        ("Sequence - Oligonucleotides"),
        ("Sequence - Pairwise Similarity"),
        ("Sequence - Pattern Discovery and Matching"),
        ("Sequence - Phylogeny"),
        ("Sequence - Protein"),
        ("Sequence - Protein Structure"),
        ("Sequence - Restriction Analysis"),
        ("Sequence - RNA Structure"),
        ("Utilities");

-- Platform -------------------------
CREATE TABLE IF NOT EXISTS Platform (
    PlatName TEXT PRIMARY KEY
);

INSERT INTO Platform ( PlatName )
    VALUES
        ("linux-x86_64"),
        ("linux-arm64"),
        ("osx-x86_64"),
        ("macos-arm64");

-- ComType -------------------------
CREATE TABLE IF NOT EXISTS ComType (
    Type TEXT PRIMARY KEY
);

INSERT INTO ComType ( Type )
    VALUES
        ("command"),
        ("interactive"),
        ("gui"),
        ("_birch_"),
        ("birchadmin"),
        ("bldna"),
        ("blnalign"),
        ("blprotein"),
        ("blpalign"),
        ("bldata"),
        ("blmarker"),
        ("blnfetch"),
        ("blpfetch"),
        ("blreads"),
        ("blncbi"),
        ("bltable"),
        ("bltree");

-- File -------------------------
CREATE TABLE IF NOT EXISTS File (
    Name TEXT PRIMARY KEY,
    Description TEXT,
    Action TEXT,
    PathOrURL TEXT
);


-- Package -------------------------
CREATE TABLE IF NOT EXISTS Package (
    Name TEXT PRIMARY KEY,
    Description TEXT,
    Installation TEXT
);


-- Program -------------------------
CREATE TABLE IF NOT EXISTS Program (
    Name TEXT PRIMARY KEY,
    Description TEXT,
    Installation TEXT
);


-- PkgCat -------------------------
CREATE TABLE IF NOT EXISTS PkgCat (
    Package TEXT NOT NULL,
    Category TEXT NOT NULL ,
    FOREIGN KEY (Package) REFERENCES Package (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Category) REFERENCES Category (CatName) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- PkgDoc -------------------------
CREATE TABLE IF NOT EXISTS PkgDoc (
    Package TEXT NOT NULL,
    Documentation TEXT NOT NULL ,
    FOREIGN KEY (Package) REFERENCES Package (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Documentation) REFERENCES File (Name) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- PkgProg -------------------------
CREATE TABLE IF NOT EXISTS PkgProg (
    Package TEXT NOT NULL,
    Program TEXT NOT NULL ,
    FOREIGN KEY (Package) REFERENCES Package (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- PkgDat -------------------------
CREATE TABLE IF NOT EXISTS PkgDat (
    Package TEXT NOT NULL,
    Data TEXT NOT NULL ,
    FOREIGN KEY (Package) REFERENCES Package (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Data) REFERENCES File (Name) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- PkgPlat -------------------------
CREATE TABLE IF NOT EXISTS PkgPlat (
    Package TEXT NOT NULL,
    Platform TEXT NOT NULL ,
    FOREIGN KEY (Package) REFERENCES Package (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Platform) REFERENCES Platform (PlatName) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- ProgCat -------------------------
CREATE TABLE IF NOT EXISTS ProgCat (
    Program TEXT NOT NULL,
    Category TEXT NOT NULL ,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Category) REFERENCES Category (CatName) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- ProgLaunch -------------------------
CREATE TABLE IF NOT EXISTS ProgLaunch (
    Program TEXT REFERENCES Program NOT NULL, 
    ComType TEXT REFERENCES ComType NOT NULL,
    Command TEXT,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (ComType) REFERENCES ComType (Type) ON UPDATE CASCADE ON DELETE CASCADE
);


-- ProgDoc -------------------------
CREATE TABLE IF NOT EXISTS ProgDoc (
    Program TEXT NOT NULL,
    Documentation TEXT NOT NULL ,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Documentation) REFERENCES File (Name) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- ProgDat -------------------------
CREATE TABLE IF NOT EXISTS ProgDat (
    Program TEXT NOT NULL,
    Data TEXT NOT NULL ,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Data) REFERENCES File (Name) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- ProgSampleInp -------------------------
CREATE TABLE IF NOT EXISTS ProgSampleInp (
    Program TEXT NOT NULL,
    SampleInput TEXT NOT NULL ,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (SampleInput) REFERENCES File (Name) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- ProgSampleOut -------------------------
CREATE TABLE IF NOT EXISTS ProgSampleOut (
    Program TEXT NOT NULL,
    SampleOutput TEXT NOT NULL ,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (SampleOutput) REFERENCES File (Name) ON UPDATE CASCADE ON DELETE CASCADE 
);


-- ProgPlat -------------------------
CREATE TABLE IF NOT EXISTS ProgPlat (
    Program TEXT NOT NULL,
    Platform TEXT NOT NULL ,
    FOREIGN KEY (Program) REFERENCES Program (Name) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY (Platform) REFERENCES Platform (PlatName) ON UPDATE CASCADE ON DELETE CASCADE 
);

COMMIT TRANSACTION;
PRAGMA foreign_keys = on;
.exit
