---
sidebar_position: 3
title: "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:

```text
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:

```sql
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.
