Skip to content

chore(repositories): Remove project and repo columns from SeerProjectRepository and RepositoryProjectPathConfig#115663

Merged
wedamija merged 7 commits into
masterfrom
danf/repository-project-remove-old-cols
May 18, 2026
Merged

chore(repositories): Remove project and repo columns from SeerProjectRepository and RepositoryProjectPathConfig#115663
wedamija merged 7 commits into
masterfrom
danf/repository-project-remove-old-cols

Conversation

@wedamija
Copy link
Copy Markdown
Member

This cleans up writes and any remaining queries to project and repo in SeerProjectRepositoryandRepositoryProjectPathConfig`, and also removes all references to the columns to prepare for deletion.

@wedamija wedamija requested review from a team as code owners May 15, 2026 19:59
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 15, 2026
Comment thread src/sentry/deletions/defaults/project.py Outdated
Comment thread src/sentry/deletions/defaults/project.py Outdated
Base automatically changed from danf/repository-project-unique-cols to master May 15, 2026 22:07
@wedamija wedamija requested review from a team as code owners May 15, 2026 22:37
Comment thread src/sentry/deletions/defaults/repository.py
@wedamija wedamija force-pushed the danf/repository-project-remove-old-cols branch from 340582d to bcb7d08 Compare May 16, 2026 00:35
@wedamija wedamija force-pushed the danf/repository-project-remove-old-cols branch from bcb7d08 to 3a08804 Compare May 18, 2026 16:41
Comment thread tests/sentry/migrations/test_0016_remove_old_fks.py Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

This PR has a migration; here is the generated SQL for src/sentry/migrations/1098_remove_old_fks.py src/sentry/seer/migrations/0016_remove_old_fks.py

for 1098_remove_old_fks in sentry

--
-- Alter unique_together for repositoryprojectpathconfig (0 constraint(s))
--
ALTER TABLE "sentry_repositoryprojectpathconfig" DROP CONSTRAINT "sentry_repositoryproject_project_id_stack_root_so_c371dfa7_uniq";
--
-- Alter field project on repositoryprojectpathconfig
--
ALTER TABLE "sentry_repositoryprojectpathconfig" ALTER COLUMN "project_id" DROP NOT NULL;
--
-- Alter field repository on repositoryprojectpathconfig
--
SET CONSTRAINTS "sentry_repositorypro_repository_id_e5400943_fk_sentry_re" IMMEDIATE; ALTER TABLE "sentry_repositoryprojectpathconfig" DROP CONSTRAINT "sentry_repositorypro_repository_id_e5400943_fk_sentry_re";
ALTER TABLE "sentry_repositoryprojectpathconfig" ALTER COLUMN "repository_id" DROP NOT NULL;
--
-- Moved repositoryprojectpathconfig.project field to pending deletion state
--
-- (no-op)
--
-- Moved repositoryprojectpathconfig.repository field to pending deletion state
--
-- (no-op)

for 0016_remove_old_fks in seer

--
-- Alter unique_together for seerprojectrepository (0 constraint(s))
--
ALTER TABLE "seer_projectrepository" DROP CONSTRAINT "seer_projectrepository_project_id_repository_id_f08c56d6_uniq";
--
-- Alter field project on seerprojectrepository
--
SET CONSTRAINTS "seer_projectrepository_project_id_9b6ca557_fk_sentry_project_id" IMMEDIATE; ALTER TABLE "seer_projectrepository" DROP CONSTRAINT "seer_projectrepository_project_id_9b6ca557_fk_sentry_project_id";
ALTER TABLE "seer_projectrepository" ALTER COLUMN "project_id" DROP NOT NULL;
--
-- Alter field repository on seerprojectrepository
--
SET CONSTRAINTS "seer_projectreposito_repository_id_1c1c52ec_fk_sentry_re" IMMEDIATE; ALTER TABLE "seer_projectrepository" DROP CONSTRAINT "seer_projectreposito_repository_id_1c1c52ec_fk_sentry_re";
ALTER TABLE "seer_projectrepository" ALTER COLUMN "repository_id" DROP NOT NULL;
--
-- Moved seerprojectrepository.project field to pending deletion state
--
-- (no-op)
--
-- Moved seerprojectrepository.repository field to pending deletion state
--
-- (no-op)

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 25898b6. Configure here.

SeerProjectRepository,
{"project_repository__project_id": instance.id},
BulkModelDeletionTask,
)
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.

Project deletion fails with branch override FK violation

High Severity

When deleting a project, SeerProjectRepository is deleted via BulkModelDeletionTask, which performs a raw SQL DELETE bypassing Django's ORM cascade. However, SeerProjectRepositoryBranchOverride rows referencing those SeerProjectRepository rows are never explicitly deleted first. Since Django creates FK constraints as NO ACTION (not ON DELETE CASCADE) at the database level, the raw DELETE will raise an IntegrityError if any SeerProjectRepositoryBranchOverride rows exist. Previously, SeerProjectRepository had a direct project FK, so Django's ORM cascade from Project.delete() handled the entire chain automatically. Now that the FK is removed, explicit deletion of SeerProjectRepositoryBranchOverride before SeerProjectRepository is needed.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 25898b6. Configure here.

@wedamija wedamija enabled auto-merge (squash) May 18, 2026 17:51
@wedamija wedamija force-pushed the danf/repository-project-remove-old-cols branch from 0190e8d to c1eaea1 Compare May 18, 2026 18:02
wedamija and others added 7 commits May 18, 2026 11:18
…ojectRepository` and `RepositoryProjectPathConfig`

This cleans up writes and any remaining queries to `project` and `repo in `SeerProjectRepository` and `RepositoryProjectPathConfig`, and also removes all references to the columns to prepare for deletion.
- Fix project deletion: RepositoryProjectPathConfig and SeerProjectRepository
  no longer have project_id, use project_repository__project_id join instead
- Fix test files accessing .repository on RepositoryProjectPathConfig, now
  goes through .project_repository.repository
- Fix migration state: keep constraint from 1097, drop unique_together to empty

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
- sentry 1098: Let AlterUniqueTogether run normally to drop the old
  (project, stack_root, source_root) constraint from the DB
- seer 0016: Use state-only AlterUniqueTogether because 0014's
  AlterField with unique=True already dropped the old constraint

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
…tion

The old (project, repository) unique constraint exists in production and
needs to be dropped by the migration. The sqlmigrate error on fresh DBs
is a false alarm — Django's from-scratch replay doesn't create the old
constraint, but production has it.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@wedamija wedamija force-pushed the danf/repository-project-remove-old-cols branch from c1eaea1 to 9626772 Compare May 18, 2026 18:18
@wedamija wedamija merged commit 21ed110 into master May 18, 2026
83 of 85 checks passed
@wedamija wedamija deleted the danf/repository-project-remove-old-cols branch May 18, 2026 18:37
wedamija added a commit that referenced this pull request May 18, 2026
Phase 2 of `SafeRemoveField`: drop the `project_id` and `repository_id` columns from `sentry_repositoryprojectpathconfig` and `seer_projectrepository`.

Phase 1 (`MOVE_TO_PENDING`) was deployed in #115663.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants