CREATE TYPE project_role AS ENUM (
    'member',
    'admin',
    'owner'
);

CREATE TYPE membership_status AS ENUM (
    'invited',
    'active',
    'suspended'
);

CREATE TABLE project_memberships (
    project_uuid UUID NOT NULL
        REFERENCES projects(uuid)
        ON DELETE CASCADE,

    user_uuid UUID NOT NULL
        REFERENCES accounts(uuid)
        ON DELETE CASCADE,

    role project_role NOT NULL,
    status membership_status NOT NULL DEFAULT 'active',

    invited_by UUID NULL
        REFERENCES accounts(uuid),
    joined_at TIMESTAMP NULL,
    PRIMARY KEY (project_uuid, user_uuid)
);

CREATE INDEX idx_project_memberships_user 
ON project_memberships(user_uuid); 

CREATE INDEX idx_project_memberships_project 
ON project_memberships(project_uuid);
