-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Stefan Nemeth <[email protected]>
- Loading branch information
1 parent
007d791
commit 1de56d9
Showing
4 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,57 @@ | ||
=================== | ||
Database migrations | ||
Database Migrations | ||
=================== | ||
|
||
We are using `Flyway <https://flywaydb.org/>`__ for database migrations. A GitHub Actions workflow validates these migrations during CI/CD by ensuring that the migration scripts are correctly formatted and can be applied without errors. for database migrations. When changing the database schema, create a new migration file in ``src/main/resources/db/migration`` within the application server with the following naming convention: ``V<VERSION-NUMBER>__<description>.sql``, e.g. ``V1__create_users.sql``. | ||
Overview | ||
-------- | ||
We use `Flyway <https://flywaydb.org/>`_ for database schema versioning and migrations. All database changes are tracked through version-controlled SQL scripts, ensuring consistent database states across all environments. | ||
|
||
The migrations are automatically applied when starting the application. | ||
Migration Files | ||
--------------- | ||
**Location** | ||
|
||
All migration scripts should be placed in:: | ||
|
||
src/main/resources/db/migration | ||
|
||
**Naming Convention** | ||
|
||
Format:: | ||
|
||
V<VERSION-NUMBER>__<description>.sql | ||
|
||
Example:: | ||
|
||
V1__create_users.sql | ||
|
||
The version number should be sequential and unique across all migrations. | ||
|
||
Branching Strategy | ||
------------------ | ||
1. Create migration files in feature branches | ||
2. Prefix with next available version (just increment the last version number) | ||
2. Use the next available version number (increment from the last existing version) | ||
3. Rebase if conflicts occur | ||
4. Run migrations locally to verify that they work as expected, even though migrations are automatically applied on application startup | ||
4. Test migrations locally before merging (just start application-server to apply migrations) | ||
5. Merge to main | ||
|
||
**Important**: Never modify committed migrations! If a migration needs to be corrected or updated, create a new migration file to apply the necessary changes rather than altering an existing one. | ||
.. warning:: | ||
|
||
Never modify existing/committed migrations! Create new migration files for any necessary changes. | ||
|
||
Handling Migration Conflicts | ||
---------------------------- | ||
When working with multiple branches, you may encounter migration conflicts. Here's how to handle them: | ||
|
||
1. Clean existing migrations:: | ||
|
||
./gradlew flywayClean flywayMigrate | ||
|
||
2. Apply current branch migrations: | ||
|
||
* Start application-server to apply migrations automatically | ||
|
||
3. When switching branches, clean and reapply migrations again:: | ||
|
||
./gradlew flywayClean flywayMigrate | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters