Created
June 4, 2012 08:26
-
-
Save fpauser/2867229 to your computer and use it in GitHub Desktop.
Add custom migration methods to rails
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
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 |
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
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, MyRailsApp::SchemaStatements) |
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
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