diff --git a/CHANGELOG.md b/CHANGELOG.md index 1971af0..df58e86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Process incoming `Move()` activities in background. - Allow custom emojis with `image/webp` media type. +### Fixed + +- Added missing `CHECK` constraints to database tables. + ## [1.19.1] - 2023-03-31 ### Changed diff --git a/mitra-models/migrations/V0051__relationship__source_id_target_id_not_equal.sql b/mitra-models/migrations/V0051__relationship__source_id_target_id_not_equal.sql new file mode 100644 index 0000000..4476f44 --- /dev/null +++ b/mitra-models/migrations/V0051__relationship__source_id_target_id_not_equal.sql @@ -0,0 +1,5 @@ +ALTER TABLE relationship ADD CONSTRAINT relationship_source_id_target_id_check CHECK (source_id != target_id); +ALTER TABLE follow_request ADD CONSTRAINT follow_request_source_id_target_id_check CHECK (source_id != target_id); +ALTER TABLE post_link ADD CONSTRAINT post_link_source_id_target_id_check CHECK (source_id != target_id); +ALTER TABLE invoice ADD CONSTRAINT invoice_sender_id_recipient_id_check CHECK (sender_id != recipient_id); +ALTER TABLE subscription ADD CONSTRAINT subscription_sender_id_recipient_id_check CHECK (sender_id != recipient_id); diff --git a/mitra-models/migrations/schema.sql b/mitra-models/migrations/schema.sql index 9141aae..8839db7 100644 --- a/mitra-models/migrations/schema.sql +++ b/mitra-models/migrations/schema.sql @@ -95,7 +95,8 @@ CREATE TABLE relationship ( source_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE, target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE, relationship_type SMALLINT NOT NULL, - UNIQUE (source_id, target_id, relationship_type) + UNIQUE (source_id, target_id, relationship_type), + CHECK (source_id != target_id) ); CREATE TABLE follow_request ( @@ -104,7 +105,8 @@ CREATE TABLE follow_request ( target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE, activity_id VARCHAR(250) UNIQUE, request_status SMALLINT NOT NULL, - UNIQUE (source_id, target_id) + UNIQUE (source_id, target_id), + CHECK (source_id != target_id) ); CREATE TABLE post ( @@ -166,7 +168,8 @@ CREATE TABLE post_tag ( CREATE TABLE post_link ( source_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE, target_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE, - PRIMARY KEY (source_id, target_id) + PRIMARY KEY (source_id, target_id), + CHECK (source_id != target_id) ); CREATE TABLE emoji ( @@ -219,7 +222,8 @@ CREATE TABLE invoice ( amount BIGINT NOT NULL CHECK (amount >= 0), invoice_status SMALLINT NOT NULL DEFAULT 1, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - UNIQUE (chain_id, payment_address) + UNIQUE (chain_id, payment_address), + CHECK (sender_id != recipient_id) ); CREATE TABLE subscription ( @@ -230,5 +234,6 @@ CREATE TABLE subscription ( chain_id VARCHAR(50) NOT NULL, expires_at TIMESTAMP WITH TIME ZONE NOT NULL, updated_at TIMESTAMP WITH TIME ZONE NOT NULL, - UNIQUE (sender_id, recipient_id) + UNIQUE (sender_id, recipient_id), + CHECK (sender_id != recipient_id) );