This project shows how flyway script versioning can be done effectively in a distributed development environment. If you are in a project that has multiple teams committing flyway scripts using the default way of using version numbers, there is a high chance that multiple people used up the same version number, resulting in a conflict.
This problem can be averted by versioning the script with a timestamp upto millis. Conflicts can be significantly reduced.
- JDK 8
- Maven 3+
- Flyway 4.2.0
- Create a flyway maven project just like this one.
- If you have multiple environments to run flyway on, create a folder structure as in src/main/resources
- Replace the Jdbc driver in the pom.xml with the one you need. It can be mysql, Oracle etc.
- Copy flyway properties as in this pom.xml
- Create sql scripts in each environment.
- 0sql: This is to hold sql's applicable for all environment
- Put environment specific sql's in each of the other folders like local or dev or qa.
- Do not version the scripts. Just put a meaningful name like 1_config_table_create.sql
- Run "mvn package"
- A junit will run to ensure that all scripts are versioned.
- Maven error console will list all unversioned scripts.
- Run "mvn package -DskipTests=true"
- This will find unversioned sql scripts and version them with a "V" followed by timestamp
- 1_config_table_create.sql --> V20140820132356560__1_config_table_create.sql
Note: org.anair.flyway.VersionFlywayScript does the versioning. Checkout the class and comments.
- If you are in a distributed development environment, ask your team members to follow the above instructions to avoid version conflicts. This process will reduce conflicts, but is still not guaranteed to fix it 100%.
- If you are running "flyway:migrate" through Chef/Ansible/Jenkins, make sure "mvn compile test flyway:migrate" is executed. The test will ensure you have versioned scripts.
- Running flyway scripts in "outOfOrder" works well for distributed teams.