basyx commited on
Commit
17c88c2
·
verified ·
1 Parent(s): a60df6d

Detect additive generation schema migrations in readiness checks

Browse files
Files changed (1) hide show
  1. app/security/database.py +22 -0
app/security/database.py CHANGED
@@ -191,6 +191,28 @@ class SecurityDatabase:
191
  )
192
  return missing
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  async def missing_tables(self) -> list[str]:
195
  async with self.engine.connect() as connection:
196
  tables = await connection.run_sync(lambda sync: set(inspect(sync).get_table_names()))
 
191
  )
192
  return missing
193
 
194
+ async def missing_schema_columns(self) -> list[str]:
195
+ """Report columns introduced by additive migrations that create_all cannot repair."""
196
+ required = {
197
+ "generation_requests": {"project_id", "product_surface"},
198
+ "generation_jobs": {"brand_kit_version_id"},
199
+ "generation_job_attempts": {"error_code"},
200
+ }
201
+ async with self.engine.connect() as connection:
202
+ def inspect_columns(sync_connection):
203
+ inspector = inspect(sync_connection)
204
+ tables = set(inspector.get_table_names())
205
+ missing: list[str] = []
206
+ for table, expected in required.items():
207
+ if table not in tables:
208
+ continue # Missing tables are reported by missing_schema_objects().
209
+ columns = {column["name"] for column in inspector.get_columns(table)}
210
+ missing.extend(
211
+ f"column:{table}.{name}" for name in sorted(expected - columns)
212
+ )
213
+ return missing
214
+ return await connection.run_sync(inspect_columns)
215
+
216
  async def missing_tables(self) -> list[str]:
217
  async with self.engine.connect() as connection:
218
  tables = await connection.run_sync(lambda sync: set(inspect(sync).get_table_names()))