Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place Play Framework 2.1 database evolutions in sub project?

I have a Play Framework 2.1 application, and the database code is located in a sub project — in case I want to support more than one kind of backend in the future, e.g. a file based database or Cassandra.

Currently, however, the database is a relational database and I'd like to use Play's database evolutions mechanism. But I don't know how, or if it is even possible, to place the evolutions script in my sub project (where they belong), rather than in the main project. — If I place them in the sup project, Play apparently ignores them. Question: Can I place my evolutions script in my sub project, and how do I do it?

Edit October 2015: I use FlywayDB now instead of Play's built-in evolutions, since a year or so. I heartily recommend FlywayDB. You can do evolutions in your sub projects with FlywayDB in any way you want, and you need to write the code that starts the evolutions yourself. /Edit


This is what I've tried thus far:

  1. Create a sub project, ./modules/evolutions-test/

  2. In that sub project, create an evolutions script:
    ./modules/evolutions-test/conf/evolutions/default/1.sql

  3. Don't configure database connection info in the sub project — apparently, those settings are ignored (?). Configure the connection info in the main project config file instead, e.g.:

    db.default.driver=org.postgresql.Driver
    db.default.url="jdbc:postgresql://192.168.0.123/test_evolutions"
    db.default.user=test_evolutions
    db.default.password=...
    
  4. Include JDBC and the PostgreSQL driver as dependencies of the sub project.

  5. Have my main project depend on the sub project.
    (And hit reload in Play's console.)

This didn't make Play realize that there is an evolutions script to apply in the sub project. Instead, Play finds and uses any evolutions script that is located in the main projects conf directory. So I suppose I could softlink from the main project to the sub project, and in that manner still keep the contents of the evolution scripts in the sub project.

(I've answered my own question below, because I might as well post all this now once I've written this question — and it actually ought to be useful to some other people? Shouldn't somewhat many people consider placing database code in a sub module?)

like image 358
KajMagnus Avatar asked Jan 22 '26 22:01

KajMagnus


1 Answers

It's currently not possible? See:
https://groups.google.com/d/msg/play-framework/548JUZnjStE/x1hbXyc7PQwJ
which is a discussion about how this can be "fixed" somehow.

Instead, I could softlink from
<main-project>/conf/evolutions/default
to
<main-project>/modules/evolutions-test-project/conf/evolutions/default

like image 188
KajMagnus Avatar answered Jan 24 '26 18:01

KajMagnus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!