Skip to content

Commit 7b6dea9

Browse files
committed
fix(boot): stop creating stub users table on metadata.create_all
Base.metadata.create_all(checkfirst=True) was creating a `users(id integer)` table from the foreign-key stub model defined in src/models/models.py. The users table is owned by evo-auth-service, and when the processor boots first on a fresh install it claims the table before auth gets a chance to run its InitSchema migration — which then silently skips its own create_table :users because if_not_exists: true matches the stub. Net effect: auth runs without the real users schema (no mfa_method, no encrypted_password, no oauth_access_tokens, etc.) and every login returns 500, which cascades as 503 in the CRM. Fix: filter `users` (and any future cross-service tables) out of the create_all() call. The Python `User` model stays for ForeignKey() typing, but no DDL is emitted for it. Auth remains the sole creator of the canonical users table. Incident: multimport.ind.br fresh install on 2026-05-27 — every fresh deploy of rc4 hits this because processor and auth race on first boot.
1 parent e193508 commit 7b6dea9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,16 @@
141141
"POSTGRES_CONNECTION_STRING", "postgresql://postgres:root@localhost:5432/evo_ai"
142142
)
143143

144-
# Create database tables
145-
Base.metadata.create_all(bind=engine, checkfirst=True)
144+
# Create database tables — exclude tables owned by other services (auth/CRM)
145+
# The `users` table is owned by evo-auth-service. Creating it here as a stub
146+
# (id integer) makes auth's InitSchema skip the real creation via if_not_exists,
147+
# permanently breaking authentication. See: incident multimport/2026-05-27.
148+
_owned_by_other_services = {"users"}
149+
_tables_to_create = [
150+
table for name, table in Base.metadata.tables.items()
151+
if name not in _owned_by_other_services
152+
]
153+
Base.metadata.create_all(bind=engine, tables=_tables_to_create, checkfirst=True)
146154

147155
API_PREFIX = "/api/v1"
148156

0 commit comments

Comments
 (0)