-- Stars: a user's bookmark on a repo. A row goes with either the user or the repo. -- The primary key serves "repos starred by a user"; the index serves the per-repo count. CREATE TABLE stars ( user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, repo_id TEXT NOT NULL REFERENCES repos(id) ON DELETE CASCADE, created_at TEXT NOT NULL, PRIMARY KEY (user_id, repo_id)); CREATE INDEX stars_repo_id ON stars(repo_id);