-- Add migration script here

CREATE TABLE kv2_metadata (
    engine_path TEXT NOT NULL,
    secret_path TEXT 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,

    PRIMARY KEY (engine_path, secret_path)
);

CREATE TABLE kv2_secret_version (
    engine_path TEXT NOT NULL,
    secret_path TEXT NOT NULL,

    version_number INTEGER NOT NULL,
    secret_data TEXT NOT NULL,
    created_time DATETIME NOT NULL,
    deletion_time DATETIME,

    PRIMARY KEY (engine_path, secret_path, version_number),
    FOREIGN KEY (engine_path, secret_path) REFERENCES kv2_metadata(engine_path, secret_path)
);
