play scala 2.4 - mysql - evolutions

I - setup connection
    To enable the database plug-in, add jdbc in your build dependencies : build.sbt
libraryDependencies += jdbc
    Enable mysql plugin :
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.34"
    Then you must configure a connection pool in the conf/application.conf file :
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://127.0.0.1/DATABASE_NAME"
db.default.username=USER_NAME
db.default.password=PASSWORD
 II- generate database with evolutions
    Add evolutions into your dependencies list in build.sbt:
libraryDependencies += evolutions
    These scripts are written in plain old SQL and should be located in the directory :
conf/evolutions/{connection name} 
     Example,as my define above,the evolutions apply to your default database, this path is :
conf/evolutions/default
    The first script is named 1.sql, the second script 2.sql, and so on…
    Each script contains two parts:
  • The Ups part the describe the required transformations.
  • The Downs part that describe how to revert them.
     Example :
# --- !Ups

CREATE TABLE
Users (
id bigint
(20) NOT NULL AUTO_INCREMENT,
email varchar
(255) NOT NULL,
password varchar
(255) NOT NULL,
fullname varchar
(255) NOT NULL,
isAdmin
boolean NOT NULL,
PRIMARY KEY
(id)
);

# --- !Downs

DROP TABLE
Users;
    Now restart your project and check it
    You can watch and do step by step with me here :



Comments