I - setup connection
To enable the database plug-in, add jdbc in your build dependencies : build.sbtlibraryDependencies += jdbcEnable 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.DriverII- generate database with evolutions
db.default.url="jdbc:mysql://127.0.0.1/DATABASE_NAME"
db.default.username=USER_NAME
db.default.password=PASSWORD
Add evolutions into your dependencies list in build.sbt:
libraryDependencies += evolutionsThese 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/defaultThe 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.
Now restart your project and check it# --- !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;
You can watch and do step by step with me here :
Comments
Post a Comment