Suppose I have a web app consisting of an API and a db.
I also have a bunch of db migrations. Some of them update tables structure, while others also update the data. For instance, in migration_5 I do the following:
- Query the db for user ids whose rating is lower than 2.
- Update some other tables based on these ids.
Now, I want to set up integration tests. From what I understand, before running tests I should do the following:
- Have a clean empty db
- Run all migrations so the db structure (tables, columns, etc.) is in the relevant state
And here's what I can't understand: in the described scenario the migration_5 will fail because it relies on the presence of some data in db (the registered users). As the db is empty, the attempt to query the db for user ids in migration will return nothing, hence the attempt to update other tables will throw an error, causing the migration to fail.
So how am I supposed to run such migrations on an empty db? What am I missing? I feel like I don't understand some very basic things