簡體   English   中英

為什么游戲框架沒有運行我的進化?

[英]Why is play framework not running my evolutions?

我最近開始了一個基於scala-play-react-seed的新項目。

我對 Play 有一點經驗,並且有其他使用 play-slick 和 slick-evolutions 的項目 - 一切正常,並且在啟動時識別和應用了演變。

在新項目中,這不會發生。 我與數據庫的連接一切正常,所以這不是問題。

據我所知,我沒有收到有關演變的任何錯誤或警告。

我嘗試在application.conf中明確打開它們。

這是我的build.sbt

// core
libraryDependencies ++= Seq(
  evolutions,
  ehcache,
  ws,
  specs2 % Test,
  guice)

libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "4.0.2" % Test

// database
libraryDependencies += "com.typesafe.play" %% "play-slick" % "4.0.2"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "4.0.2"
libraryDependencies += "org.postgresql" % "postgresql" % "9.4-1201-jdbc41"

我懷疑 React UI 的鈎子會阻止后端以某種方式獲取這些文件,但不知道從哪里開始查找。 非常感謝任何幫助。

編輯:

我很確定我的application.conf設置正確,但它是:

slick.dbs.default.profile = "slick.jdbc.PostgresProfile$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/standups?user=postgres&password=password"

正如我之前所說,我很確定這是正確設置的,因為我可以與數據庫對話。 只是沒有被拾起的進化。

這是我的1.sql ,它位於conf/evolutions/default中:

-- !Ups

create table person
(
    id       serial       not null primary key,
    name     varchar(255) not null,
    age      smallint     not null
);

-- !Downs

drop table if exists person cascade;

我不清楚為什么你的進化沒有運行。

我嘗試在此提交中模擬您的設置: https://github.com/d6y/scala-play-react-seed/commit/408853bda6f26a7a4fdc49487c2bb00d243ac0dc

...我必須修改FrontendRunHook以實際啟動前端和服務器(通過https://github.com/yohangz/scala-play-react-seed/pull/30 )。

除此之外, sbt run啟動應用程序並應用進化(通過查看數據庫驗證)。

我添加了play.evolutions.db.default.autoApply = true ,但如果沒有它,您會被告知數據庫需要遷移。

我也在使用 JDK 8,以避免與 Guice 相關的警告( WARNING: An illegal reflective access operation has occurred )。 但是,您沒有提到您看到了這一點,因此這也可能無關緊要。

您需要啟用 play evolutions 配置參數

https://www.playframework.com/documentation/2.8.x/Evolutions

play.evolutions.enabled=true


For example, to enable autoApply for all evolutions, you might set play.evolutions.autoApply=true in application.conf or in a system property. To disable autocommit for a datasource named default, you set play.evolutions.db.default.autocommit=false

您還需要在項目啟動時調用applicationEvolutions

通常,這將在ApplicationLoader的實例中完成。

這表示:

  1. 為您的應用程序“組件”添加 class,其中包括DBComponents with EvolutionsComponents和訪問applicationEvolutions
  2. 編寫一個擴展ApplicationLoader的 class ,它在ApplicationLoaderload方法中重新調整您的組件。
  3. 將完全合格的 class 添加到您的application.conf作為play.application.loader=your.package.name.here.MyAppLoader

您可以在以下位置查看ApplicationLoader和組件的概要: https://www.playframework.com/documentation/2.8.x/ScalaCompileTimeDependencyInjection#Application-entry-point

在數據庫代碼中混入調用applicationEvolutions的細節在: https://www.playframework.com/documentation/2.8.x/Evolutions#Enable-evolutions

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM