triz-docs/docs/workflow/database-migrations/03-cicd-integration.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

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:

  1. Check the flyway_schema_history table.
  2. Detect which migrations have already been executed.
  3. Execute only the new, pending migrations in version order.
  4. 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:

  1. Clone the source code.
  2. Build the application.
  3. Stop Tomcat.
  4. Backup configuration files.
  5. Deploy the new application artifacts.
  6. Restore configuration files.
  7. Run Flyway migrations.
  8. Start Tomcat.
  9. 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