From cc1fbf5b7d1cabcf1199d63dc484f960462e99ce Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Tue, 2 Jun 2026 08:46:34 +0200 Subject: [PATCH] feat(db): RESTRICT vocabulary deletes; non-empty label/lang constraints --- crates/db/migrations/0002_vocabularies_authorities.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/db/migrations/0002_vocabularies_authorities.sql b/crates/db/migrations/0002_vocabularies_authorities.sql index 668de69..012c430 100644 --- a/crates/db/migrations/0002_vocabularies_authorities.sql +++ b/crates/db/migrations/0002_vocabularies_authorities.sql @@ -6,15 +6,15 @@ CREATE TABLE vocabulary ( CREATE TABLE term ( id UUID PRIMARY KEY, - vocabulary_id UUID NOT NULL REFERENCES vocabulary (id) ON DELETE CASCADE, + vocabulary_id UUID NOT NULL REFERENCES vocabulary (id) ON DELETE RESTRICT, external_uri TEXT -- e.g. Getty AAT / KulturNav / Wikidata URI ); CREATE INDEX term_vocabulary_idx ON term (vocabulary_id); CREATE TABLE term_label ( term_id UUID NOT NULL REFERENCES term (id) ON DELETE CASCADE, - lang TEXT NOT NULL, -- BCP-47, e.g. 'sv', 'en' - label TEXT NOT NULL, + lang TEXT NOT NULL CHECK (lang <> ''), + label TEXT NOT NULL CHECK (label <> ''), PRIMARY KEY (term_id, lang) ); @@ -28,7 +28,7 @@ CREATE INDEX authority_kind_idx ON authority (kind); CREATE TABLE authority_label ( authority_id UUID NOT NULL REFERENCES authority (id) ON DELETE CASCADE, - lang TEXT NOT NULL, - label TEXT NOT NULL, + lang TEXT NOT NULL CHECK (lang <> ''), + label TEXT NOT NULL CHECK (label <> ''), PRIMARY KEY (authority_id, lang) );