yarn db:generate
yarn db:generate executes tsx scripts/mikro-modules.ts generate, iterating through every enabled module and creating MikroORM migrations when entity metadata changes.
Usage
yarn db:generate
The script requires a valid DATABASE_URL pointing to the Postgres database used for diffing.
What Happens
- Loads enabled modules via
scripts/shared/modules-config.ts. - For each module, resolves entity definitions (
data/entities.tsorschema.ts) and spins up a temporary MikroORM instance. - Writes migrations into
packages/<module>/src/modules/<module>/migrations. App overrides fall back tosrc/modules/<module>/migrations. - Renames generated files and migration classes to include the module suffix (e.g.
_auth) to keep names unique across modules. - Prints a summary such as
auth: generated Migration20240214_authordirectory: no changes.
Typical Workflow
- Run
yarn db:generateafter modifying entity definitions. - Inspect the generated TypeScript migration and adjust it if necessary.
- Commit the migration alongside your entity changes.
- Apply migrations with
yarn db:migrateornpm run db:migrate.
Troubleshooting
- Missing
DATABASE_URL— set it in your shell or.envbefore running the command. - No changes detected — ensure you saved the entity file and that MikroORM metadata can resolve it from the module registry.
- Permission errors writing migrations — confirm the module directory is writable (especially when working inside app overlays or read-only package installs).