Reputation: 1096
We're thinking about integrating flyway into our system, as it seems like a great tool to manage database migrations in an efficient way.
However, I am not quite sure how to proceed:
We have three different databases
They all contain different data (different users etc.). There is no common data (on the flyway page this is called reference data) between the databases, only the structure should remain the same.
Looking at the website my understanding is to proceed like this:
We have to extract the schema version from our production environment and save this in a file such as V1__BASE_version.sql. I would do this e.g. with this:
mysqldump -d -u username -p password -h hostname dbname
We make sure that the ddl matches that of the test environment by also getting a dump of the structure and comparing it to the structure from the production system (start with a diff and then manually where it is not clear). In the unlikely event that we find any difference we get rid of them by changing the db structure for test or live (depending on what makes more sense).
We initialize all databases with data with an initial version as described by the homepage. For my different databases I use different -Durl=, -Dusername= and -Dpassword= paramters.
mvn flyway:init -Dflyway.initVersion=1 -Dflyway.initDescription="Base version"
Configure our spring setup to pick up flyway (as described on the homepage). This makes sure migrations are applied automatically and that the database is in a consistent state with the application
Is this the correct way to do it? Did I forget any important steps?
I have one remaining question about adding test data to the in-memory database:
Where is the correct place to inset the unit test data? Even if I setup flyway using spring and make hibernate depend on it using
<bean id="sessionFactory" class="..." depends-on="flyway">
...
</bean>
the datasource will be created before and this is currently the place where we add our schema and test data. If we still add the sample data when creating the datasource the schema will not be the correct one if I am not mistaken.
How can we use test-data with flyway using an in-memory database?
Thanks!
Upvotes: 2
Views: 1385
Reputation: 35179
You can configure an extra location containing test data scripts. This should then be configured to only be included for unit tests.
Upvotes: 2