CREATE TABLE IF NOT EXISTS workspace_membership (
    id          BIGSERIAL PRIMARY KEY,
    workspace_id UUID NOT NULL,
    user_id     UUID NOT NULL,
    role        VARCHAR(50) NOT NULL DEFAULT 'member',
    status      VARCHAR(50) NOT NULL DEFAULT 'active',
    invited_by  UUID,
    joined_at   TIMESTAMPTZ NOT NULL,
    UNIQUE (workspace_id, user_id)
);

CREATE UNIQUE INDEX idx_workspace_membership_ws_user ON workspace_membership (workspace_id, user_id);
CREATE INDEX idx_workspace_membership_user ON workspace_membership (user_id);
