English 中文(简体)
How to use Evolutions in Play Framework 2.0?
原标题:

For play 1.x, we can use play evolutions:apply, How can I do it in play-2.0-beta?

最佳回答

Evolution:apply is run automatically upon application start up. What is missing in Play 2.0-rc1 is a way to generate the evolutions scripts, and to manually apply them from the SBT console.

But here is how to create them manually.

Say you have the following definition in application.conf

db.mydb.driver=org.h2.Driver
db.mydb.url=jdbc:h2:mem:play

Play2 will look for evolution in the following folder: application/db/evolutions/mydb/ In this folder, evolutions shall be stored as sql file, using the evolution step as the file name.

For instance:

application/db/evolutions/mydb/1.sql
application/db/evolutions/mydb/2.sql
application/db/evolutions/mydb/3.sql

Now the sql itself has the following structure:

# --- !Ups
create table company (
  id                        bigint not null,
  name                      varchar(255),
  constraint pk_company primary key (id));
# --- !Downs
drop table if exists company;

!Ups are used to upgrade the model to the next evolutions
!Downs are used to revert the !Ups

Like I said in the intro, evolutions will be magically applied upon application startup.

问题回答

暂无回答




相关问题
How to create a custom validator in Play Framework 2.0?

Play 1.0 comes with a full featured validation framework base on http://oval.sourceforge.net/. With the release of 2.0, my custom validators do not work anymore. How does one create custom validator ...

How to contribute modules in Play Framework 2.0?

The original Play Framework 1.x had an elegant and simple module management system. Coupled with the Play repository, it was a great way to quickly enhance an application with third party components &...

How to define a tag with Play 2.0?

There isn t much documentation about Play 2.0 template engine. How does one create a tag using Scala template?

热门标签