Does evolution create automatically database and table?
Asked Answered
P

2

6

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
Plaintiff answered 3/2, 2016 at 20:4 Comment(0)
H
2

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

Howsoever answered 30/6, 2016 at 6:43 Comment(0)
S
0

I don't know scalaz, but in general, evolutions are not automatically created, they are written manually. Each time you make a change to your database, you write the next numbered sql file, to apply the changes (Ups) and to remove the changes (Downs).

You can use database tools (such as MySql Workbenches database Synchronise function) generate the "difference" between a model and the actual database. These scripts can help in writing the evolutions.

Further docs here.

Scraper answered 5/2, 2016 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.