Skip to main content

Setup & Initialization


1. Add the Flyway Maven Plugin​

To integrate Flyway into the project, add the following plugin to your pom.xml:

<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>11.0.0</version>
</plugin>

2. Create the Migration Directory​

Flyway looks for migrations in a specific classpath location by default. Create the following directory inside your project structure:

src/main/resources/db/migration

3. Existing Database Initialization (One-Time Only)​

Since the database already exists in production, Flyway must create its internal tracking table (flyway_schema_history) and baseline the existing schema. This ensures Flyway knows the starting point and doesn't try to recreate existing tables.

3.1 Create the Initial Migration​

Create a file named V1__initial_schema.sql inside the migration folder. This file should contain the SQL representing the complete, current database structure.

3.2 Baseline the Existing Database​

Run the following command once to initialize Flyway without executing the V1 SQL script against the already populated database:

mvn flyway:baseline ^
-Dflyway.url=jdbc:postgresql://localhost:5432/TrizTresorie ^
-Dflyway.user=postgres ^
-Dflyway.password=YOUR_PASSWORD ^
-Dflyway.baselineVersion=1

This creates the flyway_schema_history table and marks version 1 as already applied. From this point forward, Flyway will only execute migrations starting from V2.