javazone 2014
TRANSCRIPT
3 billion Java developers lives was ruined on
August 29, 1997
The survivors of the deployment called the war
Judgment Day.
They lived only to face a new nightmare, the war against the
DBA.
Skynet, the computer which controlled releases, sent
two engineers back through time
Their mission: to solve the problems of
schema migrations…
Opening “quote” from “Terminator 2: Judgment Day”
Roadmap
• Introduction to the topic and why it is so important
• The current situation, the tools of the trade
• Future possibilities at hand to solve this problem
Let the team lead or the smart guy do it!Or if you are a manager, it translates to the expensive guy
change recall refactoring applied some marked specified better run units the tagged along more SQL precondition pain state both statements contains production Sets applying database nested things executes identified context leave test one management Generally apply HOPE change stable individual ran database just IT generate fails different changes uniquely per machines change written productivity log attribute Set change sets development author files WORKS Contexts describes by descript ive someone regardless Major else environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
change recall refactoring applied some marked specified better run units the tagged along more SQL precondition pain state both statements contains production Sets applying database nested things executes identified context leave test one management Generally apply HOPE change stable individual ran database just IT generate fails different changes uniquely per machines change written productivity log attribute Set change sets development author files WORKS Contexts describes by descript ive someone regardless Major else environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
change recall refactoring applied some marked specified better run units the tagged along more SQL precondition pain state both statements contains production Sets applying database nested things executes identified context leave test one management Generally apply HOPE change stable individual ran database just IT generate fails different changes uniquely per machines change written productivity log attribute Set change sets development author files WORKS Contexts describes by descript ive someone regardless Major else environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
change remember refactoring applied some marked specified better run units the tagged along more SQL precondition and state both statements contains production Sets last database nested things executes identified context leave test one management Generally apply suddenly change stable individual ran time just a generate fails different STUFF uniquely per machines change co-worker productivity log attribute Set change sets development author files DOES Contexts describes added descriptive NOT regardless Major a environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
change remember refactoring applied some marked specified better run units the tagged along more SQL precondition and state both statements contains production Sets last database nested things executes identified context leave test one management Generally apply suddenly change stable individual ran time just a generate fails different STUFF uniquely per machines change co-worker productivity log attribute Set change sets development author files DOES Contexts describes added descriptive NOT regardless Major a environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
change remember refactoring applied some marked specified better run units the tagged along more SQL precondition and state both statements contains production Sets last database nested things executes identified context leave test one management Generally apply suddenly change stable individual ran time just a generate fails different STUFF uniquely per machines change co-worker productivity log attribute Set change sets development author files DOES Contexts describes added descriptive NOT regardless Major a environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
$ git pull
change remember refactoring applied some marked specified better run units the tagged along more SQL precondition and state both statements contains production Sets last database nested things executes identified context leave test one management Generally apply suddenly change stable individual ran time just a generate fails different STUFF uniquely per machines change co-worker productivity log attribute Set change sets development author files DOES Contexts describes added descriptive NOT regardless Major a environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
change remember refactoring applied some marked specified better run units the tagged along more SQL precondition and state both statements contains production Sets last database nested things executes identified context leave test one management Generally apply suddenly change stable individual ran time just a generate fails different STUFF uniquely per machines change co-worker productivity log attribute Set change sets development author files DOES Contexts describes added descriptive NOT regardless Major a environments column queries local Each yet either WORK change ANYMORE set Preconditions DATABASECHANGELOG unexpected control file !? Concepts stop store execution arbitrarily location auto commit executed Developers
Proven national gas reserves (cubic meters)
0 2,007,000,000,000
Proven national oil reserves (barrels) 0 5,320,000,000
NO STORAGE PROBLEM
StagingDev CI
Now when we know about quality assurance we should stage
our production environment
QA
Prod
Staging clusterCI
How do we keep everything CONSISTENT?
QA
Staging cluster
Prod clusterProd cluster
Dev
{code}VCS Build server
How do we keep { code }
CONSISTENT?
artifactsRepository
push pull
publish
release
Dev
QA
promote
DevStagingProd
{code +
migrations}
VCS Build server
How do we keep { code + database }
CONSISTENT?
artifacts
{code + migrations}
Repository
push pull
publish
release
Dev
QA
promote
DevStagingProd
What can we do?create/drop TABLEcreate/drop INDEX
add/remove CONSTRAINT alter SQUENCE
STOREDPROCEDUREScreate/drop VIEWS
insert DATA
and more!
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
Tools of the Trade
FlyWay & LiquibaseStronger execution order Supports different DB / environment Stereotype of being “heavyweight" Automatic rollback
Convention over configuration Gaining popularity
Tools of the TradeFlyWay
Convention over configuration Get up and running in 5 minutes Gaining popularity
Tools of the TradeLiquibase
Stronger execution order Supports different DB for different environment Stereotype of being “heavyweight" Automatic rollback
Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one
of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the
FlyWay & Liquibase Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one
of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one of the tools Use one
Tools of the Trade summary
Schema migration is •Not solved by Java EE today •Solved by 3PP •Already in competitors standards
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
@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?
the future?
@Migration(id="1", author="duke") class CreateUserTable { @AddColumn(User.class) long id; … }
@Entity class User { @Id long id; … }
Migration2Code Generator
@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?
@Entity class User {
@Id long id;
@Column(size="80") String firstName;
@Column(size="80") String lastName;
@Column(size="255") String email; }
the future?
Wrap up
1. Start using one of the tools! 2. We need to figure out if
database migrations is a candidate to be included in Java EE
3. Now it the time to take action!