Skip to content

Commit 946dc6b

Browse files
authored
Merge pull request #983 from yellowspot/optimize-remove-columns
[Rails 7] Optimize remove columns
2 parents fd6c2d7 + 0cfde54 commit 946dc6b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#### Changed
88

9-
...
9+
- [#983](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/983) Optimize remove_columns to use a single SQL statement
1010

1111
#### Added
1212

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ def column_definitions_sql(database, identifier)
507507
}.gsub(/[ \t\r\n]+/, " ").strip
508508
end
509509

510+
def remove_columns_for_alter(table_name, *column_names, **options)
511+
first, *rest = column_names
512+
513+
# return an array like this [DROP COLUMN col_1, col_2, col_3]. Abstract adapter joins fragments with ", "
514+
[remove_column_for_alter(table_name, first)] + rest.map { |column_name| quote_column_name(column_name) }
515+
end
516+
510517
def remove_check_constraints(table_name, column_name)
511518
constraints = select_values "SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE where TABLE_NAME = '#{quote_string(table_name)}' and COLUMN_NAME = '#{quote_string(column_name)}'", "SCHEMA"
512519
constraints.each do |constraint|

0 commit comments

Comments
 (0)