All checks were successful
Deploy triz-docs to 150 / build-and-deploy (push) Successful in 1h8m49s
2.2 KiB
2.2 KiB
| sidebar_position | title |
|---|---|
| 4 | Execution & CI/CD Integration |
Execution & CI/CD Integration
Running Migrations Manually
To execute pending migrations locally or manually on a specific environment:
mvn flyway:migrate ^
-Dflyway.url=jdbc:postgresql://localhost:5432/TrizTresorie ^
-Dflyway.user=postgres ^
-Dflyway.password=YOUR_PASSWORD
When you run this command, Flyway will:
- Check the
flyway_schema_historytable. - Detect which migrations have already been executed.
- Execute only the new, pending migrations in version order.
- Save the execution history automatically.
CI/CD Integration
In your deployment pipeline, the database migration step must occur before the application server (e.g., Tomcat) starts.
Example Runner Step
# --------------------------------------------------
# Run database migrations
# --------------------------------------------------
- name: Run database migrations
shell: cmd
run: |
cd %WORKSPACE_DIR%
mvnw.cmd flyway:migrate ^
-Dflyway.url=%DB_URL% ^
-Dflyway.user=%DB_USER% ^
-Dflyway.password=%DB_PASSWORD%
Important
Store database credentials securely using CI/CD secrets or environment variables. Do not hardcode passwords inside the repository scripts.
Final Deployment Flow
A standard, safe deployment sequence utilizing Flyway should follow these steps:
- Clone the source code.
- Build the application.
- Stop Tomcat.
- Backup configuration files.
- Deploy the new application artifacts.
- Restore configuration files.
- Run Flyway migrations.
- Start Tomcat.
- Clean up the workspace.
Project Structure Reference
For reference, a properly configured project will have a structure similar to this:
project/
│
├── src/
│ └── main/
│ └── resources/
│ └── db/
│ └── migration/
│ ├── V1__initial_schema.sql
│ ├── V2__task301_add_tables_t1_t2.sql
│ ├── V3__add_client_phone.sql
│ └── V4__fix_indexes.sql
│
├── pom.xml
└── mvnw.cmd