Fix: Role model should use composite primary key (name, project)#937
Open
cuixiaojun001 wants to merge 1 commit into
Open
Fix: Role model should use composite primary key (name, project)#937cuixiaojun001 wants to merge 1 commit into
cuixiaojun001 wants to merge 1 commit into
Conversation
The Role model was missing gorm:"primaryKey" on its Project field, so the vela_role table only enforced uniqueness on the name column under the SQL (MySQL/PostgreSQL) datastore. This contradicts the intended composite key of (name, project) and causes project-scoped roles with the same name (e.g. project-admin/app-developer/project-viewer seeded for each project) to collide at the SQL level, where the second project's insert is silently skipped by BatchAdd and ends up referencing another project's role row. Add gorm:"primaryKey" to Role.Project to align with the sibling Permission model (which already uses this composite key) and with the logic already encoded in Role.PrimaryKey() / the kubeapi backend's ConfigMap naming. Existing deployments need a manual DDL migration: ALTER TABLE vela_role DROP PRIMARY KEY, ADD PRIMARY KEY (name, project); Signed-off-by: cuixiaojun002 <cuixiaojun002@ke.com>
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.
Description of your changes
Fixes #936
The
Rolemodel was missinggorm:"primaryKey"on itsProjectfield, so thevela_roletable only enforced uniqueness on thenamecolumn under the SQL (MySQL/PostgreSQL) datastore. This contradicts the intended composite key of(name, project)and causes project-scoped roles with the same name (project-admin/app-developer/project-viewer, seeded for each project) to collide at the SQL level: the second project's insert is silently skipped byBatchAddand ends up referencing another project's role row.This PR adds
gorm:"primaryKey"toRole.Projectto align with the siblingPermissionmodel (which already uses this composite key) and with the logic already encoded inRole.PrimaryKey()and the kubeapi backend's ConfigMap naming.I have:
yarn lintto ensure the frontend changes are ready for review. (N/A — no frontend change)make reviewableto ensure the server changes are ready for review.backport release-x.ylabels to auto-backport this PR if necessary.Special notes for your reviewer
AutoMigrate); it takes effect for fresh deployments. Existing MySQL/PostgreSQL deployments need a manual DDL migration: