Skip to content

Instantly share code, notes, and snippets.

@fpauser
Created June 4, 2012 08:26
Show Gist options
  • Save fpauser/2867229 to your computer and use it in GitHub Desktop.
Save fpauser/2867229 to your computer and use it in GitHub Desktop.
Add custom migration methods to rails
class CreateViewTest < ActiveRecord::Migration
def up
create_view_or_table :view_test do
view_column :select => "#{source_db}.dbo.Config.value", :as => :config_value, :type => :integer
view_sql "FROM #{source_db}.dbo.Config"
end
end
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, MyRailsApp::SchemaStatements)
module MyRailsApp
class Migration < ActiveRecord::Migration
def source_db
"source_database"
end
end
module SchemaStatements
def view_column(*args)
column *args
end
def view_sql(sql)
"additional_sql"
end
def create_view_or_table(*args)
create_table *args
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment