DAGDA SEARCH | Back to results | Support

Rake migrate without rails · GitHub

Source: https://gist.github.com/andyvanee/1232513

Instantly share code, notes, and snippets.

@andyvanee

andyvanee/Rakefile

Created September 21, 2011 16:19 Show Gist options

Select an option

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/andyvanee/1232513.js"></script> Save andyvanee/1232513 to your computer and use it in GitHub Desktop. Download ZIP Rake migrate without rails Raw _rake_migrate_without_rails.markdown

Rake migrate without rails

This is a very barebones database migration setup. All that's needed is what's required in the Rakefile and Ruby, of course.

Raw config:database.yml This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
adapter: mysql
encoding: utf8
database: database_name
username: root
password:
Raw db:migrate:001_test_migration.rb This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
class TestMigration < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :name, :string, :null => false
end
end
def self.down
drop_table :users
end
end
Raw Rakefile This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
require 'active_record'
require 'yaml'
require 'mysql'
require 'logger'
task :default => :migrate
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
end
task :environment do
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml')))
ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
end
@flypenguin

flypenguin commented Sep 18, 2014

Copy link Copy Markdown

Does this still work with rails 4.0+? I am getting an error and don't know if it's me or something changed.

@dreyks

dreyks commented Sep 23, 2014

Copy link Copy Markdown

What error do you get?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment