Giter VIP home page Giter VIP logo

play-morphia-evolutions's Introduction

Play Morphia Evolutions

Overview

This module is an adaptation of the native Play 1.2 Evolutions for Morphia.

It allows to manage evolution scripts (with "up" and "down" statements) and automatically checks if your database is up-to-date regarding this evolutions. If it is not the case, scripts can be applied :

  • from the browser in dev mode
  • via a dedicated command in prod mode

Installation

Add the dependency for this module in your application conf/dependencies.yml

require:
    - play
    - play -> morphia 1.2.9
    - morphiaevolutions -> morphiaevolutions 0.2

repositories:
    - morphiaevolutions:
        type: http
        artifact: https://github.com/cleverage/play-morphia-evolutions/raw/master/dist/[module]-[revision].zip
        containts:
            - morphiaevolutions -> *

Then retrieve the module using

play deps --sync

By default, evolutions are enabled in the plugin. If you want to disable evolutions, you can update your conf/application.conf :

morphia.evolutions.enabled=false

Usage

Once the module is installed, you can create evolution scripts in the directory db/evolutions

Evolution scripts should be name 1.js, 2.js,โ€ฆ in the order you want your evolutions to be applied.

The syntax of these scripts is quite similar to the standard Play evolution scripts syntax. Ex :

// Initializing Foo data
// --- !Ups

db.foo.insert({a: 1})

// --- !Downs

db.foo.remove({a: 1})	

You can then check your database state using the morphiaevolutions command:

$ play morphiaevolutions
~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.5, http://www.playframework.org
~
~ Application revision is 1 [432895f] and Database revision is 0 [da39a3e]
~
~ Your database needs evolutions!

# ------------------------------------------------------------------------------

// --- Rev:1,Ups - 432895f

  db.foo.insert({a: 1})

# ------------------------------------------------------------------------------

~ Run `play morphiaevolutions:apply` to automatically apply this script to the database
~ or apply it yourself and mark it done using `play morphiaevolutions:markApplied`
~

In dev mode, if you launch your app using play run you will see this in your browser.

The other command apply, markApplied, resolve works as their standard Play evolutions equivalents. see Play evolutions documentation.

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.