Slide 1

Slide 1 text

XHotel Database Migrations EKO KURNIAWAN KHANNEDY

Slide 2

Slide 2 text

Agenda Database Migrations Blibli Database Migrations XHotel Database Migrations

Slide 3

Slide 3 text

Database Migrations? XHOTEL DATABASE MIGRATIONS

Slide 4

Slide 4 text

What is Database Migrations Migrations are a convenient way to alter your database schema over time in a consistent and easy way. https://en.wikipedia.org/wiki/Schema_migration You can think of each migration as being a new 'version' of the database. A schema starts off with nothing in it, and each migration modifies it to add or remove tables, columns, or entries. Database Migrations knows how to update your schema along this timeline, bringing it from whatever point it is in the history to the latest version.

Slide 5

Slide 5 text

Why Database Migrations Easy to create database apps in every environment (local, uat, production), just run the database migration. Easy to track database changes (for code review) before run in production. Easy to rollback if something wrong in new migration script. Consistent default data in every database environment (local, uat, production).

Slide 6

Slide 6 text

Blibli Database Migrations XHOTEL DATABASE MIGRATIONS

Slide 7

Slide 7 text

Current Database Migrations In Blibli currently we are using FlywayDB and Mongobee for database migrations. All FlywayDB and Mongobee script will be included in the app. For Elasticsearch, we manually create schema using CURL, ups! 

Slide 8

Slide 8 text

Problem With Current Database Migrations (1) Every times we create new migration script, we need to redeploy the app, because migration script embedded in the app, even there is no changes in the app . For microservice that using more than one datastore, like x-fraud (using mongodb and elasticsearch), it’s a nightmare . If there is hot fix migration script, engineer will send request to dbadmin using JIRA. And it’s hard to track the migration script if using JIRA. For new engineer, good luck, you can not simulate migration from the first database creation, if you want to setup the database in your local computer, please dump the database from UAT 

Slide 9

Slide 9 text

Problem With Current Database Migrations (1) Something wrong with our last 2 migration scripts, let’s rollback the migrations. Ups, but wait? How to rollback the migrations? Hmm, just create new migrations that rollback the last 2 migration script. Oh, ok  I already rollback the mongodb migrations, but it’s still broken, the app is not working. Ups, sorry I forget, you also need to rollback the schema in elasticsearch. Etc.

Slide 10

Slide 10 text

XHotel Database Migrations XHOTEL DATABASE MIGRATIONS

Slide 11

Slide 11 text

The Project The project created as a template project, so every one can fork the project if want to create database-migration project for their apps. You can get the project template here : https://stash.gdn-app.com/projects/SANDBOX/repos/database- migration/browse For example, hotel-search fork and create new database-migration project here : https://stash.gdn-app.com/projects/HOTEL/repos/hotel-search- database/browse

Slide 12

Slide 12 text

Project Technology Database-migration project build using JRuby (Ruby Implementation on JVM). Ruby is developer friendly language, simple and dynamic, we don’t need to compile the project, just write and run. For Relational Database, the project using http://sequel.jeremyevans.net/ library. For MongoDB, the project using https://docs.mongodb.com/ruby- driver/master/ For Elasticsearch, the project using https://github.com/jnunemaker/httparty

Slide 13

Slide 13 text

Project Configuration Database-migration project support multi environment We can create local, uat1, uat2 and another configuration just in one project.

Slide 14

Slide 14 text

Supported Datastore

Slide 15

Slide 15 text

Create New Migration bin/create “your migration script name”

Slide 16

Slide 16 text

Write Migration Script

Slide 17

Slide 17 text

Run Migration bin/migrate environment

Slide 18

Slide 18 text

Rollback Migration bin/rollback environment VERSION

Slide 19

Slide 19 text

Thanks EKO KURNIAWAN KHANNEDY