Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

postgresql - Errors in evolutions on Heroku

I tried pushing some evolutions to Heroku:

2012-08-30T10:58:00+00:00 heroku[slugc]: Slug compilation finished
2012-08-30T10:58:02+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=32436 -Xmx384m -Xss512k
 -XX:+UseCompressedOops`
2012-08-30T10:58:03+00:00 app[web.1]: Play server process ID is 2
2012-08-30T10:58:05+00:00 app[web.1]: [←[37minfo←[0m] play - database [default] connected at [Database-address]
2012-08-30T10:58:05+00:00 app[web.1]: CREATE TABLE `unapprovedteaminfo` (
---
Copy of 1.sql
---
2012-08-30T10:58:05+00:00 app[web.1]: VALUES (1, 2, 2, '2012-01-01 00:00:00', 'k');
2012-08-30T10:58:05+00:00 app[web.1]: ERROR: syntax error at or near "`"
2012-08-30T10:58:05+00:00 app[web.1]:   Position: 14 [ERROR:0, SQLSTATE:42601]
2012-08-30T10:58:05+00:00 app[web.1]: Oops, cannot start the server.
2012-08-30T10:58:05+00:00 app[web.1]: PlayException: Database 'default' is in inconsistent state! [An evolution has not
been applied properly. Please check the problem and resolve it manually before marking it as resolved.]
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.Evolutions$.checkEvolutionsState(Evolutions.scala:155)

2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.Evolutions$.databaseEvolutions(Evolutions.scala:308)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.Evolutions$.evolutionScript(Evolutions.scala:284)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.s
cala:412)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.s
cala:410)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59
)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.immutable.List.foreach(List.scala:45)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:410)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59
)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.collection.immutable.List.foreach(List.scala:45)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.api.Play$.start(Play.scala:60)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.StaticApplication.<init>(ApplicationProvider.scala:51)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$.createServer(NettyServer.scala:132)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:153)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:152)
2012-08-30T10:58:05+00:00 app[web.1]:   at scala.Option.map(Option.scala:133)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer$.main(NettyServer.scala:152)
2012-08-30T10:58:05+00:00 app[web.1]:   at play.core.server.NettyServer.main(NettyServer.scala)
2012-08-30T10:58:06+00:00 heroku[web.1]: Process exited with status 255
2012-08-30T10:58:06+00:00 heroku[web.1]: State changed from starting to crashed

These evolutions would work just fine with H2, I guess there must be some issues with POSTGRESQL syntax. Anyway, the problem I am having now is that, even if I change 1.sql and push the new version on Heroku, the same error will show up in the logs - the copied 1.sql does not change according to the new pushed version.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're sending to Heroku 1.sql file generated for H2, there is big chance that they will conflict, instead, set the Heroku's url in application.conf as db.default.url and run it in dev mode on localhost first to generate valid Postres SQL. Also you will need to comment out the db.default.user and db.default.password settings, as Heroku's URL contains this information already.

If you don't know current connection's URL you will find it on:

https://postgres.heroku.com/ -> YourDBs -> db-name -> Connection settings -> JDBC URL

To connect from localhost (or other machine, not in the Heroku's space) you need to add this param to the URL:

&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

Thanks to this approach you can test your application locally with established connection to the remote Heroku's DB, (don't be surprised - that combination will be much slower than working with local app + local DB or Heroku app + Heroku DB) anyway for testing it's better than repeatedly pushing small fixes to the cloud.

Also you'll be able to perform evolutions from localhost - without pushing the code to Heroku, and it's really shorter approach if you have problems in your SQL.

Additionally it's good occasion to turn on SQL logging in local dev mode and hunt for redundant SQL queries, if you'll remove all not necessary queries and will be satisfied on localhost, after deploying to the Heroku, you will be just much more satisfied :)

Reset

If you'll create proper 1.sql file than most probably you'll need to reset your DB containing invalid structure (as I assume that's not a problem yet as you just moving from local to Heroku). First find a name of the DB for the current app (with bash, in app's folder):

heroku pg

And then reset it with (it will destroy all data so consider backup first if you don't want to loose your data!):

heroku pg:reset HEROKU_DATABASE_SOMEBASE

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.7k users

...