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

val appDependencies = Seq(
      // Add your project dependencies here,
        "postgresql" % "postgresql" % "9.1-901-1.jdbc4"
    )

 2.  Configure database access in conf/application.conf

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

# --- !Ups

CREATE TABLE products (
	id serial primary key,
	name text,
	price float
);

# -- !Downs

DROP TABLE products;

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation