From a86d4d7bbd6e48e99ed43140c3fae2a54e2b015d Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 27 Sep 2023 02:33:07 +0900 Subject: [PATCH] Add a CHANGELOG entry for #49383 And restore updating old ones in the CHANGELOG. --- activerecord/CHANGELOG.md | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index fa233b15e70c2..109188579b66a 100644 --- a/activerecord/CHANGELOG.md +++ b/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 @@ -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*