-- schema.sql - Structure initiale de la base Erminig

CREATE TABLE packages (
    name TEXT PRIMARY KEY,
    version TEXT NOT NULL,
    revision INTEGER NOT NULL,
    status TEXT NOT NULL, -- draft, built, failed, validated
    blocked BOOLEAN NOT NULL DEFAULT 0,
    created_at TEXT DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE sources (
    package_name TEXT,
    url TEXT,
    hash TEXT,
    FOREIGN KEY (package_name) REFERENCES packages(name)
);

CREATE TABLE dependencies (
    package_name TEXT,
    dependency TEXT,
    type TEXT, -- build, runtime, check
    FOREIGN KEY (package_name) REFERENCES packages(name)
);

CREATE TABLE builds (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    package_name TEXT,
    version TEXT,
    revision INTEGER,
    start_time TEXT DEFAULT CURRENT_TIMESTAMP,
    end_time TEXT,
    status TEXT, -- success, failed
    log TEXT,
    FOREIGN KEY (package_name) REFERENCES packages(name)
);
