diff options
author | Dinah Shi <dinahshi28@gmail.com> | 2017-12-02 14:30:10 +0800 |
---|---|---|
committer | Dinah Shi <dinahshi28@gmail.com> | 2017-12-02 14:30:10 +0800 |
commit | dd6338a0699f2301d4b2fc8653688b4c4183cee5 (patch) | |
tree | 18d2dfa8292fd57367ce0360407c9883ad787dfa /activerecord/lib/active_record/connection_adapters/abstract | |
parent | 11720c23476a49c6c75239182f096847172b1683 (diff) | |
download | rails-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/connection_adapters/abstract')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 9b7345f7c3..f0c6ad63f9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -600,7 +600,7 @@ module ActiveRecord # to provide these in a migration's +change+ method so it can be reverted. # In that case, +type+ and +options+ will be used by #add_column. def remove_column(table_name, column_name, type = nil, options = {}) - execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{quote_column_name(column_name)}" + execute "ALTER TABLE #{quote_table_name(table_name)} #{remove_column_for_alter(table_name, column_name, type, options)}" end # Changes the column's definition according to the new options. @@ -1340,6 +1340,20 @@ module ActiveRecord options.is_a?(Hash) && options.key?(:name) && options.except(:name, :algorithm).empty? end + def add_column_for_alter(table_name, column_name, type, options = {}) + td = create_table_definition(table_name) + cd = td.new_column_definition(column_name, type, options) + schema_creation.accept(AddColumnDefinition.new(cd)) + end + + def remove_column_for_alter(table_name, column_name, type = nil, options = {}) + "DROP COLUMN #{quote_column_name(column_name)}" + end + + def remove_columns_for_alter(table_name, *column_names) + column_names.map { |column_name| remove_column_for_alter(table_name, column_name) } + end + def insert_versions_sql(versions) sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name) |