aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration
diff options
context:
space:
mode:
authorDinah Shi <dinahshi28@gmail.com>2017-12-02 14:30:10 +0800
committerDinah Shi <dinahshi28@gmail.com>2017-12-02 14:30:10 +0800
commitdd6338a0699f2301d4b2fc8653688b4c4183cee5 (patch)
tree18d2dfa8292fd57367ce0360407c9883ad787dfa /activerecord/lib/active_record/migration
parent11720c23476a49c6c75239182f096847172b1683 (diff)
downloadrails-dd6338a0699f2301d4b2fc8653688b4c4183cee5.tar.gz
rails-dd6338a0699f2301d4b2fc8653688b4c4183cee5.tar.bz2
rails-dd6338a0699f2301d4b2fc8653688b4c4183cee5.zip
Extract sql fragment generators for alter table from PostgreSQL adapter
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r--activerecord/lib/active_record/migration/compatibility.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb
index c979aaf0a0..da307c1723 100644
--- a/activerecord/lib/active_record/migration/compatibility.rb
+++ b/activerecord/lib/active_record/migration/compatibility.rb
@@ -16,6 +16,15 @@ module ActiveRecord
V5_2 = Current
class V5_1 < V5_2
+ if adapter_name == "PostgreSQL"
+ def change_column(table_name, column_name, type, options = {})
+ unless options[:null] || options[:default].nil?
+ column = connection.send(:column_for, table_name, column_name)
+ connection.execute("UPDATE #{connection.quote_table_name(table_name)} SET #{connection.quote_column_name(column_name)}=#{connection.quote_default_expression(options[:default], column)} WHERE #{connection.quote_column_name(column_name)} IS NULL") if column
+ end
+ connection.change_column(table_name, column_name, type, options)
+ end
+ end
end
class V5_0 < V5_1