Spec the SQL that resolves a user's feature flags
Your task
Your Postgres app decides which features each user gets from 3 sources: their plan, grants to their org and overrides for that user. An agent will write the query, plus a thin TypeScript wrapper, that answers "which features does this user have?"
Write the spec you would hand the agent.
What you know:
features(key)lists every feature, andusers(id, org_id, plan_id)holds each user's org and planplan_features(plan_id, feature_key)lists what each plan includesorg_grants(org_id, feature_key, enabled)anduser_overrides(user_id, feature_key, enabled)can turn a feature on or off- the product rule: a user override beats an org grant, and an org grant beats the plan
Then, in a few sentences: what does "query the user's enabled features" get wrong in SQL?