Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote check constraint to not null on PG >= 12 #35

Conversation

solebared
Copy link
Contributor

@solebared solebared commented Sep 26, 2023

Addresses #34 .

References

Note on author's minimal expertise :)

I'm not really qualified to evaluate any risks associated with this approach. I've read through the references above and done some minimal testing locally, but don't have much personal expertise in PostgreSQL.

As such, i'm relying on reviewers to weigh in on the approach and potential gotchas.

@solebared
Copy link
Contributor Author

Tested locally on v13.11, and am seeing the desired log output:

LOG:  statement: ALTER TABLE "some_numbers" VALIDATE CONSTRAINT "chk_rails_0171ff2f52" /*application:Wrapbook*/
DEBUG:  verifying table "some_numbers"
LOG:  statement: SET statement_timeout TO '0' /*application:Wrapbook*/
LOG:  statement: BEGIN /*application:Wrapbook*/
LOG:  statement: ALTER TABLE "some_numbers"
        ALTER "number_for_type_change"
        SET NOT NULL
         /*application:Wrapbook*/
DEBUG:  existing constraints on column "some_numbers.number_for_type_change" are sufficient to prove that it does not contain nulls
LOG:  execute <unnamed>: SELECT conname, pg_get_constraintdef(c.oid, true) AS constraintdef, c.convalidated AS valid
                    FROM pg_constraint c
                    JOIN pg_class t ON c.conrelid = t.oid
                    JOIN pg_namespace n ON n.oid = c.connamespace
                    WHERE c.contype = 'c'
                      AND t.relname = 'some_numbers'
                      AND n.nspname = ANY (current_schemas(false))
         /*application:Wrapbook*/
LOG:  statement: ALTER TABLE "some_numbers" DROP CONSTRAINT "chk_rails_0171ff2f52" /*application:Wrapbook*/
LOG:  statement: COMMIT /*application:Wrapbook*/

Note in particular the second DEBUG entry.

@solebared solebared marked this pull request as ready for review September 26, 2023 14:40
@fatkodima
Copy link
Owner

Thanks for the PR! 💪
I will review it today/tomorrow, make some inline changes (if necessary) and release a new version.

@fatkodima fatkodima merged commit e6c2aa4 into fatkodima:master Sep 26, 2023
33 checks passed
@solebared solebared deleted the change-column-type/promote-constraint-on-recent-pg-versions branch September 26, 2023 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants