Databases & migrations

Swappable database providers, local-first db commands, the cloud project database, and the migration discipline.

Providers

PostgreSQL, MySQL, and SQLite are first-class, swappable bonds — the same handlers run on any of them. Change providers with one command:

npx mlcl swap @molecule/api-database-mysql

Local development

npx mlcl db migrate          # apply migrations (runs the scaffolded migrate.ts)
npx mlcl db reset --force    # drop/recreate + migrate  (DESTRUCTIVE)
npx mlcl db console          # psql on the project DB
npx mlcl db url              # print DATABASE_URL

Local defaults work out of the box (SQLite, or Postgres if you have it running); credentials live in api/.env.

The cloud database

npx mlcl db info --project <id>        # connection + settings
npx mlcl db tables --project <id>      # (also: query)
npx mlcl db backup --project <id>      # (also: backup-list / restore)

Migration discipline

  • Every schema change ships a migration — handlers never alter tables at runtime.
  • Migrations are ordered SQL under api/migrations/, applied by db migrate (and automatically on deploy).
  • Never edit an applied migration — add a new one that moves the schema forward.
Careful

db reset --force drops data. It is for local development only.