Skip to content

CXH-2461: enforce unique role_name in Postgres test fixture - #154

Open
al-conductorone wants to merge 1 commit into
mainfrom
cxh-2461-baton-sql-de-duplicate-the-role-names-seeded-by-the-postgres
Open

al-conductorone wants to merge 1 commit into
mainfrom
cxh-2461-baton-sql-de-duplicate-the-role-names-seeded-by-the-postgres

Conversation

@al-conductorone

Copy link
Copy Markdown
Contributor

Makes each role in the Postgres test database unique, so a role maps 1:1 to its access grant and the connector's grant-replacement test can run against the repo's own fixture (CXH-2461).

The shipped Postgres specs key the role resource id on role_name
(id: ".role_name") and build feature-grant entitlement ids as
'role:' + .role_name + ':member', both assuming role_name is unique.
The roles table had no UNIQUE constraint, so re-applying the init
script against an existing DB appended a second admin/user/reader set,
producing two role_name='user' rows and an ambiguous role:user:member
entitlement that blocked the grant_replace path.

Add UNIQUE to roles.role_name (matching sqlserver-init.sql) so a
duplicate role name is rejected at the schema level and each role
maps 1:1 to an entitlement.
@linear-code

linear-code Bot commented Sep 16, 2026

Copy link
Copy Markdown

CXH-2461

Comment thread test/postgres-init.sql
CREATE TABLE roles (
id SERIAL PRIMARY KEY,
role_name VARCHAR(100) NOT NULL
role_name VARCHAR(100) NOT NULL UNIQUE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: This matches what examples/postgres-test.yml already assumes (role resource id: ".role_name"), and the seeded values admin/user/reader are already distinct, so the constraint is safe. For parity, test/mysql-init.sql:66 has the same roles.role_name column without UNIQUE while examples/mysql-test.yml:310 also derives the role resource ID from .role_name — worth adding the same constraint there (test/sqlserver-init.sql:23 already has it).

@github-actions

Copy link
Copy Markdown
Contributor

Connector PR Review: CXH-2461: enforce unique role_name in Postgres test fixture

Blocking Issues: 0 | Suggestions: 1 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base f429aeef81b2.
Review mode: full
View review run

Review Summary

Scanned the full PR diff for security and correctness: it is a one-line change adding UNIQUE to roles.role_name in the Postgres test fixture. The constraint is consistent with examples/postgres-test.yml, which already derives the role resource ID from .role_name, and the seeded values (admin, user, reader) are already distinct, so CI's psql -f ./test/postgres-init.sql step and the downstream grant/revoke queries are unaffected. No connector code, go.mod/go.sum, or docs changes are in this PR; no prior findings existed.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • test/postgres-init.sql:75 — for cross-fixture parity, test/mysql-init.sql:66 still lacks the same UNIQUE on roles.role_name even though examples/mysql-test.yml:310 also uses .role_name as the role resource ID (test/sqlserver-init.sql:23 already has it).
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `test/mysql-init.sql`:
- Around line 66: The `roles` table declares `role_name VARCHAR(100) NOT NULL` without a
  UNIQUE constraint, but `examples/mysql-test.yml` (line 310) maps the role resource id to
  `.role_name`, so duplicate role names would collide into one resource. Mirror the Postgres
  fixture change by making the column `role_name VARCHAR(100) NOT NULL UNIQUE`. The seeded
  values (`admin`, `user`, `reader`) are already distinct, so no data changes are needed.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blocking issues found.

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.

3 participants