nkonev / r2dbc-migrate

R2DBC database migration library
https://nkonev.name/post/136
Apache License 2.0
98 stars 9 forks source link

Support for running migrations for tests #20

Closed 1nF0rmed closed 2 years ago

1nF0rmed commented 2 years ago

I am currently using the spring-starter dependency: name.nkonev.r2dbc-migrate:r2dbc-migrate-spring-boot-starter:2.7.6

And while following the spring example, added migrations under: src/main/resources/db/migration src/test/resources/test/migration

and specified the same paths in the application.yml as:

r2dbc:
  migrate:
    resources-paths:
      - classpath:/db/migration/*.sql
      - classpath:/test/migration/*.sql

But when running the tests, the test migrations are not run. Is there a way to trigger these via a gradle task or any configuration needs to be added for the same?

nkonev commented 2 years ago

@1nF0rmed

  1. Please clarify what exactly not run. Currently the target behavior like in other migration libs - to run all migrations once.
  2. No way to trigger via the gradle/maven task, but if you want, for example to wipe your database and re-start migrations you can to do following @Autowired R2dbcMigrateAutoConfiguration.R2dbcMigrateBlockingInvoker migrationInvoker; and then restartmigrationInvoker.migrate();
1nF0rmed commented 2 years ago

@nkonev Sorry for the late response.

  1. When running the tests, migrations under: src/main/resources/db/migration -> Executed src/test/resources/test/migration -> Did Not execute
1nF0rmed commented 2 years ago

I did not realise that the migration number provided for the test migrations should be different from those in db/migrations.

I was able to fix my issue by changing the migration number from V1 to V<BIGNUMBER>. I'm not sure if it was the optimal solution.

nkonev commented 2 years ago

@1nF0rmed Please provide reproducer project.

1nF0rmed commented 2 years ago

I did not realise that the migration number provided for the test migrations should be different from those in db/migrations.

I was able to fix my issue by changing the migration number from V1 to V<BIGNUMBER>. I'm not sure if it was the optimal solution.

@nkonev

nkonev commented 2 years ago

Sorry, didn't see last sentence.

Yes, it is correct fix.