Skip to content

Add migration to deduplicate connectors and enforce uniqueness#1041

Merged
SachaProbo merged 1 commit intomainfrom
SachaProbo/unique-connector-per-org
Apr 20, 2026
Merged

Add migration to deduplicate connectors and enforce uniqueness#1041
SachaProbo merged 1 commit intomainfrom
SachaProbo/unique-connector-per-org

Conversation

@SachaProbo
Copy link
Copy Markdown
Contributor

@SachaProbo SachaProbo commented Apr 14, 2026

Delete duplicate connectors per (organization_id, provider), keeping the oldest one, then add a unique index to prevent future duplicates.


Summary by cubic

Deduplicates connectors per organization and provider by keeping the oldest. Adds a unique index to enforce one connector per pair going forward.

  • Migration
    • Temporarily set access_sources.connector_id FK to ON DELETE CASCADE, delete newer duplicates (keep oldest by created_at), then restore the FK.
    • Create unique index idx_connectors_organization_id_provider on (organization_id, provider); run during a low-write window due to locks.

Written for commit c32aff5. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/coredata/migrations/20260414T125046Z.sql">

<violation number="1" location="pkg/coredata/migrations/20260414T125046Z.sql:18">
P1: Re-link dependent `access_sources` rows before deleting duplicate connectors, otherwise the FK can make this migration fail.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread pkg/coredata/migrations/20260414T125046Z.sql
@SachaProbo SachaProbo force-pushed the SachaProbo/unique-connector-per-org branch 3 times, most recently from e444f71 to 1ddb19a Compare April 15, 2026 12:29
Delete duplicate connectors per (organization_id, provider), keeping the
oldest one, then add a unique index to prevent future duplicates.

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
@SachaProbo SachaProbo force-pushed the SachaProbo/unique-connector-per-org branch from 1ddb19a to c32aff5 Compare April 20, 2026 13:07
@SachaProbo SachaProbo merged commit c32aff5 into main Apr 20, 2026
17 checks passed
@SachaProbo SachaProbo deleted the SachaProbo/unique-connector-per-org branch April 20, 2026 13:16
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