seiteBEGIN;

CREATE TABLE IF NOT EXISTS community.user_block (
    id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    blocker_id INTEGER NOT NULL REFERENCES community."user"(id) ON DELETE CASCADE,
    blocked_id INTEGER NOT NULL REFERENCES community."user"(id) ON DELETE CASCADE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT user_block_not_self CHECK (blocker_id <> blocked_id),
    CONSTRAINT user_block_unique UNIQUE (blocker_id, blocked_id)
);

CREATE INDEX IF NOT EXISTS user_block_blocker_id_idx
    ON community.user_block (blocker_id);

COMMIT;
