Skip to content

Commit 152ebf2

Browse files
authored
Rails 6.1: Add support for if_exists on remove_column (#892)
* Add support for "if_exists" on "remove_column" See rails/rails@95ed7e7 * add changelog item
1 parent e309aee commit 152ebf2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [#861](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/861) Fix Rails 6.1 database config
1313
- [#890](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/890) Fix removal of invalid ordering from select statements
1414
- [#881](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/881) Dump column collation to schema.rb and allow collation changes using column_change
15+
- [#892](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/892) Add support for if_exists on remove_column
1516

1617
#### Changed
1718

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ def rename_table(table_name, new_name)
130130
rename_table_indexes(table_name, new_name)
131131
end
132132

133-
def remove_column(table_name, column_name, type = nil, options = {})
133+
def remove_column(table_name, column_name, type = nil, **options)
134134
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_name.is_a? Array
135+
return if options[:if_exists] == true && !column_exists?(table_name, column_name)
135136

136137
remove_check_constraints(table_name, column_name)
137138
remove_default_constraint(table_name, column_name)

0 commit comments

Comments
 (0)