abhyas docsStorybook

Database

Code: app.abhyas.database.dev. Data: Supabase Postgres, one project per environment (dev wvwcibiijcwvtcjbxjvt, prd pqncgrgssiopykgctjge). app.abhyas.database.prd only deploys releases.

Layout

PathWhat it is
prisma/schema.prismaThe tables, columns, keys and relations, with notes
prisma/migrations/Every change, in order. 0_init is the database as it was when migrations began
prisma/shadow-supabase.sqlStands in for what Supabase provides (auth.users, auth.uid(), roles) in local and CI databases
prisma.config.tsPrisma's settings: auth.users belongs to Supabase, so Prisma never changes it
scripts/local-db.mjsA local PostgreSQL 17 for trying migrations (npm run db:local)
deploy/prd/Copies of database.prd's workflows

Making a change

You need Node 22.12 or newer. Once: npm ci, cp .env.example .env, then npm run db:local in its own terminal.

  1. Edit prisma/schema.prisma.
  2. npm run migrate:new -- <name> writes the migration without applying it. Read it.
  3. Add by hand what Prisma can't express: row-level security, functions, triggers, views, grants. Follow 0_init.
  4. npm run migrate:dev applies it to the local Postgres.
  5. npm run check must pass: the migrations produce exactly schema.prisma.
  6. Commit the schema and migration together and open a pull request. Merging applies it to dev.

Never edit a migration that has been applied; write a new one. Migrations only move forward. Other commands: npm run status, npm run format. Delete .local/ to reset the local database.

Tables

disciplines → chapters → topics, each with a uuid and a readable code (mathematics, 04, 04-13). Chapters and topics carry lesson_latex (the Concept tab). Sources and tags belong to a discipline. Each discipline has its own question bank, made by create_question_bank(slug):

Table or viewWhat it holds
<slug>_questionsEach question: main topic, source and folder, question_latex, official_answer_latex and its status
<slug>_question_topicsTopics a question is in besides its main one
<slug>_question_tagsIts tags
<slug>_question_topic_links (view)Every question and topic pair
<slug>_practice_questions (view)What practice loads
question_progressEach user's answers, files, ratings and notes
recordsEach user's saved papers and results

To add a discipline's bank: a migration with select public.create_question_bank('physics');, copies of the three Mathematics… models in schema.prisma renamed, then npm run check.

Access

Workflows

WorkflowRepositoryWhat it does
🚀 Deploy (migrations.yml)database.devOn pull requests: check. On merge: migrate the dev database, make a release with bundle.zip
Sync from the bookdatabase.devDaily: opens a PR with a migration of the book's changes
🚀 Deploydatabase.prdBy hand: applies a release to the prd database
Export the question banksdatabase.prdNightly: commits exports/<slug>.sql to the exports branch

SUPABASE_DB_URL is the Session pooler connection string (port 5432). The direct connection is IPv6 only, which GitHub's runners can't reach. A database with no migration history is set up by the deploy job itself on its first deploy.