You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for if_exists/if_not_exists on remove_column/add_column
This PR adds support for `if_exists` on `remove_column` and
`if_not_exists` on `add_column` to support silently ignoring migrations
if the remove tries to remove a non-existent column or an add tries to
add an already existing column.
We (GitHub) have custom monkey-patched support for these features and
would like to upstream this behavior.
This matches the same behavior that is supported for `create_table` and
`drop_table`. The behavior for sqlite is different from mysql/postgres
and sqlite for remove column and that is reflected in the tests.
Copy file name to clipboardExpand all lines: activerecord/CHANGELOG.md
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,27 @@
1
+
* Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column.
2
+
3
+
Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
4
+
5
+
Example Usage:
6
+
7
+
```
8
+
class AddColumnTitle < ActiveRecord::Migration[6.1]
class RemoveColumnTitle < ActiveRecord::Migration[6.1]
17
+
def change
18
+
remove_column :posts, :title, if_exists: true
19
+
end
20
+
end
21
+
```
22
+
23
+
*Eileen M. Uchitelle*
24
+
1
25
* Regexp-escape table name for MS SQL
2
26
3
27
Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
0 commit comments