Skip to content

Fix double CREATE TYPE for workspace_role enum#13

Merged
cyrossignol merged 1 commit into
mainfrom
fix-double-enum
Jun 17, 2026
Merged

Fix double CREATE TYPE for workspace_role enum#13
cyrossignol merged 1 commit into
mainfrom
fix-double-enum

Conversation

@cyrossignol

@cyrossignol cyrossignol commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

This fixes the double CREATE TYPE workspace_role AS ENUM... statement that ran once in the standalone statement and again in the column definition despite create_type=False because SQL Alchemy ignores the argument when the definition contains the enum values.

This also removes all the boilerplate for checking whether objects exist—these are inappropriate for migrations which should hard-fail when the DB state does not match the encoded definitions. Those checks masked the issue in some situations.

Summary

This PR simplifies the Alembic migration for the user role table by removing idempotency checks and directly applying schema changes without bind-time introspection.

Changes Made

File: alembic_osm/versions/9221408912dd_add_user_role_table.py

  • Added explicit import of text from sqlalchemy for executing raw SQL
  • upgrade() function: Unconditionally creates the auth_uid_unique unique constraint and the user_workspace_roles table with:
    • Inline enum type definition (sa.Enum("lead", "validator", "contributor", name="workspace_role"))
    • Appropriate column definitions, primary key, and foreign key constraint
  • downgrade() function: Unconditionally drops the table, executes raw DROP TYPE workspace_role SQL, and drops the constraint

Impact

The migration now follows a stricter pattern appropriate for database versioning: directly applying changes rather than checking for object existence before creation. This eliminates the double enum creation issue that occurred when existence checks masked the problem. The migration will hard-fail if the database state does not match the encoded definitions, which is the expected behavior for schema migrations.

Lines changed: +16/-63

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3f7d334-2af7-4dde-a291-026e21d91055

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb02ee and a037f91.

📒 Files selected for processing (1)
  • alembic_osm/versions/9221408912dd_add_user_role_table.py

📝 Walkthrough

Walkthrough

The Alembic migration 9221408912dd_add_user_role_table.py is simplified by removing bind-time introspection and conditional idempotency checks. Both upgrade() and downgrade() now unconditionally apply DDL operations. The inspect import is removed; text is imported directly from sqlalchemy.

Changes

Migration Simplification

Layer / File(s) Summary
Remove idempotency checks and simplify upgrade/downgrade
alembic_osm/versions/9221408912dd_add_user_role_table.py
inspect import is removed and text is imported directly from sqlalchemy. upgrade() unconditionally creates the auth_uid_unique constraint and the user_workspace_roles table with an enum-backed role column. downgrade() unconditionally drops the table, executes DROP TYPE workspace_role, and drops the constraint, replacing prior conditional teardown logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, no more checks to make,
The migration runs clean in its wake!
No inspect, no if, just DDL true,
Up goes the table, down drops it too.
A simpler burrow for every migration crew! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: removing the double CREATE TYPE statement for the workspace_role enum during database migrations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cyrossignol cyrossignol merged commit e8c0902 into main Jun 17, 2026
3 checks passed
@cyrossignol cyrossignol deleted the fix-double-enum branch June 18, 2026 03:26
@coderabbitai coderabbitai Bot mentioned this pull request Jun 24, 2026
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.

1 participant