Databases & migrations

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

Providers

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

mlcl swap @molecule/api-database-mysql

Local development

mlcl db migrate          # apply migrations (runs the scaffolded migrate.ts)
mlcl db reset --force    # drop/recreate + migrate  (DESTRUCTIVE)
mlcl db console          # psql on the project DB
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

mlcl db info --project <id>        # connection + settings
mlcl db tables --project <id>      # (also: query)
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.