1111import sqlalchemy as sa
1212from alembic import op
1313from sqlalchemy import inspect , text
14+ from sqlalchemy .dialects import postgresql
1415
1516# revision identifiers, used by Alembic.
1617revision : str = "9221408912dd"
@@ -24,6 +25,25 @@ def upgrade() -> None:
2425 assert bind is not None
2526 insp = inspect (bind )
2627
28+ # `users` is normally owned and migrated by the OSM Rails app. When
29+ # running against a fresh database without Rails (CI/testcontainers,
30+ # or a dev box without the osm-rails service), create a minimal stub
31+ # so the FK from `tasking_project_roles`/`user_workspace_roles` can
32+ # be added below. Guarded by has_table so the production-owned
33+ # schema wins when it is already present.
34+ if not insp .has_table ("users" ):
35+ op .create_table (
36+ "users" ,
37+ # `id` matches the Rails `users.id` numeric PK so the FK
38+ # from `team_user.user_id` in the next migration can attach.
39+ sa .Column ("id" , sa .BigInteger (), autoincrement = True , nullable = False ),
40+ sa .Column ("auth_uid" , sa .String (), nullable = False ),
41+ sa .Column ("email" , sa .String (), nullable = True ),
42+ sa .Column ("display_name" , sa .String (), nullable = True ),
43+ sa .PrimaryKeyConstraint ("id" ),
44+ sa .UniqueConstraint ("auth_uid" , name = "auth_uid_unique" ),
45+ )
46+
2747 # Add unique constraint on users.auth_uid (if not already present)
2848 constraint_exists = bind .execute (
2949 text ("SELECT 1 FROM pg_constraint WHERE conname = 'auth_uid_unique'" )
@@ -49,7 +69,7 @@ def upgrade() -> None:
4969 sa .Column ("workspace_id" , sa .BigInteger (), nullable = False ),
5070 sa .Column (
5171 "role" ,
52- sa . Enum (
72+ postgresql . ENUM (
5373 "lead" ,
5474 "validator" ,
5575 "contributor" ,
0 commit comments