javaone 2014

55
Database migrations the missing piece in Java EE BOF3528 Rikard Thulin

Upload: rikard-thulin

Post on 14-Apr-2017

151 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Javaone 2014

Database migrationsthe missing piece in Java EE

BOF3528

Rikard Thulin

Page 2: Javaone 2014

This is a short version of this talk !

Full length video available at: http://vimeo.com/105880153

Rikard Thulin

Page 3: Javaone 2014

We will discuss how

schema migrations

improves the software engineering life cycle and the

possibilities to improve Java for the future

Page 4: Javaone 2014

Roadmap

• Introduction to the topic and why it is so important (7 min) • Schema Migrations demo (8 min) • The current situation, the tools of the trade (5 min) • Future possibilities at hand to solve this problem (5 min) • Discussion (15 min)

Page 5: Javaone 2014

About me

Page 6: Javaone 2014

Part 1 !

Introduction to the topic and why it is so important

Page 7: Javaone 2014

Staging clusterCI

How do we keep everything CONSISTENT?

QA

Staging cluster

Prod clusterProd cluster

Dev team

Page 8: Javaone 2014

{code}VCS Build server

How do we keep { code }

CONSISTENT?

artifactsRepository

push pull

publish

releaseQA

promote

DEV/CIStagingProd

Dev team

Page 9: Javaone 2014

What is the problem?

Page 10: Javaone 2014

Two entities

Page 11: Javaone 2014
Page 12: Javaone 2014
Page 13: Javaone 2014

Really?Is the database EVIL?

Page 14: Javaone 2014

artifact manual, script, …

Source Database

Page 15: Javaone 2014

HOW

Page 16: Javaone 2014

artifact manual, script, …

Source Database

db deltas, automatic

Page 17: Javaone 2014

artifact

Source

Page 18: Javaone 2014

{code +

migrations}

VCS Build server

How do we keep { code + database }

CONSISTENT?

artifacts

{code + migrations}

Repository

push pull

publish

releaseQA

promote

StagingProd

Dev team

DEV/CI

Page 19: Javaone 2014

Shiny Happy PeopleWe get

Page 20: Javaone 2014

Schema MigrationDEMO DEMO DEMO DEMO

Page 21: Javaone 2014

Schema MigrationDEMO DEMO DEMO DEMO

Migrations are applied automatically during deployment

Page 22: Javaone 2014

Schema MigrationDEMO DEMO DEMO DEMO

Spring based application

Page 23: Javaone 2014

Shiny Happy PeopleDEMONSTRATION OF

Page 24: Javaone 2014

LOCAL DEV PROD

Version 0 Version 0 Version 0

Page 25: Javaone 2014

LOCAL DEV PROD

Version 1 Version 0 Version 0

Page 26: Javaone 2014

LOCAL DEV PROD

Version 1 Version 1 Version 0

Page 27: Javaone 2014

LOCAL DEV PROD

Version 2 Version 1 Version 0

Page 28: Javaone 2014

LOCAL DEV PROD

Version 2 Version 3 Version 0

Page 29: Javaone 2014

LOCAL DEV PROD

Version 2 Version 3 Version 3

Page 30: Javaone 2014

What can we do?create/drop TABLEcreate/drop INDEX

add/remove CONSTRAINT java REFACTORINGS

STORED PROCEDUREScreate/drop VIEWS

insert DATA !

and more!

Page 31: Javaone 2014

What

is the trick?

Page 32: Javaone 2014

When

is the trick?

Page 33: Javaone 2014

Another view

Automatization of:a sequences of instructions to be executed

given the revision of the source code

Page 34: Javaone 2014

Database Change ManagementReal Life Tricks

• Possible to use on an existing database • Quick and simple to implement • Database copies mix and match • Wash copies of production database • DBA approval / review process • One click release possible

Page 35: Javaone 2014

Part 2 !

The current situation tools of the trade

Page 36: Javaone 2014
Page 37: Javaone 2014

Tools of the Trade

ActiveRecord Ruby (Ruby)

Entity Framework Migrations (.net)

COMPETITION HAS IT

Page 38: Javaone 2014

Tools of the Trade

Hibernate & JPA Schema Generation

Page 39: Javaone 2014

Tools of the Trade

FlyWay & LiquibaseStronger execution order Supports different DB / environment Stereotype of being “heavyweight" Automatic rollback

Convention over configurationGaining popularity

Page 40: Javaone 2014

Tools of the TradeFlyWay

Convention over configurationGet up and running in 5 minutesGaining popularity

Page 41: Javaone 2014

Tools of the TradeLiquibase

Stronger execution order Supports different DB for different environment Stereotype of being “heavyweight" Automatic rollback

Page 42: Javaone 2014

Tools of the TradeI [Nathan Voxland] would summarize the differences as: !

FlyWay is "lower level" with you specifying exactly the SQL you want ran whereas Liquibase is "higher level" with you specifying what you want changed and Liquibase computing the SQL !

FlyWay manages changes by filename whereas Liquibase manages changes by order in a file.

Nathan Voxland, Liquibase developer

Page 43: Javaone 2014

Tools of the Trade summary

Schema migration is •Not solved by Java EE today •Solved by 3PP •Already in competitors standards

Page 44: Javaone 2014

Part 3 !

Future possibilities to solve this problem

Page 45: Javaone 2014

The future my proposal

Add schema migration to

Java EE

Page 46: Javaone 2014

Reasons to add Migrations to Java EE

We are behind the competition Schema migrations is not well know to the broad developer community Increased Quality and Productivity

Adding complexity to the platform

Page 47: Javaone 2014

Advanced tooling the future?

Page 48: Javaone 2014

the future?

class User { }

Page 49: Javaone 2014

@Migration(id="1", author="duke") class CreateUserTable { !

@CreateTable(User.class) @AddColumn(User.class) long id; !

@AddColumn(entity = User.class, size = "255") String name; }

the future?

Warning: the following slides are possibilities for the future — not what we have

Page 50: Javaone 2014

the future?@Migration(id="1", author="duke") class CreateUserTable { @AddColumn(User.class) long id; … }

@Entity class User { @Id long id; … }

Migration2Code Generator

Warning: the following slides are possibilities for the future — not what we have

Page 51: Javaone 2014

@Entity class User { !

@Id long id; !

@Column(size="255") String name; }

the future?

Page 52: Javaone 2014

@Migration(id="2", author="duke") class AddColumnsToUser { !

@DropColumn(User.class) String name; !

@AddColumn(entity = User.class, size="80") String firstName; !

@AddColumn(entity = User.class, size="80") String lastName; !

@AddColumn(entity = User.class, size="255") String email; }

the future?

Warning: the following slides are possibilities for the future — not what we have

Page 53: Javaone 2014

@Entity class User { !

@Id long id; !

@Column(size="80") String firstName; !

@Column(size="80") String lastName; !

@Column(size="255") String email; }

the future?

Page 54: Javaone 2014

Wrap up

YOU! Should use Schema MigrationWE? JCP JSR! "What? Lets figure it out!"When? Now. Lets start!

[email protected]

Page 55: Javaone 2014

Discussion and

Q & A

[email protected]