triz-docs/docs/workflow/database-migrations/02-creating-migrations.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

1.1 KiB

sidebar_position title
3 Creating Migrations

Creating Migrations


Every new database modification must be added as a completely new migration file.

Naming Convention

Flyway requires an exact naming format to recognize and order migrations correctly:

V<version>__<description>.sql

Examples

  • V1__initial_schema.sql
  • V2__task301_add_tables_t1_t2.sql
  • V3__add_client_phone.sql
  • V4__fix_invoice_indexes.sql

Warning

Important Rules:

  • You must use exactly TWO underscores (__) after the version number.
  • Never modify old executed migrations.
  • Never rename old migrations after they have been executed on any environment.
  • Always create a new migration file for new changes.

Example Workflow

If you need to add new tables for a specific task (e.g., Task 301), create a file named V2__task301_add_tables_t1_t2.sql with the necessary content:

CREATE TABLE table1 (
    id BIGSERIAL PRIMARY KEY
);

CREATE TABLE table2 (
    id BIGSERIAL PRIMARY KEY
);

Commit this file alongside your application code changes and push it to the repository.