Skip to content

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

@vercel
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
Contributor

@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
Contributor

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

@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants