Code Monkey home page Code Monkey logo

migrate's Introduction

migrate

Build Status

Tool for managing and executing your database migrations.

Installation

gem install db-migrate

If you are going to use for example Postgres with migrate, make sure that you have Postgresql server running. migrate is using lazy installation of database specific gems, so it will install pg or mysql2 (if they are not installed already) gem when you choose database type. It is recommended that you install them manually (officialy-supported-versions).

Demo

img

How it works?

It saves metadata about your migrations to database and uses that metadata for executing and creating new migrations.

It supports multiple databases and multiple languages for executing migrations.

Supported databases

  • PostgreSQL
  • MySQL

Supported languages

  • SQL
  • Ruby
  • Python
  • Javascript (Node.js)
  • Go

Additional features

  • ENV variables support in configuration file

How to use it?

--help
Commands:
  migrate init               # initialize tables and create config file if necessary
  migrate new [DESCRIPTION]  # generate files for new migration
  migrate up                 # Upgrade database schema
  migrate down               # Downgrade database schema
  migrate list               # Show list of all migrations
  migrate delete [VERSION]   # Will delete migration data
  migrate version            # Show current version
  migrate help [COMMAND]     # Describe available commands or one specific
Options:
  -r, [--root=ROOT]      # Sepcify migration root directory, where config file is located
                         # Default: .
  -c, [--config=CONFIG]  # Specify custom configuration file name
                         # Default: migrate.conf

init

First thing you have to do is to make initial configuration with migrate init command.

migrate will look for file migrate.conf. If file exists, it will make configuration based on file contents. Example configuration file:

# pg or mysql
storage=pg
# can be one of: sql, ruby, javascript, go, python
lang=sql
# db host
host=localhost
# db port
port=5432
# name of database to use
database=mydb
# db user
user=myuser
# db password
password=${SOME_ENV_VARIABLE}
# name of table where version information will be stored
version_info=version_info_table_name
# name of table where version number will be stored
version_number=version_number_table_name

If configuration file does not exist, it will run interactive configuration file creation process. You will answer few questions about your database, and migrate will create configuration file for you.

new

This command will generate migration scripts for you based on your prefered language.

You will get new directory in format vXXX-YYYY, where XXX is version number, and YYY is short description you provide. Inside generated directory there will be two files. up.LANG and down.LANG, where LANG is language you use for writing migration scripts.

up

When you are done with writing your up and down migration script, you can execute migrate up to run up migration script for new version.

Running up without arguments will move for one version up. You can also execute multiple migrations in single call by providing --to n argument, where n is highest version where you want to navigate.

If you want to run all remaining available migrations, you can pass -a flag to up command, and migrate will run all available migrations.

down

You can also use migrate down to go one version back. down comand also accepts --to n argument, but in this case n is lowest version where you want to navigate.

version

If you are asking yourself about current version, use migrate version to find out current version.

delete

If you don't need some migration, use migrate delete n to remove version n.

list

You can see list of your migrations by running migrate list. This command also provides some additional options for filtering results.

Contributing

  • do ruby magic
  • write tests!
  • send pull request

License

MIT

migrate's People

Contributors

ivpusic avatar

Stargazers

 avatar Artem Kirienko avatar Felix  avatar Giovanni Kock Bonetti avatar  avatar Zhao Han avatar mr.The avatar Michael Lu avatar Joel Moss avatar raecoo avatar june29 avatar Kazunari Takahashi avatar Rodrigo Panachi avatar Sean Huber avatar Gabriel Corado avatar Serdar Dogruyol - Sedo セド avatar Jeremy W. Rowe avatar Joe Fredette avatar Yiorgos Michokostas avatar Jeff Sandberg avatar Chandan Jog avatar Jérôme Lipowicz avatar Patrick Lim avatar Steve Hill avatar Xiaofan Hu avatar Blake Thomson avatar Sven Sporer avatar Roman Bambycha avatar Gabriel Givigier avatar Sergei Stralenia avatar Lee Provoost avatar Dmitry Polushkin avatar Junya Ogura avatar Kensuke Nagae avatar Tomohiro Taira avatar Stéphane Busso avatar Jordan Arentsen avatar Alex Lemanski avatar Robert Audi avatar Amy Dusek avatar Bill Gloff avatar Rodrigo Rosenfeld Rosas avatar Rakhmad Azhari avatar Moritz Lawitschka avatar Juanito Fatas avatar Charles avatar feipinghuang avatar Artur Trofimov avatar Jaymie Jones avatar janfri avatar Jeremy Hinegardner avatar Pablo Crivella avatar Nick DeMonner avatar Vadim Gorbunov avatar  avatar Josh Powell avatar Kimmo Hernborg avatar Samuel Toriel avatar José Carvalho avatar  avatar

Watchers

Rakhmad Azhari avatar  avatar Thomas Ehardt avatar James Cloos avatar  avatar

Forkers

tomzhang

migrate's Issues

Transfer ownership of Ruby gem.

I would like to discuss whether you'd be willing to transfer the ownership of this gem on Rubygems.org so that I can reuse this namespace. I'm currently working on a new database layer and part of that is handling migrations, which I want to release as a gem called "db-migrate". Here is the proposed implementation: https://github.com/socketry/db-migrate

If you would like to go ahead with this, you need to execute the following:

gem owner db-migrate --add [email protected]

Thanks for your consideration.

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.