Add MRT recovery state migration#810
Conversation
📝 WalkthroughWalkthroughA single SQL migration adds the ChangesMRT Queue Recovery State Migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql (1)
27-28: ⚖️ Poor tradeoffConsider indexes for common query patterns.
The status index is appropriate for finding PENDING jobs. If the recovery process will also query by
org_id,queue_id, or combinations like(status, org_id), consider adding those indexes for performance. This can be deferred until actual query patterns are known.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql` around lines 27 - 28, Review the recovery process code to identify all common query patterns against the mrt_queue_recovery_state table, particularly checking if queries filter by org_id, queue_id, or combinations of status with these fields. Once the actual query patterns are confirmed, add additional indexes to the migration script for frequently used fields or composite indexes like (status, org_id) to optimize query performance, or document that this optimization can be deferred until query patterns stabilize in production.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql`:
- Line 18: The `mrt_queue_recovery_state` table has an `updated_at` column that
defaults to `now()` but lacks a trigger to update it during row modifications.
Add a trigger function named `update_mrt_queue_recovery_state_updated_at()` in
the `manual_review_tool` schema that sets `NEW.updated_at` to the current
timestamp, then create a BEFORE UPDATE trigger named
`mrt_queue_recovery_state_updated_at_trigger` on the `mrt_queue_recovery_state`
table that executes this function for each row being updated. This should be
added after the table and index creation in the migration script.
- Around line 8-19: The migration file creates the table
mrt_queue_recovery_state but is missing the required GRANT statements to allow
application roles to access it. After the CREATE TABLE statement for
mrt_queue_recovery_state, add GRANT statements that grant appropriate
permissions (SELECT, INSERT, UPDATE, DELETE) to the application role, using
CURRENT_USER syntax instead of hardcoded role names, as per coding guidelines
for supporting any postgres user.
---
Nitpick comments:
In
`@db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql`:
- Around line 27-28: Review the recovery process code to identify all common
query patterns against the mrt_queue_recovery_state table, particularly checking
if queries filter by org_id, queue_id, or combinations of status with these
fields. Once the actual query patterns are confirmed, add additional indexes to
the migration script for frequently used fields or composite indexes like
(status, org_id) to optimize query performance, or document that this
optimization can be deferred until query patterns stabilize in production.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a1b8faf4-4c92-429e-aedb-cc0a87f1c5b2
📒 Files selected for processing (1)
db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql
986dd48 to
aca6460
Compare
aca6460 to
48c0bff
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql (2)
14-14: ⚡ Quick winConsider adding
DEFAULT 'PENDING'to the status column.Since
PENDINGis the initial state for recovery entries (per the column comment on line 52-53), adding a default would simplify inserts and make the intent explicit in the schema.💡 Proposed enhancement
- status text NOT NULL CHECK (status IN ('PENDING', 'FAILED')), + status text NOT NULL DEFAULT 'PENDING' CHECK (status IN ('PENDING', 'FAILED')),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql` at line 14, The status column in the migration file currently lacks a default value despite PENDING being the documented initial state for recovery entries. Add `DEFAULT 'PENDING'` to the status column definition to set the default value explicitly and simplify future inserts by automatically applying the initial state when no status is specified.
9-9: Consider usingcharacter varying(255)forjob_idto match the FK target type.The
job_idcolumn usestext, but it referencesjob_creations.idwhich ischaracter varying(255). While PostgreSQL allows this FK relationship, aligning the types improves schema consistency. Other ID columns in the table (org_id,queue_id, etc.) should also match the types used in their corresponding source tables.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql` at line 9, The job_id column is defined as text but should match the type of its foreign key target job_creations.id which is character varying(255). Change the job_id column definition from text to character varying(255) PRIMARY KEY. Additionally, review other ID columns in the table (org_id, queue_id) and update them to match the types used in their corresponding source tables to ensure schema consistency throughout.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql`:
- Line 14: The status column in the migration file currently lacks a default
value despite PENDING being the documented initial state for recovery entries.
Add `DEFAULT 'PENDING'` to the status column definition to set the default value
explicitly and simplify future inserts by automatically applying the initial
state when no status is specified.
- Line 9: The job_id column is defined as text but should match the type of its
foreign key target job_creations.id which is character varying(255). Change the
job_id column definition from text to character varying(255) PRIMARY KEY.
Additionally, review other ID columns in the table (org_id, queue_id) and update
them to match the types used in their corresponding source tables to ensure
schema consistency throughout.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 1268e2a0-ab4c-40bf-b740-acf6a684fbd8
📒 Files selected for processing (1)
db/src/scripts/api-server-pg/2026.06.17T03.57.25.add_mrt_queue_recovery_state.sql
Context & Requests for Reviewers
Adds the
mrt_queue_recovery_statemigration only. This should land before the recovery code PRs.Tests
Not run; migration only.
Rollout Plan
Merge this first, then land the recovery code stack on top of it.
Summary by CodeRabbit