triz-docs/docs/workflow/database-migrations/01-setup.md
Othmane Ataallah ba04c9a7d3
All checks were successful
Deploy triz-docs to 150 / build-and-deploy (push) Successful in 1h8m49s
fix flyway docs & add fr localization
2026-05-11 10:49:30 +01:00

55 lines
1.6 KiB
Markdown

---
sidebar_position: 2
title: "Setup & Initialization"
---
# Setup & Initialization
---
## 1. Add the Flyway Maven Plugin
To integrate Flyway into the project, add the following plugin to your `pom.xml`:
```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:
```text
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:
```cmd
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`.