yarn db:greenfield
yarn db:greenfield executes saasframe db greenfield --yes. It is designed for development only when you want to rebuild the schema from scratch.
Usage
# Using yarn script
yarn db:greenfield
# Using CLI directly (requires --yes flag for confirmation)
yarn saasframe db greenfield --yes
What the Command Does
- Cleans every module's
migrations/directory by deleting generated migration.tsfiles and snapshot JSON files. - Removes checksum files under the repository's
/generatedfolder. - Drops per-module MikroORM migration tables (
mikro_orm_migrations_<module>). - Drops all tables in the
publicschema of the database referenced byDATABASE_URL. - Regenerates fresh migrations for every enabled module by internally calling
saasframe db generate. - Applies the newly generated migrations immediately via
saasframe db migrate.
Safety Considerations
- The command irreversibly wipes the target database. Never run it against production or staging environments.
- Ensure
DATABASE_URLpoints to a disposable database before executing. - Because it removes migration files, you may want to stash or commit any pending migration work beforehand.
Suggested Workflow
- Stop any dev servers using the database.
- Run
yarn db:greenfield. - Optionally execute
yarn initializeto reseed data and example content.
Troubleshooting
- Permission errors when dropping tables — verify the database user has privileges to drop tables and alter replication roles.
- Migrations fail after regeneration — inspect generated migration files and adjust entity definitions accordingly, then re-run
yarn db:greenfieldoryarn db:migrate.