forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate the
validate: false
option for check_constraint
`check_constraint` with `validate: false` option actually creates a valid check constraint because PostgreSQL ignores `NOT VALID` option used with `CREATE TABLE` statement. To create a check constraint that is `NOT VALID`, `add_check_constraint` is preferred that generates `ALTER TABLE` statement with `NOT VALID` option. - `check_constraint` with `validate: false` option creates a valid check constraint ```ruby create_table :posts, force: true do |t| t.check_constraint "id > 0", name: "foo", validate: false end ``` ```sql CREATE TABLE "posts" ("id" bigserial primary key, CONSTRAINT foo CHECK (id > 0) NOT VALID); SELECT conname, convalidated FROM pg_constraint WHERE contype = 'c' AND conname = 'foo'; /* conname | convalidated ---------+-------------- foo | t (1 row) */ ``` - `add_check_constraint` with `validate: false` option creates a invalid check constraint ```ruby create_table :posts, force: true do |t| end add_check_constraint :posts, "id > 0", name: "foo", validate: false ``` ```sql CREATE TABLE "posts" ("id" bigserial primary key); ALTER TABLE "posts" ADD CONSTRAINT foo CHECK (id > 0) NOT VALID; SELECT conname, convalidated FROM pg_constraint WHERE contype = 'c' AND conname = 'foo'; /* conname | convalidated ---------+-------------- foo | f (1 row) */ ``` Related to rails#53732 Refer to the following discussion at pgsql-hackers mailing list. https://www.postgresql.org/message-id/202412050936.bse4z5tbmze6%40alvherre.pgsql > Maybe it would have been wise to forbid NOT VALID when used with CREATE > TABLE. But we didn't. Should we do that now? Maybe we can just > document that you can specify it but it doesn't do anything.
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters