Stop running data migrations in migrations loop
See aa1cc994 (comment 1921628).
There are two kind of migrations:
- Classic migrations, that typeorm will run based on a timestamp. Those migrations should not read things from database.
- Data migrations: a bank was renamed, a field should be updated (ex: the balance is computed and then set when migrating to the real balance)
Data migrations will use methods such as Transaction.all
or Transaction.byAccountId
that internally uses .all()
. The .all()
method then proceeds to read every field from the model (which is always the latest version, since it is code, and not model that existed before the classic migrations) to generate the query (with aliases etc.) instead of a simple SELECT * FROM
.
Data migrations are currently only run on import. To update the data on launch we call the data migration in a classic migration (ex: rename a bank field).
If a data migration is called on a model that has later been updated (ie. the properties changed in the typescript code), it will fail.
We should stop running data migrations inside classic migrations.
Instead we could:
- For each data migration, add a timestamp.
- After
setupOrm
(which runs the classic migrations), check the latest migration timestamp from database, and run all data migrations for which the timestamp is after this one.
Which would mean that we should store the data migration timestamp somewhere (to avoid running data migrations again) like the migrations table does for classic migrattions. Or we should create a dummy (empty) classic migration so that the current timestamp is stored in the migrations
table.