Open MercatoDocsSearch docsAPI reference

CLI

yarn db:greenfield

This command deletes database state and rebuilds migrations. Use it only against a disposable development database whose contents you intend to replace.

yarn db:greenfield executes mercato 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 mercato db greenfield --yes

What the Command Does

  1. Cleans every module's migrations/ directory by deleting generated migration .ts files and snapshot JSON files.
  2. Removes checksum files under the repository's /generated folder.
  3. Drops per-module MikroORM migration tables (mikro_orm_migrations_<module>).
  4. Drops all tables in the public schema of the database referenced by DATABASE_URL.
  5. Regenerates fresh migrations for every enabled module by internally calling mercato db generate.
  6. Applies the newly generated migrations immediately via mercato db migrate.

Safety Considerations

Suggested Workflow

  1. Stop any dev servers using the database.
  2. Run yarn db:greenfield.
  3. Optionally execute yarn initialize to reseed data and example content.

Troubleshooting

Previous: yarn db:generate · Next: yarn db:migrate