Skip to content

ref(models): Update CodeReviewEvent per reviewer feedback#109401

Closed
vaind wants to merge 1 commit intomasterfrom
ref/code-review-event-model-updates
Closed

ref(models): Update CodeReviewEvent per reviewer feedback#109401
vaind wants to merge 1 commit intomasterfrom
ref/code-review-event-model-updates

Conversation

@vaind
Copy link
Copy Markdown
Contributor

@vaind vaind commented Feb 25, 2026

Address post-merge reviewer feedback on CodeReviewEvent from PR #108531 (and related discussion in #108533 / Slack). No data has been written to the table yet, making this a safe schema adjustment.

Changes:

  • DefaultFieldsModel base class — Provides standard date_added (auto_now_add) and date_updated (auto_now) fields, replacing the manual date_added. Recommended by wedamija and Dan Fuller.
  • FlexibleForeignKey for organization and repository — Adds FK constraints for cascade deletion support and referential integrity. The underlying column names (organization_id, repository_id) are unchanged, so all existing code using _id accessors continues to work. Recommended by wedamija, Dan Fuller, and Armen.
  • RelocationScope.Organization — Ensures data is preserved when orgs move between regions. Confirmed by markstory.
  • Backup test coverage — Added CodeReviewEvent instance in create_exhaustive_organization() to satisfy the exhaustive/uniqueness backup test requirements.

Important note:

Django can't auto-detect that the raw ID fields are being converted to ForeignKeys (same column names under the hood).

The migration uses SeparateDatabaseAndState because the column names don't change — only Django's field representation and the addition of FK constraints. Composite index names are identical since they're derived from column names (not field names).

Address post-merge feedback on CodeReviewEvent from PR #108531:

- Use DefaultFieldsModel base class for standard date_added/date_updated
  fields (wedamija, Dan Fuller)
- Add FlexibleForeignKey for organization and repository instead of plain
  integer fields, enabling cascade deletion (wedamija, Dan Fuller, Armen)
- Change __relocation_scope__ from Excluded to Organization so data is
  preserved during org relocation (markstory)
- Add backup test coverage in create_exhaustive_organization()

The migration uses SeparateDatabaseAndState because the underlying column
names (organization_id, repository_id) don't change — only Django's field
representation and the addition of FK constraints.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1034_alter_code_review_event_model.py

for 1034_alter_code_review_event_model in sentry

--
-- Custom state/database change combination
--
ALTER TABLE "sentry_code_review_event" ADD CONSTRAINT "sentry_code_review_ev_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE "sentry_code_review_event" ADD CONSTRAINT "sentry_code_review_ev_repository_id_fk" FOREIGN KEY ("repository_id") REFERENCES "sentry_repository" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "sentry_code_review_ev_repository_id_fk_idx" ON "sentry_code_review_event" ("repository_id");
--
-- Custom state/database change combination
--
ALTER TABLE "sentry_code_review_event" ADD COLUMN "date_updated" timestamp with time zone DEFAULT (STATEMENT_TIMESTAMP()) NOT NULL;
--
-- Alter field date_added on codereviewevent
--
DROP INDEX CONCURRENTLY IF EXISTS "sentry_code_review_event_date_added_cd622aec";
--
-- Create index sentry_code_date_ad_a2451c_idx on field(s) date_added of model codereviewevent
--
CREATE INDEX CONCURRENTLY "sentry_code_date_ad_a2451c_idx" ON "sentry_code_review_event" ("date_added");

@vaind vaind closed this Feb 26, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant