Migrations.scala 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package models
  2. import persistenceContext._
  3. class CreateSchema extends Migration {
  4. def timestamp = System.currentTimeMillis + 100
  5. def up = {
  6. removeAllEntitiesTables.cascade.ifExists
  7. createTableForAllEntities.ifNotExists
  8. }
  9. }
  10. class MigrateFortunes extends Migration {
  11. def timestamp = System.currentTimeMillis + 200
  12. def up = {
  13. customScript {
  14. val con = storage.directAccess
  15. try {
  16. val rs = con.createStatement.executeQuery("SELECT id, message FROM Fortune")
  17. while (rs.next)
  18. new ActivateFortune(rs.getLong(1), rs.getString(2))
  19. } finally
  20. con.close
  21. }
  22. }
  23. }
  24. class MigrateWorlds extends Migration {
  25. def timestamp = System.currentTimeMillis + 300
  26. def up = {
  27. customScript {
  28. val con = storage.directAccess
  29. try {
  30. val rs = con.createStatement.executeQuery("SELECT id, randomNumber FROM World")
  31. while (rs.next)
  32. new ActivateWorld(rs.getLong(1), rs.getInt(2))
  33. } finally
  34. con.close
  35. }
  36. }
  37. }
  38. class CreateVersionIndexes extends Migration {
  39. def timestamp = System.currentTimeMillis + 400
  40. def up = {
  41. customScript {
  42. val con = storage.directAccess
  43. try {
  44. con.createStatement.executeUpdate("CREATE UNIQUE INDEX IX_WORLD_VERSION ON ActivateWorld(id, version)")
  45. con.createStatement.executeUpdate("CREATE UNIQUE INDEX IX_FORTUNE_VERSION ON ActivateFortune(id, version)")
  46. } finally
  47. con.close
  48. }
  49. }
  50. }