Skip to content

Commit

Permalink
Add a CHANGELOG entry for #49383
Browse files Browse the repository at this point in the history
And restore updating old ones in the CHANGELOG.
  • Loading branch information
kamipo committed Sep 26, 2023
1 parent dc56140 commit a86d4d7
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions activerecord/CHANGELOG.md
@@ -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
Expand Down Expand Up @@ -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*

Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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*
Expand Down

0 comments on commit a86d4d7

Please sign in to comment.