diff options
author | Matthew Draper <matthew@trebex.net> | 2017-12-03 04:19:27 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-03 04:19:27 +1030 |
commit | 6a7787218b8d75913b58d7bed198495e8d29e34e (patch) | |
tree | ec324f35f9dd2d839016579855c2dac0a6dde90a /activerecord/lib/active_record/connection_adapters/abstract | |
parent | 4c4d092431f45471f90badb81eaa2011843cc39b (diff) | |
parent | dd6338a0699f2301d4b2fc8653688b4c4183cee5 (diff) | |
download | rails-6a7787218b8d75913b58d7bed198495e8d29e34e.tar.gz rails-6a7787218b8d75913b58d7bed198495e8d29e34e.tar.bz2 rails-6a7787218b8d75913b58d7bed198495e8d29e34e.zip |
Merge pull request #31230 from dinahshi/postgresql_extract_sql
Extract sql fragment generators 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 09ccf0c193..fac9e1cca2 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. @@ -1365,6 +1365,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) |