development:database_migration_management
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| development:database_migration_management [2015/04/23 20:25] – [Background] lee | development:database_migration_management [2015/04/24 13:18] (current) – [How the OHDSI WebAPI services use Flyway] lee | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| The OHDSI WebAPI executable has a dependency on a java framework called " | The OHDSI WebAPI executable has a dependency on a java framework called " | ||
| + | The advantages of this approach are: | ||
| + | |||
| + | * It provides a timestamped, | ||
| + | * All database schema changes are performed via SQL DDL scripts that are version controlled | ||
| + | * Initial creation of tables and all subsequent database migrations are automatically executed dynamically in new and existing databases | ||
| ==== The basics of how Flyway works ==== | ==== The basics of how Flyway works ==== | ||
| - | The Flyway data migration framework will execute database migration scripts that are provided in a known directory (or sub-directory) in the source code tree and each script name must begin with a database migration version number. | + | The Flyway data migration framework will execute database migration scripts that are provided in a known directory (or sub-directory) in the source code tree and each script name must begin with a database migration version number. |
| + | |||
| + | Each database migration | ||
| The scripts are executed in the order of the database migration version number in the script names. | The scripts are executed in the order of the database migration version number in the script names. | ||
| Line 24: | Line 31: | ||
| ==== How the OHDSI WebAPI services use Flyway ==== | ==== How the OHDSI WebAPI services use Flyway ==== | ||
| - | The WebAPI database migration scripts are created in the sub-folders of the https:// | + | The WebAPI database migration scripts are created in the sub-folders of the https:// |
| - | The database migration scripts file names are prefixed with " | + | The database migration scripts file names are prefixed with " |
| e.g. The next heracles related database migration script after V1.0.0.1_heracles_schema_migation.sql would be called V1.0.0.1.1_heracles_schema_migration.sql. | e.g. The next heracles related database migration script after V1.0.0.1_heracles_schema_migation.sql would be called V1.0.0.1.1_heracles_schema_migration.sql. | ||
| - | Note. The OHDSI WebAPI build has the Flyway "out of order execution" | + | Note. The OHDSI WebAPI build has the Flyway "out of order execution" |
| + | |||
| + | When the Flyway "out of order execution" | ||
| + | |||
| + | For the OHDSI WebAPI having this option enabled gives us the flexibility for one developer to e.g. add a new database migration script V1.0.0.1.1_heracles_schema_migration.sql and it will be executed one time, even if the last previous version change was V1.0.0.4_circe_schema_migration.sql. i.e. It allows each developer to flexibly & independently migrate their database tables for the set of WebAPI services they are responsible for, without schema change conflicts, as long as those sets of tables are distinct from the tables used by other WebAPI services. | ||
| ==== Testing Flyway migration scripts prior to a pull request ==== | ==== Testing Flyway migration scripts prior to a pull request ==== | ||
| Ideally you will need access to a local test environment with all three DBMS systems - SQL Server, Postgresql and Oracle. | Ideally you will need access to a local test environment with all three DBMS systems - SQL Server, Postgresql and Oracle. | ||
| Line 36: | Line 47: | ||
| ==== Create idempotent database migration scripts ==== | ==== Create idempotent database migration scripts ==== | ||
| If a script fails half way through then you don't want to have to manually drop the objects that were created. | If a script fails half way through then you don't want to have to manually drop the objects that were created. | ||
| - | This can be avoided by including DDL statements to drop objects if they already exist. | + | This can be avoided by including DDL statements to drop objects if they already exist. |
| ==== Manually rolling back a Flyway migration ==== | ==== Manually rolling back a Flyway migration ==== | ||
| It is not encouraged but it is possible to edit a database migration script and re-run it. You would need to manually delete the row containing the record of the previous execution of the script from the SCHEMA_VERSION table (and if necessary also drop any database objects that had been created). | It is not encouraged but it is possible to edit a database migration script and re-run it. You would need to manually delete the row containing the record of the previous execution of the script from the SCHEMA_VERSION table (and if necessary also drop any database objects that had been created). | ||
development/database_migration_management.1429820749.txt.gz · Last modified: by lee
