CREATE TABLE resource_share_invitations (
 token_hash VARCHAR(64) PRIMARY KEY,
 resource_kind VARCHAR(16) NOT NULL,
 resource_slug VARCHAR(255) NOT NULL,
 user_id BIGINT NOT NULL,
 permission VARCHAR(2) NOT NULL,
 created_by BIGINT NOT NULL,
 expires_at TEXT NOT NULL,
 accepted_at TEXT NULL,
 created_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP),
 UNIQUE KEY uq_resource_share_invitation (resource_kind, resource_slug, user_id),
 CONSTRAINT fk_share_invitation_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
 CONSTRAINT fk_share_invitation_creator FOREIGN KEY(created_by) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX idx_resource_share_invitations_user ON resource_share_invitations(user_id);
