Auto-migrate: Drop schema objects if they already exist and re-create thembased on model definitions. Existing data will be lost.
Warning: Auto-update will attempt to preserve data whileupdating the schema in your target database, but this is not guaranteed to besafe.
Please check the documentation for your specific connector(s) for a detailedbreakdown of behaviors for automigrate!
Examples
In the future, we would like to provide finer-grained control of database schemaupdates, learn more in the GitHub issue
To automatically update the database schema whenever the application is started,modify your main script to execute app.migrateSchema()
after the applicationwas bootstrapped (all repositories were registered) but before it is actuallystarted.
src/index.ts
It’s usually better to have more control about the database migration andtrigger the updates explicitly. To do so, projects scaffolded using come with a custom CLI script src/migrate.ts
to run schema migration. Checkout e.g.Todo example appto see the full source code of the script.
The migration process consists of two steps now:
- Build the project:
- Migrate database schemas (alter existing tables):
Alternatively, you can also tell the migration script to drop any existingschemas:
In some scenarios, the application may need to define additional schemaconstraints or seed the database with predefined model instances. This can beachieved by overriding the method provided by the mixin.
The example below shows how to do so in our Todo example application.