docs: correct schema reference against the live database - #530
Merged
Conversation
Verified docs/DATABASE_SCHEMA.md table by table against the local database (which matches cloud — see below) and fixed what was wrong. lib/database.types.ts needed no change: regenerating it from the local DB produces a byte-identical file apart from the __InternalSupabase header that `--linked` adds. Local migrations, cloud schema and the committed types are all in sync. Columns that did not exist as documented (each one silently breaks a query or a .rpc() call): - enrollments: still listed product_id/subscription_id and their CHECK constraint, all dropped by the entitlements migration. entitlements itself was absent from the doc entirely despite being the source of truth for course access. - plans: documented `name`, `interval`, `stripe_*_id`; actually plan_name, duration_in_days, provider_*_id. - subscriptions: documented `status`, `stripe_subscription_id`, `created_at`; actually subscription_status, provider_subscription_id, created. - exercise_completions: documented student_id + submission/is_correct/ ai_feedback; actually user_id + completed_by/score. - exercises: documented initial_code/solution_code/test_cases — none exist. - products: documented stripe_product_id/stripe_price_id; actually provider_*_id. - exam_questions: documented a `sequence` column that does not exist. - exam_submissions: documented is_reviewed; actually review_status. - gamification: documented 12 tables including gamification_daily_caps and gamification_challenges, neither of which exists. There are 10. - transactions: documented one composite unique index; there are three (product-shaped, plan-shaped, provider_charge_id idempotency). - currency_type: documented usd/eur; there are eight values. - RPCs: handle_new_subscription is missing _start_date, save_exam_feedback takes nine p_-prefixed args not six, award_xp's signature was wrong in CLAUDE.md and AI_AGENT_GUIDE.md. - Table count was "65+" everywhere; it is 116. Also adds what the doc had no way to keep right on its own: - "Verifying this document" — the diff/introspection commands to check any claim here against the database in one line. - "Tables without tenant_id" — the full 55-table list plus the query that regenerates it. Filtering these by tenant_id errors the whole query, which is a recurring source of blank pages. - docs/README.md rewritten: it indexed six files that do not exist (API_ROUTES.md, RLS_POLICIES.md, four features/*.md) and advertised the project as "Phase 5 complete, Phase 6 next". - docs/ACTUAL_SCHEMA.md now carries a stale banner — it claims to be the actual live schema and is the first thing a name-search finds, but it is a February 2026 snapshot documenting dropped columns. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01853LDokPbhv9Kg9Ctz9DB5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #529. Verified the schema docs table-by-table against the live database instead of trusting the prose.
Types: no change needed
lib/database.types.tsis in sync. Regenerating from the local DB produces a byte-identical file except the__InternalSupabaseheader that--linkedadds:So local migrations, cloud schema, and the committed types all agree.
The schema doc did not
Each of these silently breaks a query or an
.rpc()call:enrollments.product_id/subscription_id+ CHECKentitlements— the source of truth for access — was missing from the doc entirelyplans.name,.interval,.stripe_*_idplan_name,duration_in_days,provider_*_idsubscriptions.status,.stripe_subscription_id,.created_atsubscription_status,provider_subscription_id,createdexercise_completions.student_id+submission/is_correct/ai_feedbackuser_id+completed_by/scoreexercises.initial_code/solution_code/test_casesproducts.stripe_product_id/stripe_price_idprovider_product_id/provider_price_idexam_questions.sequenceexam_submissions.is_reviewedreview_statusgamification_daily_caps,gamification_challengestransactionsprovider_charge_ididempotency)currency_type= usd, eurhandle_new_subscription(3 args),save_exam_feedback(6 args),award_xp(p_user_id, p_action_type, p_reference_id)p_-prefixed), andaward_xp(_user_id, _action_type, _xp_amount, _reference_id, _reference_type)Making it self-correcting
The doc drifted because there was no cheap way to check it. Added:
psqlintrospection commands for columns, enums and exact RPC signatures, plus the source-of-truth ordering (generated types → live DB → this page).tenant_id— the full 55-table list and the query that regenerates it. Filtering one of these bytenant_iderrors the entire query; it's a recurring cause of blank pages.Two more traps for new devs
docs/README.mdindexed six files that don't exist (API_ROUTES.md,RLS_POLICIES.md, fourfeatures/*.md) and advertised the project as "Phase 5 complete, Phase 6 next". Rewritten as a real map, with a note on which parts ofdocs/are historical records rather than references.docs/ACTUAL_SCHEMA.mdclaims to be "the actual column names from the live database" and is what a name-search surfaces first — but it's a Feb 2026 snapshot still documenting the droppedenrollmentscolumns. Now carries a stale banner pointing at the real sources.CLAUDE.mdalso had the wrong RPC signatures, a four-file E2E test list where 33 specs now live, andcreator@codeacademy.comlabelled teacher when the seed makes it admin.Test plan
Docs only.
information_schema,pg_indexes,pg_constraint,pg_enum,pg_get_function_identity_arguments).lib/database.types.tsdiffed against freshly generated local types.🤖 Generated with Claude Code
https://claude.ai/code/session_01853LDokPbhv9Kg9Ctz9DB5