Add missing CHECK constraints to database tables

This commit is contained in:
silverpill 2023-04-05 19:49:51 +00:00
parent b9fdb1ccf4
commit 20080333d0
3 changed files with 19 additions and 5 deletions

View file

@ -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

View file

@ -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);

View file

@ -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)
);