Created
January 22, 2014 06:57
-
-
Save miyamae/8554551 to your computer and use it in GitHub Desktop.
RailsのmigrationでDBの種類を判定して、PostgreSQLでstring→integerへchange_columnする方法。
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
def change | |
adapter = ActiveRecord::Base.connection.instance_values['config'][:adapter] | |
if adapter == 'postgresql' | |
change_column :table_name, :field_name, 'integer USING CAST(field_name AS integer)' | |
else | |
change_column :table_name, :field_name, :integer | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment