-- Add migration script here

CREATE TABLE metadata (
    secret_path TEXT PRIMARY KEY NOT NULL,

    cas_required INTEGER NOT NULL, -- no bool datatype in sqlite
    created_time TIMESTAMP NOT NULL,
    delete_version_after TEXT, -- Maybe NOT NULL
    max_versions INTEGER NOT NULL,
    -- current_version INTEGER NOT NULL,
    -- oldest_version INTEGER NOT NULL,
    updated_time TIMESTAMP NOT NULL,
    custom_data TEXT
);

CREATE TABLE secret_versions (
    secret_data TEXT NOT NULL,
    
    created_time TIMESTAMP NOT NULL,
    deletion_time TIMESTAMP,

    version_number INTEGER NOT NULL DEFAULT 0,
    secret_path TEXT NOT NULL,
    PRIMARY KEY (secret_path, version_number),
    FOREIGN KEY (secret_path) REFERENCES metadata(secret_path)
);

CREATE INDEX idx_secret_versions_secret_path ON secret_versions (secret_path);
