Skip to content

fix(schedules): backfill agent_run_schedules deleted_at/version on early-deployed envs#341

Merged
jromualdez-scale merged 2 commits into
mainfrom
jerome/fix-agent-run-schedules-columns
Jun 29, 2026
Merged

fix(schedules): backfill agent_run_schedules deleted_at/version on early-deployed envs#341
jromualdez-scale merged 2 commits into
mainfrom
jerome/fix-agent-run-schedules-columns

Conversation

@jromualdez-scale

@jromualdez-scale jromualdez-scale commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What

Adds a follow-up Alembic revision (e7f8a9b0c1d2, child of 3b1c9d2e4f6a) that adds the deleted_at and version columns to agent_run_schedules with ADD COLUMN IF NOT EXISTS.

Why

Revision 3b1c9d2e4f6a (the agent_run_schedules create_table) was amended after it had already been applied in some environments — deleted_at and version were added to its create_table after the fact. Alembic tracks applied revisions by id, not by content, so any environment already stamped at 3b1c9d2e4f6a never re-runs the revision and never picks up the added columns. The ORM selects both columns, so reads fail with:

asyncpg.exceptions.UndefinedColumnError: column agent_run_schedules.deleted_at does not exist

Environments that first applied the final create_table (i.e. created the table in one shot with all columns) are unaffected.

Fix

A new revision is the only thing Alembic will execute on already-stamped environments. It adds both columns idempotently:

  • no-op where create_table already created them (healthy envs)
  • repair where it didn't (envs that ran an earlier form of 3b1c9d2e4f6a)

Schema-only and metadata-cheap — both columns add with a constant/non-volatile default (or nullable), so no table rewrite and no backfill. Passes the migration linter (no findings).

Notes

  • Does not edit 3b1c9d2e4f6a — editing an already-applied revision does nothing for the environments that already ran it.
  • The stray initial_input_method column (dropped from the revision in a later edit) may persist as an unused, harmless extra column on early-deploy envs; the ORM doesn't reference it, so it's left as-is.

🤖 Generated with Claude Code

Greptile Summary

This PR updates the follow-up migration for agent_run_schedules repair columns. The main changes are:

  • Adds deleted_at when missing on early-deployed databases.
  • Adds version with a default of 1 when missing.
  • Makes the downgrade a no-op so parent-owned columns are not removed.

Confidence Score: 5/5

Safe to merge: the migration is narrowly scoped, idempotent for already-healthy databases, and avoids destructive downgrade behavior.

The change adds only missing repair columns with guarded DDL and leaves existing parent-owned schema intact, matching the described Alembic recovery scenario.

T-Rex T-Rex Logs

What T-Rex did

  • Reviewed the base state to confirm the migration file was absent and the schema lacked deleted_at and version before the upgrade.
  • Validated the head revision e7f8a9b0c1d2, which has down_revision 3b1c9d2e4f6a, and confirmed it executes ALTER TABLE agent_run_schedules ADD COLUMN IF NOT EXISTS for deleted_at TIMESTAMP WITH TIME ZONE and version INTEGER NOT NULL DEFAULT 1 to repair the missing-column schema while preserving an already-healthy schema (PRESERVED: True).
  • Inspected the log artifacts captured during the migration run to verify the before and after states.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (2): Last reviewed commit: "fix(schedules): make backfill migration ..." | Re-trigger Greptile

…eployed envs

Revision 3b1c9d2e4f6a was amended after it had already been applied in some
environments: deleted_at and version were added to its create_table after the
fact. Alembic tracks applied revisions by id, so those environments stay
stamped at 3b1c9d2e4f6a and never re-run the revision, leaving their table
without the two columns. The ORM selects both, so reads fail with
UndefinedColumnError; environments that first applied the final create_table
are unaffected.

Add a follow-up revision that adds both columns with ADD COLUMN IF NOT EXISTS:
a no-op where create_table already added them, a repair where it did not.
Schema-only and metadata-cheap (constant/non-volatile defaults), no backfill.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jromualdez-scale jromualdez-scale requested a review from a team as a code owner June 29, 2026 20:29
deleted_at/version belong to the parent revision's final create_table; this
repair migration only re-adds them where the parent ran in an earlier form.
Dropping them on downgrade would strip parent-owned columns from environments
that created the table whole. Addresses Greptile P1 on PR #341.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jromualdez-scale jromualdez-scale enabled auto-merge (squash) June 29, 2026 20:49
@jromualdez-scale jromualdez-scale merged commit fc1ba55 into main Jun 29, 2026
32 checks passed
@jromualdez-scale jromualdez-scale deleted the jerome/fix-agent-run-schedules-columns branch June 29, 2026 20:52
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.

2 participants