se2016 java roman ugolnikov "migration and source control for your db"
TRANSCRIPT
![Page 1: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/1.jpg)
Migrationа and source control for your DB
![Page 2: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/2.jpg)
what:Database migration: Database structure: - Tables, constrains, indexes;
Database data:
- Initial data like list of post codes,
statuses for order, etc.
Database logic:
- stored procedures, triggers, functions
![Page 3: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/3.jpg)
why: versionsData Base migration: Data base structure: - Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.0.0
![Page 4: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/4.jpg)
why: versionsData Base migration: Data base structure: - Tables, constrains, indexes;
Data base data:
v1.0.0
![Page 5: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/5.jpg)
why: versionsData Base migration: Data base structure: - Tables, constrains, indexes;
Data base data:
- Initial data like list of post co
v1.2.1
v1.0.0
![Page 6: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/6.jpg)
Data Base migration: Data base structure: - Tables, constrains, indexes;
Data base data:
- Initial data like list of post
v1.2.1
v1.6.0
v1.0.0
why: versions
![Page 7: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/7.jpg)
Data Base migration: Data base structure: - Tables, constrains, indexes;
Data base data:
- Initial data like list of post c
v1.2.1
v1.6.0
v2.0.1
v1.0.0
why: versions
![Page 8: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/8.jpg)
Data Base migration: Data base structure: - Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.2.1
v1.6.0
v2.0.1
v1.0.0
why: versions
![Page 9: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/9.jpg)
Data Base migration: Data base structure: - Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.2.1
v1.6.0
v2.0.1
v1.0.0DEV
why: environments
![Page 10: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/10.jpg)
Conclusion
We need version control over our database
migration
![Page 11: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/11.jpg)
Tools
Play framework:migration
Rails ActiveRecord migrations
Mogeez for
![Page 12: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/12.jpg)
Tools
Play framework:migration
Rails ActiveRecord migrations
Mongeez for
![Page 13: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/13.jpg)
Tools
Play framework:migration
Rails ActiveRecord migrations
Mogeez for
![Page 14: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/14.jpg)
Tools
Play framework:migration
Rails ActiveRecord migrations
Mogeez for
![Page 15: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/15.jpg)
Tools
Liquibase :
•Apache license
•Started in 2006 (active)
•http://liquibase.org
Flyway:
•Apache license
•Started in 2010
•http://www.flywaydb.or
g
![Page 16: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/16.jpg)
Common flow
Build Test Run
• Dev• Test• Acceptance• Production
• GUI tests• Integration
tests• API tests• Unit tests
• Ant• Maven• Gradle
![Page 17: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/17.jpg)
Common flow
Build Test Run
• Dev• Test• Acceptance• Production
• GUI tests• Integration
tests• API tests• Unit tests
• Ant• Maven• Gradle
![Page 18: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/18.jpg)
Common flow
Build Test Run
• Java API• Spring Bean
• Plugins• CLI
• Plugins• CLI
![Page 19: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/19.jpg)
How it worksDatabaseChangelogLock:
DatabaseChangelog:
![Page 20: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/20.jpg)
How it works
Schema_versions:
![Page 21: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/21.jpg)
How it works
Sequential change flow1. Init db
2. Add column “type”
3. Add new table
![Page 22: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/22.jpg)
How it works
Sequential change flow1. Init db
2. Add column “type”
3. Add new tableX
![Page 23: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/23.jpg)
How it works
Sequential change flow1. Init db
3. Add new table
4. Remove column “type”
2. Add column “type”
![Page 24: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/24.jpg)
difference?, comparison.Rollback vs no rollback
SQL outputConditions
baseline
Supported modes:https://flywaydb.org/documentation/gradle/Flyway more and esear.
![Page 25: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/25.jpg)
How it works
V1__Initial_Setup.sql
V1_1__First_Changes.sql
V1_2__Added_user_info.sql
V2__ ….
![Page 26: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/26.jpg)
How it works
Changes are grouped into changesets: • Change(s) that should be applied atomically
Changesets are grouped into changelogs:•Files managed in version control
![Page 27: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/27.jpg)
How it works
v1_changeLog.xml
v1.1_changeLog.xml
v2_changeLog.xml
v1.2_changeLog.xml
v1.3_changeLog.xml
v2.1_changeLog.xml
…
![Page 28: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/28.jpg)
Supported db listMySQLPostgreSQLOracleMSSQL ServerSybase_EnterpriseSybase_AnywhereDB2Apache_DerbyHSQLH2InformixFirebirdSQLite
MySQLPostgreSQLOracle MSSQL ServerSQL AzureMariaDBPhoenixVerticaAWS RedshiftDB2, DB2 z/OSDerbyH2, Hsql, SQLite, SAP HANA, solidDB, Sybase ASE
![Page 29: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/29.jpg)
Supported formats
DSL for database changes:
• XML• YAML• JSON• sql
Pure SQL
![Page 30: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/30.jpg)
Base lineConvention over configuration
Toolbox
![Page 31: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/31.jpg)
Toolbox
• SQL output• Rollback• Context• Precondition
![Page 32: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/32.jpg)
Toolbox: precondition
<preConditions onFail="WARN" onError="MARK_RAN"><dbms type="oracle"/><runningAs username="SYSTEM"/><tableExists tableName=“newTable"/><customPrecondition className=“com.example.CheckOne"/>
<sqlCheck expectedResult="0">select count(*) from oldtable
</sqlCheck></preConditions>
![Page 33: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/33.jpg)
Toolbox: precondition
<preConditions onFail="WARN" onError="MARK_RAN"><dbms type="oracle"/><runningAs username="SYSTEM"/><tableExists tableName=“newTable"/><customPrecondition className=“com.example.CheckOne"/>
<sqlCheck expectedResult="0">select count(*) from oldtable
</sqlCheck></preConditions>
![Page 34: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/34.jpg)
Toolbox: precondition
<preConditions onFail="WARN" onError="MARK_RAN"><dbms type="oracle"/><runningAs username="SYSTEM"/><tableExists tableName=“newTable"/><customPrecondition className=“com.example.CheckOne"/>
<sqlCheck expectedResult="0">select count(*) from oldtable
</sqlCheck></preConditions>
![Page 35: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/35.jpg)
Toolbox: precondition
<preConditions onFail="WARN" onError="MARK_RAN"><dbms type="oracle"/><runningAs username="SYSTEM"/><tableExists tableName=“newTable"/><customPrecondition className=“com.example.CheckOne"/>
<sqlCheck expectedResult="0">select count(*) from oldtable
</sqlCheck></preConditions>
![Page 36: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/36.jpg)
Toolbox: precondition
<preConditions onFail="WARN" onError="MARK_RAN"><dbms type="oracle"/><runningAs username="SYSTEM"/><tableExists tableName=“newTable"/><customPrecondition className=“com.example.CheckOne"/>
<sqlCheck expectedResult="0">select count(*) from oldtable
</sqlCheck></preConditions>
![Page 37: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/37.jpg)
Toolbox: precondition
<preConditions onFail="WARN" onError="MARK_RAN"><dbms type="oracle"/><runningAs username="SYSTEM"/><tableExists tableName=“newTable"/><customPrecondition className=“com.example.CheckOne"/>
<sqlCheck expectedResult="0">select count(*) from oldtable
</sqlCheck></preConditions>
![Page 38: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/38.jpg)
Toolbox: precondition
<preConditions onFail="WARN" onError="MARK_RAN"><dbms type="oracle"/><runningAs username="SYSTEM"/><tableExists tableName=“newTable"/><customPrecondition className=“com.example.CheckOne"/>
<sqlCheck expectedResult="0">select count(*) from oldtable
</sqlCheck></preConditions>
![Page 39: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/39.jpg)
DEMO
![Page 40: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/40.jpg)
let us try it
DDLv1
![Page 41: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/41.jpg)
DDL
v2
v1
Init data, new column(source)
let us try it
![Page 42: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/42.jpg)
how it works
DDL
v2
v3
v1
Init data, new column(source)
Move values in separate table
let us try it
![Page 43: SE2016 Java Roman Ugolnikov "Migration and source control for your DB"](https://reader036.vdocuments.mx/reader036/viewer/2022062412/5881dbc11a28ab331a8b7869/html5/thumbnails/43.jpg)
let us try it
DDL
v2
v3
v1
Init data, new column(source)
Move values in separate table