I am diving into Play! framework for Scala. While I’ve been working on MySQL all this time, I thought I’ll use a new database to learn Play! for Scala. Thats how I decided to use PostgreSQL. So, here’s how I got it setup.
1. Add Dependency project/Build.scala
1 2 3 4 | val appDependencies = Seq(
"postgresql" % "postgresql" % "9.1-901-1.jdbc4"
)
|
2. Configure database access in conf/application.conf
1 2 3 4 | db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/YOUR_POST_GRE_SQL_DATABASE"
db.default.user=USERNAME
db.default.password=PASSWORD
|
3. Using evolutions
Evolutions help you propagate your schema changes easily to your database. Its similar to migrations in Ruby on Rails. Each evolution script is a plain sql script. The file name goes as 1.sql, 2.sql and so on. Evolutions are placed under the directoryconf/evolutions/<DATABASE_NAME>. Here is an example.
conf/evolutions/warehouse/1.sql
1 2 3 4 5 6 7 8 9 10 11 | #
CREATE TABLE products (
id serial primary key ,
name text,
price float
);
#
DROP TABLE products;
|