The source project of this merge request has been removed.
WIP: Add a unique index on namespaces.owner_id
What does this MR do?
Prevents data inconsistencies by putting a unique index on the namespaces.owner_id
column
Are there points in the code the reviewer needs to double check?
Perhaps this should be a foreign key instead?
Do we need a data migration to sort out any existing bad rows?
We can get a list of duplicated owner_id
s with SQL like this:
SELECT owner_id, count(1)
FROM namespaces
WHERE owner_id IS NOT NULL
GROUP BY owner_id
HAVING count(owner_id) > 1
If GitLab.com is fine, we can assume everywhere else is. It's not immediately obvious what strategy we would take when resolving duplicates - oldest wins? Oldest loses?
Why was this MR needed?
A user has_one :namespace, foreign_key: :owner_id
. Having multiple rows in the namespaces
table with the same owner_id
means that we get a random record back from the database when we follow that association. This breaks tests, and could be nasty in production too.
Screenshots (if relevant)
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated -
API support added -
Tests added for this feature/bug - Review
-
Has been reviewed by UX -
Has been reviewed by Frontend -
Has been reviewed by Backend -
Has been reviewed by Database
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Squashed related commits together -
Internationalization required/considered -
End-to-end tests pass ( package-qa
manual pipeline job)
What are the relevant issue numbers?
Edited by Nick Thomas