You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I have some migrations that backfill data into a new table using another table.
I want to be able to test that the backfill migration worked correctly, but in order to test it, I need to insert data into the original table before the migrations run.
Overall, there are situations in test where you want to insert data into the DB to test migrations are correct. Testing on empty DB is one use case, but testing when data is not empty mirrors production more.
Describe the solution you'd like
It would be ideal if there was a callback mechanism / event handler that we can register with golang-migrate that executes before/after a migration runs. (event params could be eventType:[Before/After], and migrationName and a db connection/session object).
We would use this during test only to intercept pre-migration event for backfill migration, and insert the data we want into the original table. Then we would check at the end of all migrations being run that the state of DB is what is expected.
This would also address situations like #136 which could be achieved using a callback (to insert data).
Note that what I propose is an optional way to add callbacks in special situations. It should not affect existing use cases.
Describe alternatives you've considered
Other solutions, could be
A SQL callback: You provide a SQL file (named in a suitable way to indicate which migration it is connected to). This is similar to Flyway SQL callbacks. I think programmatic is better, so we can insert it only in test code.
Another would be for Up to run till a specific migration (like Up(sentinelMigrationId, inclusive)). Then we could run
Up(BakfillMigrationId, false)
// insert some test data
Up() // run everything
// test backfill was correct
But I think my proposed solution is better.
Additional context
Of course, we are opening up a way for people to run code in the migration sequence.
But it is not magical, and someone would have to explicitly register a callback.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I have some migrations that backfill data into a new table using another table.
I want to be able to test that the backfill migration worked correctly, but in order to test it, I need to insert data into the original table before the migrations run.
Overall, there are situations in test where you want to insert data into the DB to test migrations are correct. Testing on empty DB is one use case, but testing when data is not empty mirrors production more.
Describe the solution you'd like
It would be ideal if there was a callback mechanism / event handler that we can register with golang-migrate that executes before/after a migration runs. (event params could be
eventType:[Before/After]
, andmigrationName
and a db connection/session object).We would use this during test only to intercept pre-migration event for backfill migration, and insert the data we want into the original table. Then we would check at the end of all migrations being run that the state of DB is what is expected.
This is similar to FlyWay Java callbacks. https://documentation.red-gate.com/fd/callback-concept-184127466.html
This would also address situations like #136 which could be achieved using a callback (to insert data).
Note that what I propose is an optional way to add callbacks in special situations. It should not affect existing use cases.
Describe alternatives you've considered
Other solutions, could be
Up
to run till a specific migration (likeUp(sentinelMigrationId, inclusive)
). Then we could runBut I think my proposed solution is better.
Additional context
Of course, we are opening up a way for people to run code in the migration sequence.
But it is not magical, and someone would have to explicitly register a callback.
The text was updated successfully, but these errors were encountered: