Skip to content

fix(backend): alembic drift PR-B — F3 14x index=True + F7 33x server_default (Option A) + env.py compare_* flags - #66

Merged
adamatdevops merged 1 commit into
mainfrom
fix/alembic-drift-pr-b
Sep 1, 2026
Merged

fix(backend): alembic drift PR-B — F3 14x index=True + F7 33x server_default (Option A) + env.py compare_* flags#66
adamatdevops merged 1 commit into
mainfrom
fix/alembic-drift-pr-b

Conversation

@adamatdevops

Copy link
Copy Markdown
Owner

Closes the MEDIUM canonicalization findings from the Alembic drift recon at research/db_audit/ALEMBIC_DRIFT_RECON.md v0.1. Second of three PRs in the AB-037 A/B/C sequence — PR-A (#65) shipped the runtime-bug fixes; this PR aligns model↔migration representation; PR-C will land the CI gate. Filed as AB-037B in the backlog.

What this PR does

Aligns the SQLAlchemy model metadata with what the migrations actually build against Postgres, so alembic revision --autogenerate produces a clean empty diff going forward — instead of emitting spurious op.drop_index() for 14 valid indexes + missing 33 server_default drift signals + missing type change signals.

F3 — 14x index=True added

Table Columns
actions type, target_id, created_at
anomalies service_id, severity, is_active
recommendations team_id, workload_type
refresh_tokens expires_at
services team_id, template_id, status
users role, is_active

SQLAlchemy's default naming convention produces ix_<table>_<col> — matches the migration index names exactly for all 14. Column types preserved.

F7 — 33x server_default= mirrored (Option A)

All 33 server_default= declarations from the migrations are now mirrored in the models (matching values verbatim). Chose Option A over Option B because zero non-Python writers found in the codebase (grep-verified across airflow-worker, flink-jobs, normalizer, webhook-gateway, job-dispatcher) and zero migration seed-data, so explicit `server_default=` is defense-in-depth for any future writer AND enables `compare_server_default=True` to give accurate autogen signal.

Both `default=` (Python-side) and `server_default=` (DB-side) are preserved — Python code paths continue to work identically.

env.py — compare flags enabled

Both `context.configure(...)` calls now pass `compare_server_default=True` + `compare_type=True`. Without these, autogen silently misses the drift classes that led to the 2026-09-01 recon (F5 ENUM, F6 token_hash length, F7 server_defaults).

Verification

Author-side:

  • All 8 models import cleanly
  • Model server_default coverage: templates(11) + services(7) + recommendations(5) + anomalies(4) + actions(3) + users(3) = 33 ✓
  • Model index count: 15 = migration-alive indexes (15) → parity after PR-A dropped 2 redundant

Final `alembic revision --autogenerate should emit empty` verification requires a fresh dev Postgres — deferred to AB-037C's `alembic check` CI gate.

Scope

7 files, ~60 lines of substantive change (plus formatting):

  • `src/backend/alembic/env.py` — 2x compare_* flags
  • `src/backend/app/db/models/template.py` — 11x server_default
  • `src/backend/app/db/models/service.py` — 7x server_default + 3x index=True
  • `src/backend/app/db/models/anomaly.py` — 4x server_default + 3x index=True
  • `src/backend/app/db/models/recommendation.py` — 5x server_default + 2x index=True
  • `src/backend/app/db/models/action.py` — 3x server_default + 3x index=True
  • `src/backend/app/db/models/user.py` — 3x server_default + 3x index=True (2 User + 1 RefreshToken)

`src/backend/app/db/models/team.py` — no changes (no F3/F7 columns).

Runtime impact

None. Metadata-only changes at the SQLAlchemy binding layer. No DDL, no data migration, no runtime behavior change.

References

🤖 Generated with Claude Code

https://claude.ai/code/session_015G6Qu6rwJZYWjMdxU5bMVt

…default (Option A) + env.py compare_* flags

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015G6Qu6rwJZYWjMdxU5bMVt
@adamatdevops
adamatdevops enabled auto-merge (squash) September 1, 2026 09:54
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 1fc6347f-5962-4833-b62f-a86682fc6818


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.

@github-actions github-actions Bot added pr status:opened Pull Request open, not yet under review pkg:backend Changes to @forge-works/backend labels Sep 1, 2026
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

@@            Coverage Diff             @@
##             main      #66      +/-   ##
==========================================
+ Coverage   52.99%   53.02%   +0.03%     
==========================================
  Files         110      110              
  Lines        6337     6337              
  Branches     1058     1058              
==========================================
+ Hits         3358     3360       +2     
+ Misses       2872     2871       -1     
+ Partials      107      106       -1     
Flag Coverage Δ
backend 63.86% <100.00%> (+0.04%) ⬆️
frontend 28.25% <ø> (ø)
Files with missing lines Coverage Δ
src/backend/app/db/models/action.py 98.00% <100.00%> (ø)
src/backend/app/db/models/anomaly.py 97.82% <100.00%> (ø)
src/backend/app/db/models/recommendation.py 96.77% <100.00%> (ø)
src/backend/app/db/models/service.py 97.91% <100.00%> (ø)
src/backend/app/db/models/template.py 96.96% <100.00%> (ø)
src/backend/app/db/models/user.py 90.69% <100.00%> (ø)

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 164371a...fa87705. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adamatdevops
adamatdevops merged commit fc02ba1 into main Sep 1, 2026
18 checks passed
@adamatdevops
adamatdevops deleted the fix/alembic-drift-pr-b branch September 1, 2026 09:57
@github-actions github-actions Bot added pr status:merged Pull Request merged and removed pr status:opened Pull Request open, not yet under review labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:backend Changes to @forge-works/backend pr status:merged Pull Request merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant