Advertisement
mitrakov

Scala Play: Evolutions

Jan 18th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.21 KB | None | 0 0
  1. // MySQL:
  2. CREATE DATABASE `students`;
  3.  
  4. // build.sbt:
  5. libraryDependencies ++= Seq(evolutions, jdbc)
  6.  
  7. // application.conf:
  8. db.students {
  9.   driver="com.mysql.jdbc.Driver"
  10.   url="jdbc:mysql://localhost/students?useSSL=false"
  11.   username="root"
  12.   password="1234"
  13. }
  14.  
  15. play.evolutions {
  16.   # enable evolutions
  17.   enabled = true         # default is true
  18.  
  19.   # schema in which the generated evolution and lock tables will be saved to
  20.   schema = students      # default is no schema
  21.  
  22.   # unset autoCommit, so that evolutions will be applied in a single transaction
  23.   autocommit = false     # default is true
  24.  
  25.   # set useLocks, if you have many Play nodes that may potentially run evolutions
  26.   useLocks = true        # default is false
  27.  
  28.   # in dev mode, autoApply will cause both ups and downs evolutions to be automatically applied (only ups in prod)
  29.   autoApply = true       # default is false
  30.  
  31.   # in prod mode, this will cause down evolutions to be automatically applied (no effect in dev)
  32.   autoApplyDowns = false # default is false
  33. }
  34.  
  35. // create folder conf/evolutions/students and create file "1.sql":
  36. # students schema, faculty table
  37.  
  38. # --- !Ups
  39.  
  40. CREATE TABLE `faculty` (
  41.     `faculty_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'primary key',
  42.     `name` VARCHAR(64) NOT NULL COMMENT 'faculty name',
  43.     `isArts` BOOLEAN NOT NULL COMMENT 'whether a faculty is Arts School',
  44.     PRIMARY KEY (`faculty_id`),
  45.     UNIQUE INDEX `faculty_name` (`name`)
  46. ) COMMENT='faculty table' COLLATE='utf8_general_ci' ENGINE=InnoDB;
  47.  
  48. # --- !Downs
  49.  
  50. DROP TABLE IF EXISTS `faculty`;
  51.  
  52. '// ready! Start the server and run http://localhost:9000 and see what will happen to `students` DB
  53.  
  54.  
  55.  
  56. // (2018-02-28) Bonus: let's add Slick to our Play project!
  57.  
  58. // build.sbt
  59. libraryDependencies += "com.typesafe.play" %% "play-slick" % "3.0.1"
  60. libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.41"    // put the driver from your DBMS
  61.  
  62. // application.conf
  63. slick.dbs.students {
  64.   profile = "slick.jdbc.MySQLProfile$"
  65.   db {
  66.     driver = "com.mysql.jdbc.Driver"
  67.     url = "jdbc:mysql://localhost/students?useSSL=false"
  68.     user = "root"
  69.     password = "1234"
  70.   }
  71. }
  72.  
  73. // how to create DAO see at https://pastebin.com/Pa1Ub1Ri
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement