Coder Social home page Coder Social logo

wbailey / standalone-migrations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thuss/standalone-migrations

1.0 2.0 0.0 274 KB

A thin wrapper to use Rails Migrations in non Rails projects

Home Page: http://gabrito.com/post/standalone-migrations-using-rails-migrations-in-non-rails-projects

Ruby 100.00%

standalone-migrations's Introduction

Rails migrations in non-Rails (and non Ruby) projects.

USAGE

Install Ruby, RubyGems and a ruby-database driver (e.g. gem install mysql) then: sudo gem install standalone_migrations

Add to Rakefile in your projects base directory: begin require 'tasks/standalone_migrations' MigratorTasks.new do |t| # t.migrations = "db/migrations" # t.config = "db/config.yml" # t.schema = "db/schema.rb" # t.env = "DB" # t.default_env = "development" # t.verbose = true # t.log_level = Logger::ERROR end rescue LoadError => e puts "gem install standalone_migrations to get db:migrate:* tasks! (Error: #{e})" end

Add database configuration to db/config.yml in your projects base directory e.g.: development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000

production:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: somedatabase_dev
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock

test: &test
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

To create a new database migration:

rake db:new_migration name=FooBarMigration
edit db/migrations/20081220234130_foo_bar_migration.rb

... and fill in the up and down migrations Cheatsheet.

If you're lazy and want to just execute raw SQL:

def self.up
  execute "insert into foo values (123,'something');"
end

def self.down
  execute "delete from foo where field='something';"
end

To apply your newest migration:

rake db:migrate

To migrate to a specific version (for example to rollback)

rake db:migrate VERSION=20081220234130

To migrate a specific database (for example your "testing" database)

rake db:migrate DB=test

To execute a specific up/down of one single migration

rake db:migrate:up VERSION=20081220234130

Contributors

This work is based on Lincoln Stoll's blog post and David Welton's post.

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.