From 298c965448f6f66757034262eb36e00ea55f853e Mon Sep 17 00:00:00 2001 From: Simon Axelsson Date: Mon, 7 Sep 2026 18:00:58 +0200 Subject: [PATCH] feat: add durable dataset version store --- sql/012_dataset_versions.sql | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 sql/012_dataset_versions.sql diff --git a/sql/012_dataset_versions.sql b/sql/012_dataset_versions.sql new file mode 100644 index 0000000..85c2d86 --- /dev/null +++ b/sql/012_dataset_versions.sql @@ -0,0 +1,26 @@ +-- Durable canonical metadata for 0pt dataset versions. +-- Bytes remain canonical ST0RE artifacts referenced by artifact_refs. + +CREATE TABLE IF NOT EXISTS opt_dataset_versions ( + dataset_id text NOT NULL REFERENCES opt_datasets(dataset_id) ON DELETE RESTRICT, + version integer NOT NULL CHECK (version > 0), + tenant_id text NOT NULL, + project_id text NOT NULL, + artifact_refs text[] NOT NULL CHECK (cardinality(artifact_refs) > 0), + schema_version text NOT NULL, + record_count bigint CHECK (record_count IS NULL OR record_count >= 0), + description text, + created_at timestamptz NOT NULL DEFAULT now(), + created_by text NOT NULL, + correlation_id text, + idempotency_key text, + PRIMARY KEY (dataset_id, version), + CONSTRAINT opt_dataset_versions_idempotency + UNIQUE NULLS NOT DISTINCT (tenant_id, idempotency_key) +); + +CREATE INDEX IF NOT EXISTS opt_dataset_versions_tenant_dataset_idx + ON opt_dataset_versions (tenant_id, dataset_id, version DESC); + +COMMENT ON TABLE opt_dataset_versions IS + 'Immutable 0pt dataset-version metadata. Content bytes remain in ST0RE artifacts.';