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

feat(develop): Clarify adding constraints #12169

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

isabellaenriquez
Copy link
Member

@isabellaenriquez isabellaenriquez commented Dec 17, 2024

DESCRIBE YOUR PR

Updates develop docs Database Migrations page to clarify the caveats for adding any type of constraint (as opposed to just not null).

Adding Columns

image

Adding Not Null to Columns -> Adding Constraints to Columns (Including Not Null)

image

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.

  • Urgent deadline (GA date, etc.):
  • Other deadline:
  • None: Not urgent, can wait up to 1 week+

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

Copy link

vercel bot commented Dec 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
develop-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 9:08pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Dec 17, 2024 9:08pm
sentry-docs ⬜️ Ignored (Inspect) Visit Preview Dec 17, 2024 9:08pm

Copy link

@vbro vbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
wait for owners-migrations before merging

@vbro
Copy link

vbro commented Dec 17, 2024

FYI: https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-NOTES

Scanning a large table to verify a new foreign key or check constraint can take a long time, and other updates to the table are locked out until the ALTER TABLE ADD CONSTRAINT command is committed ...

@isabellaenriquez
Copy link
Member Author

@vbro thanks, this is covered in the section already:

One approach is to create the constraint as not valid. Then we validate it afterwards. We still need to scan the whole table to validate, but we only need to hold a SHARE UPDATE EXCLUSIVE lock, which only blocks other ALTER TABLE commands, but will allow reads/writes to continue. This works well, but has a slight performance penalty of 0.5-1%. After Postgres 12 we can extend this method to add a real NOT NULL constraint.

Copy link
Member

@vgrozdanic vgrozdanic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks for updating the docs 🙌

@isabellaenriquez isabellaenriquez merged commit dceb512 into master Dec 18, 2024
10 checks passed
@isabellaenriquez isabellaenriquez deleted the isabella/add-col-constraint branch December 18, 2024 15:54
Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this - I'm wondering if we should considering just banning the positive integer fields as well. Either that, or modify them to validate the constraint afterwards without the statement timeout

@isabellaenriquez
Copy link
Member Author

@wedamija We use them a lot on billing side for currency fields, so I'd lean towards the latter solution

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.

4 participants