CREATE TABLE IF NOT EXISTS repos (
    id         INTEGER  PRIMARY KEY AUTOINCREMENT,
    name       TEXT     NOT NULL UNIQUE,
    type       TEXT     NOT NULL CHECK(type IN ('apt','rpm','docker','binary')),
    source_url TEXT     NOT NULL,
    frozen     BOOLEAN  NOT NULL DEFAULT FALSE,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS artifacts (
    id         INTEGER  PRIMARY KEY AUTOINCREMENT,
    repo_id    INTEGER  NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
    name       TEXT     NOT NULL,
    version    TEXT     NOT NULL,
    path       TEXT     NOT NULL,
    checksum   TEXT     NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS snapshots (
    id         INTEGER  PRIMARY KEY AUTOINCREMENT,
    repo_id    INTEGER  NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
    label      TEXT     NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
