[#74977] Modify friendly_id_slugs constraints.#23223
Open
ba1ash wants to merge 1 commit into
Open
Conversation
https://community.openproject.org/wp/74977 Add NOT NULL to *sluggable_type* and fix NULL *scope* uniqueness in *friendly_id_slugs* - Delete duplicate NULL *scope* rows, keeping the most recent per (slug, sluggable_type) - Delete NULL *sluggable_type* rows before adding NOT NULL constraint - Replace unique index on (slug, sluggable_type, scope) with NULLS NOT DISTINCT variant (requires Postgres 15+) Why? 1. *sluggable_type* NOT NULL every slug must belong to a model (e.g. Post, User). A slug with no *sluggable_type* is orphaned and meaningless. 2. NULLS NOT DISTINCT in the unique constraint not treating every NULL *scope* as unique leads to duplicate records if *scope* is NULL which does not make sense and pollutes the table with unnecessary data
2a1aca4 to
357b476
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://community.openproject.org/wp/74977
Add NOT NULL to sluggable_type and fix NULL scope uniqueness in friendly_id_slugs
Why?
Every slug must belong to a model (e.g. Post, User). A slug with no sluggable_type is orphaned and meaningless.
In the unique constraint not treating every NULL scope as unique leads to duplicate records if scope is NULL which does not make sense and pollutes the table with unnecessary data