Skip to content

Instantly share code, notes, and snippets.

@filinvadim
Created August 30, 2018 08:44
Show Gist options
  • Save filinvadim/4e170930e9f8dbd62647267f2bb607cf to your computer and use it in GitHub Desktop.
Save filinvadim/4e170930e9f8dbd62647267f2bb607cf to your computer and use it in GitHub Desktop.
MtM
CREATE TABLE user_friend (
id BIGSERIAL NOT NULL,
user_id BIGINT NOT NULL,
friend_id BIGINT NOT NULL,
created_at TIMESTAMP(0) NOT NULL DEFAULT now(),
CONSTRAINT pk_user_friend_id PRIMARY KEY (id),
CONSTRAINT fk_user_friend_user_id FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE,
UNIQUE(user_id, friend_id),
CONSTRAINT not_equal_id CHECK (user_id != friend_id)
);
ALTER TABLE user_friend
owner TO app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment