29 lines
1.2 KiB
SQL
29 lines
1.2 KiB
SQL
-- 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)
|
|
);
|
|
|
|
CREATE UNIQUE INDEX IF NOT EXISTS opt_dataset_versions_idempotency_idx
|
|
ON opt_dataset_versions (tenant_id, idempotency_key)
|
|
WHERE idempotency_key IS NOT NULL;
|
|
|
|
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.';
|