Git Product home page Git Product logo

flyway-play's Introduction

flyway-play

Scala CI

Flyway module for Play 2.4 or later. It aims to be a substitute for play-evolutions.

Features

  • Based on Flyway
  • No 'Downs' part.
  • Independent of DBPlugin(play.api.db).

Install

flyway-play version play version flyway version
7.22.0 2.8.x 9.0.0
7.21.0 2.8.x 8.5.0
7.20.0 2.8.x 8.5.0
7.19.0 2.8.x 8.4.0
7.18.0 2.8.x 8.3.0
7.17.0 2.8.x 8.2.0
7.16.0 2.8.x 8.1.0
7.15.0 2.8.x 8.0.0
7.14.0 2.8.x 7.14.0
7.13.0 2.8.x 7.13.0
7.12.0 2.8.x 7.12.0
7.11.0 2.8.x 7.11.0
7.10.0 2.8.x 7.10.0
7.9.0 2.8.x 7.9.0
7.8.0 2.8.x 7.8.0
7.7.0 2.8.x 7.7.0
7.6.0 2.8.x 7.6.0
7.5.0 2.8.x 7.5.4
7.2.0 2.8.x 7.2.1
6.5.0 2.8.x 6.5.7
6.2.0 2.8.x 6.2.4
6.0.0 2.8.x 6.1.0
5.4.0 2.7.x 6.0.1
5.3.2 2.7.x 5.2.4
5.2.0 2.6.x 5.2.4
5.1.0 2.6.x 5.1.4
5.0.0 2.6.x 5.0.7
4.0.0 2.6.x 4.2.0
3.2.0 2.5.x 4.2.0

build.sbt

libraryDependencies ++= Seq(
  "org.flywaydb" %% "flyway-play" % "7.22.0"
)

conf/application.conf

play.modules.enabled += "org.flywaydb.play.PlayModule"

Maintenance

This repository is a community project and not officially maintained by the Flyway Team at Redgate. This project is looked after only by the open source community. Community Maintainers are people who have agreed to be contacted with queries for support and maintenance. Community Maintainers:

If you would like to be named as a Community Maintainer, let us know via Twitter: https://twitter.com/flywaydb.

Getting Started

Basic configuration

Database settings can be set in the manner of Play2.

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:example2;db_CLOSE_DELAY=-1"
db.default.username="sa"
db.default.password="secret"

# optional
db.default.migration.schemas=["public", "other"]

Place migration scripts

A migration script is just a simple SQL file.

CREATE TABLE FOO (.............

By default place your migration scripts in conf/db/migration/${dbName} .

If scriptsDirectory parameter is set, it will look for migrations scripts in conf/db/migration/${scriptsDirectory} .

playapp
├── app
│   ├── controllers
│   ├── models
│   └── views
├── conf
│   ├── application.conf
│   ├── db
│   │   └── migration
│   │       ├── default
│   │       │   ├── V1__Create_person_table.sql
│   │       │   └── V2__Add_people.sql
│   │       └── secondary
│   │           ├── V1__create_job_table.sql
│   │           └── V2__Add_job.sql
│   ├── play.plugins
│   └── routes

Alternatively, specify one or more locations per database and place your migrations in conf/db/migration/${dbName}/${locations[1...N]} . By varying the locations in each environment you are able to specify different scripts per RDBMS for each upgrade. These differences should be kept minimal.

For example, in testing use the configuration:

db.default.migration.locations=["common","h2"]

And in production use the configuration:

db.default.migration.locations=["common","mysql"]

Then put your migrations in these folders. Note that the migrations for the secondary database remain in the default location.

playapp
├── app
│   ├── controllers
│   ├── models
│   └── views
├── conf
│   ├── application.conf
│   ├── db
│   │   └── migration
│   │       ├── default
│   │       │   ├── common
│   │       │   │   └── V2__Add_people.sql
│   │       │   ├── h2
│   │       │   │   └── V1__Create_person_table.sql
│   │       │   └── mysql
│   │       │       └── V1__Create_person_table.sql
│   │       └── secondary
│   │           ├── V1__create_job_table.sql
│   │           └── V2__Add_job.sql
│   ├── play.plugins
│   └── routes

Please see flyway's documents about the naming convention for migration scripts.

https://flywaydb.org/documentation/migration/sql.html

Placeholders

Flyway can replace placeholders in Sql migrations. The default pattern is ${placeholder}. This can be configured using the placeholderPrefix and placeholderSuffix properties.

The placeholder prefix, suffix, and key-value pairs can be specified in application.conf, e.g.

db.default.migration.placeholderPrefix="$flyway{{{"
db.default.migration.placeholderSuffix="}}}"
db.default.migration.placeholders.foo="bar"
db.default.migration.placeholders.hoge="pupi"

This would cause

INSERT INTO USERS ($flyway{{{foo}}}) VALUES ('$flyway{{{hoge}}}')

to be rewritten to

INSERT INTO USERS (bar) VALUES ('pupi')

Enable/disable Validation

From flyway 3.0, validate run before migrate by default. Set validateOnMigrate to false if you want to disable this.

db.${dbName}.migration.validateOnMigrate=false // true by default

Migration prefix

Custom sql migration prefix key-value pair can be specified in application.conf:

db.${dbName}.migration.sqlMigrationPrefix="migration_"

Insert Query

If you want to apply your migration not via the web interface, but manually on your production databases you also need the valid insert query for flyway.

db.${dbName}.migration.showInsertQuery=true

Dev

screenshot

For existing schema, Flyway has a option called 'initOnMigrate'. This option is enabled when -Ddb.${dbName}.migration.initOnMigrate=true. For example,

$ play -Ddb.default.migration.initOnMigrate=true

Of course, You can write this in your application.conf.

Manual migration is also supported. Click 'Other operations' or open /@flyway/${dbName} directly.

screenshot

Test

In Test mode, migration is done automatically.

Prod

In production mode, migration is done automatically if db.${dbName}.migration.auto is set to be true in application.conf. Otherwise, it failed to start when migration is needed.

$ play -Ddb.default.migration.auto=true start

Example application

seratch/devteam-app is using play-flyway. Maybe this is a good example.

compile-time DI support

class MyComponents(context: Context)
    extends BuiltInComponentsFromContext(context)
    with FlywayPlayComponents
    ...
    {
  flywayPlayInitializer
  ...
}

License

  • Apache 2.0 License

flyway-play's People

Contributors

aziegler avatar baztoune avatar bitespresso avatar dziman avatar etspaceman avatar gakuzzzz avatar gomes-rocket avatar jopecko avatar k4200 avatar kenichiro22 avatar markterm avatar mikielagutu avatar mipe avatar muuki88 avatar nafg avatar nlochschmidt avatar readmecritic avatar scala-steward avatar scubacabra avatar sullis avatar tilmanginzel avatar tkawachi avatar tototoshi avatar xuwei-k avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.