14 lines
555 B
SQL
14 lines
555 B
SQL
-- Add migration script here
|
|
CREATE TYPE status AS ENUM ('pending', 'accepted', 'blocked');
|
|
|
|
CREATE TABLE relationships (
|
|
id SERIAL PRIMARY KEY,
|
|
from_user INTEGER NOT NULL REFERENCES users(id),
|
|
to_user INTEGER NOT NULL REFERENCES users(id),
|
|
status status NOT NULL DEFAULT 'pending',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
CONSTRAINT no_self_relationship CHECK (from_user != to_user),
|
|
CONSTRAINT unique_relationship UNIQUE (from_user, to_user)
|
|
);
|