Play2 and Postgres
More on developing with H2 from here.
http://www.playframework.com/documentation/2.2.x/Developing-with-the-H2-Database
Postgres installation options for Mac are here
http://www.postgresql.org/download/macosx/
I selected Postgres.app, which was perfect for me, since it's easy to operate.
http://postgresapp.com/
Just to make sure all goes well I also added it to path in .profiles file
Testing connection was easy
But I also installed induction.app for browsing content
http://inductionapp.com/
I used Postgres 9.3 and wanted to use latest driver. Driver was easy to find from maven central.
project/build.scala needed single new dependency for jdbc driver
Here's more of setting up your database
http://www.playframework.com/documentation/2.2.x/JavaDatabase
I could have hacked existing application.conf, but decided to have separate conf/postgres-local.conf for Postgres database settings
Installing Postgres
Postgres installation options for Mac are here
http://www.postgresql.org/download/macosx/
I selected Postgres.app, which was perfect for me, since it's easy to operate.
http://postgresapp.com/
Just to make sure all goes well I also added it to path in .profiles file
- export PG_HOME=/Applications/Postgres.app/Contents/MacOS/bin
- export PATH="$PG_HOME:$PATH"
Testing connection was easy
- psql -h localhost
But I also installed induction.app for browsing content
http://inductionapp.com/
Getting driver
I used Postgres 9.3 and wanted to use latest driver. Driver was easy to find from maven central.
project/build.scala needed single new dependency for jdbc driver
"postgresql" % "postgresql" % "9.1-901.jdbc4",
http://www.playframework.com/documentation/2.2.x/JavaDatabase
Setting up connection
I could have hacked existing application.conf, but decided to have separate conf/postgres-local.conf for Postgres database settings
- db.default.driver=org.postgresql.Driver
- db.default.url="jdbc:postgresql://localhost/nikkijuk"
- db.default.user="nikkijuk"
- db.default.password=""
You can find more of JDBC settings from here
http://www.playframework.com/documentation/2.2.x/SettingsJDBC
For deploying Play2 apps to production one shouldn't ever use "run". I wanted to override settings from command line and use Postgres as 2nd development database. So; "run" is ok.
If you want to know more of overriding settings, please see
http://www.playframework.com/documentation/2.2.x/ProductionConfiguration
I had in Entities some strange stuff like maximum size of numeric identifier.
"@Size(min = 2, max = 64)" definiton generated fields with type bigint(64), which went thru on H2, but were inappropriate on Postgres. Commenting out extra annotations solved problems here.
I found out that Ebean and H2 are unbeatable during development. Changes on data model (Entity classes) were automatically detected, sql was generated, and database model changed according model.
With Postgres there isn't as tight integration. My process is thus, that I first develop all with H2, and then let Play2 to run SQL sentences that set up Postgres. This works fine to me, and at the end I know that I have two very good databases on my service locally.
Get your app to Cloud. Heroku is here a good option, since it supports natively both Play2 and Postgres.
Starting app
- play -Dconfig.file=conf/postgres-local.conf ~run
If you want to know more of overriding settings, please see
http://www.playframework.com/documentation/2.2.x/ProductionConfiguration
Datatype generation
@NotNull
@Column(unique = true)
// @Size(min = 2, max = 64)
public long processId;
"@Size(min = 2, max = 64)" definiton generated fields with type bigint(64), which went thru on H2, but were inappropriate on Postgres. Commenting out extra annotations solved problems here.
Development process
I found out that Ebean and H2 are unbeatable during development. Changes on data model (Entity classes) were automatically detected, sql was generated, and database model changed according model.
With Postgres there isn't as tight integration. My process is thus, that I first develop all with H2, and then let Play2 to run SQL sentences that set up Postgres. This works fine to me, and at the end I know that I have two very good databases on my service locally.
No comments:
Post a Comment