为什么游戏框架不是 运行 我的进化?
Why is play framework not running my evolutions?
我最近开始了一个新项目,基于 scala-play-react-seed。
我对 Play 有一点经验,并且有其他项目使用 play-slick 和 slick-evolutions - 一切正常,并且在启动时识别并应用了 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;
您需要启用 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
.
的实例中完成
这意味着:
- 为您的应用程序“组件”添加 class,其中包括扩展
DBComponents with EvolutionsComponents
和访问 applicationEvolutions
。
- 编写一个扩展
ApplicationLoader
的 class,它会在 ApplicationLoader
的 load
方法中重新调整您的组件。
- 将完全限定的 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
我不清楚为什么你的进化不是 运行。
我已尝试在此提交中模拟您的设置:https://github.com/d6y/scala-play-react-seed/commit/408853bda6f26a7a4fdc49487c2bb00d243ac0dc
...我不得不修改 FrontendRunHook
以实际启动 front-end 和服务器(通过 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
) 相关的警告。但是,你没有提到你看到了,所以这也可能无关。
我最近开始了一个新项目,基于 scala-play-react-seed。
我对 Play 有一点经验,并且有其他项目使用 play-slick 和 slick-evolutions - 一切正常,并且在启动时识别并应用了 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;
您需要启用 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
.
这意味着:
- 为您的应用程序“组件”添加 class,其中包括扩展
DBComponents with EvolutionsComponents
和访问applicationEvolutions
。 - 编写一个扩展
ApplicationLoader
的 class,它会在ApplicationLoader
的load
方法中重新调整您的组件。 - 将完全限定的 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
我不清楚为什么你的进化不是 运行。
我已尝试在此提交中模拟您的设置:https://github.com/d6y/scala-play-react-seed/commit/408853bda6f26a7a4fdc49487c2bb00d243ac0dc
...我不得不修改 FrontendRunHook
以实际启动 front-end 和服务器(通过 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
) 相关的警告。但是,你没有提到你看到了,所以这也可能无关。