Database Migrations
To learn more, visit the Flyway Documentation.
Migration Types
There are many types of migrations, we mostly use these:
| Versioned |
runs once |
| Repeatable |
runs when changed |
Directory Structure
The directory structure starts with no/tritt/finsta
and has been chosen to allow both SQL-based migration and Java-based migrations.
directory structure
src/main
- groovy/no/tritt/finsta
- migrations
- resources/no/tritt/finsta
- migrations
- test-data
Versioned Migrations
The version must be unique.
V{app-version}_{counter}__{description}.{sql|groovy}
V1_0_0_010_create_table_user_account.sql
V1_0_0_020_create_table_organization.sql
V1_1_0_030_create_table_financial_statement.sql
version parts
app-version
|
helps us identify what application version a migration targeted |
counter
|
incremented across all migrations (could suffice as version) |
Configuration
finsta-db/**/application.yml
flyway:
datasources:
global:
loggers: slf4j
clean-schema: ${db.clean-global-on-startup:false}
enabled: ${db.migrate-global-on-startup:false}
schemas: ${micronaut.multitenancy.datasources.global-schema}
create-schemas: true
locations:
- classpath:tritt/finsta/migrations
tenant:
loggers: slf4j
enabled: ${db.migrate-tenant-on-startup:false}
schemas: ${micronaut.multitenancy.datasources.fixed-tenant-schema}
create-schemas: true
locations:
- classpath:tritt/finsta/migrations/tenant