Skip to content

fix: make alembic task model same in staging as in dev and prod - #518

Draft
tombrooks248 wants to merge 1 commit into
mainfrom
fix/make-alembic-task-model-same-in-staging
Draft

fix: make alembic task model same in staging as in dev and prod#518
tombrooks248 wants to merge 1 commit into
mainfrom
fix/make-alembic-task-model-same-in-staging

Conversation

@tombrooks248

@tombrooks248 tombrooks248 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

In the previous migration (a41b142924f7) I edited it in place after it had already
been applied to staging — its details column was changed from Text to JSONB
(plus NOT NULL constraints and indexes) under the same revision id.

Because Alembic only tracks the revision id, not the file contents, staging never re-ran
it and kept the old Text schema, which made /task.json fail with "details value
is not a valid dict".

This migration is a fresh revision that re-applies those
changes so every environment converges on the correct schema.

Related Tickets & Documents

  • Ticket Link
  • Related Issue #
  • Closes #

QA Instructions, Screenshots, Recordings

I have done some checks locally that the formatting is all correct but now need to run in staging and then DEV to be sure its ready to merge.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above. Please refer to the Digital Land Testing Guidance for more information.

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests

[optional] Are there any post deployment tasks we need to perform?

[optional] Are there any dependencies on other PRs or Work?

Summary by CodeRabbit

  • Chores
    • Optimised task table schema by improving data structure for task details and enforcing stricter validation constraints on key fields.
    • Added database indexes to improve query performance and ensure consistency across environments.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@tombrooks248, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 12 minutes and 38 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99f4911e-40a7-4747-b182-a6a309b962c3

📥 Commits

Reviewing files that changed from the base of the PR and between 95284e5 and f275403.

📒 Files selected for processing (1)
  • migrations/versions/08139a9624a2_reconcile_task_table_details_jsonb_cols_.py

Walkthrough

A new Alembic migration (08139a9624a2) alters the task table by converting the details column from TEXT to JSONB (casting empty strings to NULL), enforcing NOT NULL on dataset, severity, responsibility, and task_source, and creating several idempotent indexes. The downgrade reverses all changes.

Changes

Task Table Schema Reconciliation

Layer / File(s) Summary
Task table JSONB, NOT NULL, and index migration
migrations/versions/08139a9624a2_reconcile_task_table_details_jsonb_cols_.py
Converts details from TEXT to JSONB using NULLIF(details, '')::jsonb casting, alters dataset, severity, responsibility, and task_source to NOT NULL, and creates required indexes with IF NOT EXISTS for idempotence. Downgrade reverts details to TEXT and relaxes nullability on all four columns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the main change: addressing a schema inconsistency in the task model across environments (staging, dev, and prod).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/make-alembic-task-model-same-in-staging

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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
`@migrations/versions/08139a9624a2_reconcile_task_table_details_jsonb_cols_.py`:
- Around line 41-45: The upgrade function creates four indexes with names
"idx_task_dataset", "idx_task_organisation", "idx_task_severity", and
"idx_task_responsibility" on the task table, but the downgrade function does not
remove them. Add a corresponding loop in the downgrade section that drops each
of these four indexes by executing DROP INDEX IF NOT EXISTS statements for each
index name, mirroring the structure of the upgrade block but using DROP INDEX
instead of CREATE INDEX to fully reverse the migration changes.
- Around line 32-36: The current postgresql_using clause in the op.alter_column
call for the "task" table's "details" column only handles exact empty strings
with NULLIF(details, '')::jsonb, but will crash on malformed or whitespace-only
JSON values with InvalidTextRepresentation error. Modify the postgresql_using
parameter to use a safer casting approach that handles invalid JSON gracefully -
consider using a CASE statement or a PostgreSQL function that attempts the JSONB
cast and returns NULL for any malformed values instead of raising an error. This
ensures the migration can run successfully on databases with legacy malformed
data without requiring manual cleanup beforehand.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ef98fda-0d4d-46fe-9130-35343582eb8b

📥 Commits

Reviewing files that changed from the base of the PR and between 6522573 and 95284e5.

📒 Files selected for processing (1)
  • migrations/versions/08139a9624a2_reconcile_task_table_details_jsonb_cols_.py

@tombrooks248
tombrooks248 force-pushed the fix/make-alembic-task-model-same-in-staging branch from 95284e5 to 7183db1 Compare June 22, 2026 12:41
@tombrooks248
tombrooks248 force-pushed the fix/make-alembic-task-model-same-in-staging branch from 7183db1 to f275403 Compare June 22, 2026 12:54
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.

1 participant