Skip to content

feat: add sequin date-based backfill script and missing backfill indexes#4385

Closed
epipav wants to merge 1 commit into
mainfrom
feat/sequin-backfill-tooling
Closed

feat: add sequin date-based backfill script and missing backfill indexes#4385
epipav wants to merge 1 commit into
mainfrom
feat/sequin-backfill-tooling

Conversation

@epipav

@epipav epipav commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

…indexes

Signed-off-by: anilb <epipav@gmail.com>
Copilot AI review requested due to automatic review settings July 22, 2026 19:13
@cursor

cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Concurrent index builds on multi-million-row production tables add load and deploy coupling to Flyway mixed mode; the script can start production CDC backfills if misused, though it requires explicit confirmation.

Overview
Adds database support and an ops script so Sequin can run date-bounded backfills without timing out on huge tables.

A Flyway migration creates CREATE INDEX CONCURRENTLY composites on versions (last_synced_at, id, package_id) and package_dependencies (updated_at, id, depends_on_id) to match Sequin’s keyset pagination cursor. The migration notes Flyway -mixed=true so CONCURRENTLY runs outside a transaction.

New scripts/sequin-backfill.py walks operators through (or accepts flags for) choosing a Sequin CLI context, database, UTC start date, and tables, then creates one partial backfill per sink/table. It lists databases/sinks via the Management API but creates backfills through bin/sequin rpc and Sequin.Consumers.create_backfills_for_form/3, because the HTTP API only supports full-table backfills. It auto-picks common sort columns, supports SEQUIN_RPC_EXEC / lfx-prod kubectl exec, dry-run, and a typed yes confirmation for production.

Reviewed by Cursor Bugbot for commit ceca499. Bugbot is set up for automated code reviews on this repo. Configure here.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ceca499. Configure here.

return data
except (urllib.error.URLError, OSError, json.JSONDecodeError) as e:
last_err = e
die(f"cannot reach Sequin API at {self.host}: {last_err}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

HTTP 404 never reaches handlers

Medium Severity

SequinApi.get catches urllib.error.URLError, which includes HTTPError, so a 404 from /api/postgres_databases or /api/sinks is treated like a connectivity failure. The script retries HTTP and exits instead of running the HTTPError handlers that fall back to /api/databases or report a missing sinks endpoint.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ceca499. Configure here.

ON versions (last_synced_at, id, package_id);

CREATE INDEX CONCURRENTLY IF NOT EXISTS package_dependencies_updated_at_id_depends_on_id_idx
ON package_dependencies (updated_at, id, depends_on_id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Concurrent index on partitioned tables

High Severity

The migration runs CREATE INDEX CONCURRENTLY on versions and package_dependencies, which are hash-partitioned parents. On PostgreSQL 14 (the version used for the packages DB in this repo), concurrent index builds on partitioned tables are rejected, so Flyway can fail before either backfill index exists.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ceca499. Configure here.

@epipav epipav closed this Jul 22, 2026

Copilot AI 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.

Pull request overview

Adds tooling and indexes for date-based Sequin backfills.

Changes:

  • Adds an interactive/non-interactive backfill script.
  • Adds keyset-pagination indexes for large package tables.

Metadata: PR title is missing the required JIRA key.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
scripts/sequin-backfill.py Plans and triggers date-based Sequin backfills.
backend/src/osspckgs/migrations/V1784745489__sequin_backfill_sort_column_indexes.sql Adds backfill sort indexes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +8
CREATE INDEX CONCURRENTLY IF NOT EXISTS versions_last_synced_at_id_package_id_idx
ON versions (last_synced_at, id, package_id);
Comment on lines +10 to +11
CREATE INDEX CONCURRENTLY IF NOT EXISTS package_dependencies_updated_at_id_depends_on_id_idx
ON package_dependencies (updated_at, id, depends_on_id);
Comment on lines +164 to +168
class SequinApi:
def __init__(self, ctx):
self.token = ctx["api_token"]
self.host = ctx["hostname"]
self.base = None # resolved on first request
@epipav
epipav deleted the feat/sequin-backfill-tooling branch July 22, 2026 19:32
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.

3 participants