When developing an application, you need to synchronize model changes into the database. Changing the code of your entity files is not sufficient by itself. You need either to set
ormconfig.json or to use migrations.
synchronize option is set to
true by default in FoalTS. It auto creates the database schema on every application launch and thus allows fast development. But it is unsafe to use it on production once you get data in your database.
Migrations are TS/JS files that execute SQL queries to update the database schema. TypeORM provides great tools to auto generate these migrations based on model changes.
Migrations are stored in the
npm run build:app # Build the entitiesnpm run migration:generate -- -n my-migration # Generate the migrationnpm run build:migrations # Build the migrationsnpm run migration:run # Run the migrations
npm run migration:run
npm run migration:revert
Find more details in the TypeORM docs.