Merge pull request #49393 from kamipo/changelog_for_unique_constraint

Add a CHANGELOG entry for #49383
This commit is contained in:
Ryuta Kamizono 2023-09-27 02:53:45 +09:00 committed by GitHub
commit 6ef9007cf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 7 deletions

View File

@ -1,3 +1,24 @@
* Better naming for unique constraints support.
Naming unique keys leads to misunderstanding it's a short-hand of unique indexes.
Just naming it unique constraints is not misleading.
In Rails 7.1.0.beta1 or before:
```ruby
add_unique_key :sections, [:position], deferrable: :deferred, name: "unique_section_position"
remove_unique_key :sections, name: "unique_section_position"
```
Now:
```ruby
add_unique_constraint :sections, [:position], deferrable: :deferred, name: "unique_section_position"
remove_unique_constraint :sections, name: "unique_section_position"
```
*Ryuta Kamizono*
* Fix duplicate quoting for check constraint expressions in schema dump when using MySQL
A check constraint with an expression, that already contains quotes, lead to an invalid schema
@ -512,7 +533,7 @@
Because `deferrable: true` and `deferrable: :deferred` are hard to understand.
Both true and :deferred are truthy values.
This behavior is the same as the deferrable option of the add_unique_constraint method, added in #46192.
This behavior is the same as the deferrable option of the add_unique_key method, added in #46192.
*Hiroyuki Ishii*
@ -729,8 +750,8 @@
* Add support for unique constraints (PostgreSQL-only).
```ruby
add_unique_constraint :sections, [:position], deferrable: :deferred, name: "unique_section_position"
remove_unique_constraint :sections, name: "unique_section_position"
add_unique_key :sections, [:position], deferrable: :deferred, name: "unique_section_position"
remove_unique_key :sections, name: "unique_section_position"
```
See PostgreSQL's [Unique Constraints](https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-UNIQUE-CONSTRAINTS) documentation for more on unique constraints.
@ -755,11 +776,11 @@
Using the default behavior, the transaction would fail when executing the
first `UPDATE` statement.
By passing the `:deferrable` option to the `add_unique_constraint` statement in
By passing the `:deferrable` option to the `add_unique_key` statement in
migrations, it's possible to defer this check.
```ruby
add_unique_constraint :items, [:position], deferrable: :immediate
add_unique_key :items, [:position], deferrable: :immediate
```
Passing `deferrable: :immediate` does not change the behaviour of the previous example,
@ -770,14 +791,14 @@
check (after the statement), to a deferred check (after the transaction):
```ruby
add_unique_constraint :items, [:position], deferrable: :deferred
add_unique_key :items, [:position], deferrable: :deferred
```
If you want to change an existing unique index to deferrable, you can use :using_index
to create deferrable unique constraints.
```ruby
add_unique_constraint :items, deferrable: :deferred, using_index: "index_items_on_position"
add_unique_key :items, deferrable: :deferred, using_index: "index_items_on_position"
```
*Hiroyuki Ishii*