diff options
author | Scott Barron <scott@elitists.net> | 2005-12-20 21:43:47 +0000 |
---|---|---|
committer | Scott Barron <scott@elitists.net> | 2005-12-20 21:43:47 +0000 |
commit | 88bb279df7d2f4c1b4c48be98fbbbae859b20847 (patch) | |
tree | 95e259b5e129d9b31d10f0f944bf0bcc874b4cbe /activerecord/lib | |
parent | 581f12b7b18a6e5205bfabb814f6e9997bf92be8 (diff) | |
download | rails-88bb279df7d2f4c1b4c48be98fbbbae859b20847.tar.gz rails-88bb279df7d2f4c1b4c48be98fbbbae859b20847.tar.bz2 rails-88bb279df7d2f4c1b4c48be98fbbbae859b20847.zip |
Fix change_column to work with postgres 7.x and 8.x.
Closes #3141
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3327 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index e3059ea010..fbb978e034 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -302,7 +302,17 @@ module ActiveRecord end def change_column(table_name, column_name, type, options = {}) #:nodoc: - execute = "ALTER TABLE #{table_name} ALTER #{column_name} TYPE #{type}" + begin + execute "ALTER TABLE #{table_name} ALTER #{column_name} TYPE #{type_to_sql(type, options[:limit])}" + rescue ActiveRecord::StatementInvalid + # This is PG7, so we use a more arcane way of doing it. + begin_db_transaction + add_column(table_name, "#{column_name}_ar_tmp", type, options) + execute "UPDATE #{table_name} SET #{column_name}_ar_tmp = CAST(#{column_name} AS #{type_to_sql(type, options[:limit])})" + remove_column(table_name, column_name) + rename_column(table_name, "#{column_name}_ar_tmp", column_name) + commit_db_transaction + end change_column_default(table_name, column_name, options[:default]) unless options[:default].nil? end |