Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does evolution create automatically database and table?

I have class GroupTable that makes schema of table.

As I saw, in other projects there are at conf/evolution/default folder file 1.sql, that is automatically generated from code (as I assume).

But when I start my application - nothing creates.

What should I do? Is it creating automatically or have I write it in my code?

 class GroupTable(tag: Tag) extends Table[Group](tag, "groups") {
    def name = column[String]("name", O.PrimaryKey)

    def day = column[String]("day")

    def subject = column[String]("subject")

    def typeSub = column[String]("typeSub")

    def start = column[Time]("start")

    def end = column[Time]("end")

    def teacher = column[String]("teacher")

    def auditorium = column[Int]("auditorium")

    override def * = (name, day, subject, typeSub, start, end, teacher, auditorium) <>((Group.apply _).tupled, Group.unapply)
  }

application.conf:

slick.dbs.default.driver = "slick.driver.MySQLDriver$"
slick.dbs.default.db.driver="com.mysql.jdbc.Driver"
slick.dbs.default.db.url="jdbc:mysql://localhost:3306/testdb"
slick.dbsdefault.user="root"
slick.dbs.default.password=""

play.evolutions.autoApply=true

evolutionplugin=enabled
play.evolutions.db.default.autoApply=true
play.evolutions.db.default.autoApplyDowns=true

built.sbt:

name := "TimetableAPI"

version := "1.0"

lazy val `timetableapi` = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(cache, ws, specs2 % Test, evolutions,
  "mysql" % "mysql-connector-java" % "5.1.34",
  "com.typesafe.play" %% "play-slick" % "1.1.0",
  "com.typesafe.play" %% "play-slick-evolutions" % "1.1.0")

unmanagedResourceDirectories in Test <+= baseDirectory(_ / "target/web/public/test")

resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"

routesGenerator := InjectedRoutesGenerator
like image 465
Azula Avatar asked Feb 03 '16 20:02

Azula


1 Answers

I tried evolution in Play framework.

As to your question, "Does evolution create automatically database and table?"

Since you are using mysql,

1.) No, evolution does not create database for you. You need to create the "testdb" database and grant privilege to "root"

2.) Yes, evolution create the datatable for you.

Why not use H2 as the database engine for testing? The evolution will create the database and datatable for you from scratch (no need to create the database). You may also mimic mysql using the H2 Database engine:

db.default.url="jdbc:h2:mem:play;MODE=MYSQL"

Please see link: https://www.playframework.com/documentation/2.5.x/Developing-with-the-H2-Database

like image 193
Carlos Galo Campos Avatar answered Jan 04 '23 12:01

Carlos Galo Campos