Skip to content

feat(models): Recreate CodeReviewEvent with updated schema [3/3]#109424

Draft
vaind wants to merge 1 commit intoref/delete-code-review-eventfrom
feat/recreate-code-review-event
Draft

feat(models): Recreate CodeReviewEvent with updated schema [3/3]#109424
vaind wants to merge 1 commit intoref/delete-code-review-eventfrom
feat/recreate-code-review-event

Conversation

@vaind
Copy link
Contributor

@vaind vaind commented Feb 26, 2026

Recreate the CodeReviewEvent table with reviewer feedback from PR #108531 applied:

  • DefaultFieldsModel base class for standard date_added/date_updated fields
  • FlexibleForeignKey for organization and repository (cascade deletion, referential integrity)
  • RelocationScope.Organization so data is preserved during org relocation
  • Backup test coverage in create_exhaustive_organization()

Migration is a clean auto-generated CreateModel — no manual edits.

Stacked on #109422 (table deletion). Retarget to master after PR 2 merges.

This is PR 3 of 3:

  1. ref(models): Pending-delete CodeReviewEvent table [1/3] #109420SafeDeleteModel with MOVE_TO_PENDING
  2. ref(models): Delete CodeReviewEvent table [2/3] #109422SafeDeleteModel with DELETE (drops the table)
  3. This PR — Recreate with updated schema

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 26, 2026
@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1034_remove_code_review_event.py src/sentry/migrations/1035_delete_code_review_event.py src/sentry/migrations/1036_create_code_review_event.py

for 1034_remove_code_review_event in sentry

--
-- Moved model CodeReviewEvent to pending deletion state
--
-- (no-op)

for 1035_delete_code_review_event in sentry

--
-- Delete model CodeReviewEvent
--
DROP TABLE "sentry_code_review_event" CASCADE;

for 1036_create_code_review_event in sentry

--
-- Create model CodeReviewEvent
--
CREATE TABLE "sentry_code_review_event" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NOT NULL, "pr_number" integer NULL, "pr_title" text NULL, "pr_author" text NULL, "pr_url" text NULL, "pr_state" varchar(16) NULL, "raw_event_type" varchar(64) NOT NULL, "raw_event_action" varchar(64) NOT NULL, "trigger_id" varchar(64) NULL, "trigger" varchar(64) NULL, "trigger_user" text NULL, "trigger_at" timestamp with time zone NOT NULL, "target_commit_sha" varchar(64) NULL, "status" varchar(32) NOT NULL, "denial_reason" text NULL, "webhook_received_at" timestamp with time zone NULL, "preflight_completed_at" timestamp with time zone NULL, "task_enqueued_at" timestamp with time zone NULL, "sent_to_seer_at" timestamp with time zone NULL, "review_started_at" timestamp with time zone NULL, "review_completed_at" timestamp with time zone NULL, "seer_run_id" varchar(64) NULL, "comments_posted" integer NULL CHECK ("comments_posted" >= 0), "review_result" jsonb NULL, "organization_id" bigint NOT NULL, "repository_id" bigint NOT NULL);
ALTER TABLE "sentry_code_review_event" ADD CONSTRAINT "sentry_code_review_e_organization_id_1ce9fe63_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_code_review_event" VALIDATE CONSTRAINT "sentry_code_review_e_organization_id_1ce9fe63_fk_sentry_or";
ALTER TABLE "sentry_code_review_event" ADD CONSTRAINT "sentry_code_review_e_repository_id_a5be62a4_fk_sentry_re" FOREIGN KEY ("repository_id") REFERENCES "sentry_repository" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_code_review_event" VALIDATE CONSTRAINT "sentry_code_review_e_repository_id_a5be62a4_fk_sentry_re";
CREATE UNIQUE INDEX CONCURRENTLY "unique_org_repo_trigger_id" ON "sentry_code_review_event" ("organization_id", "repository_id", "trigger_id") WHERE "trigger_id" IS NOT NULL;
CREATE INDEX CONCURRENTLY "sentry_code_review_event_organization_id_1ce9fe63" ON "sentry_code_review_event" ("organization_id");
CREATE INDEX CONCURRENTLY "sentry_code_review_event_repository_id_a5be62a4" ON "sentry_code_review_event" ("repository_id");
CREATE INDEX CONCURRENTLY "sentry_code_date_ad_a2451c_idx" ON "sentry_code_review_event" ("date_added");
CREATE INDEX CONCURRENTLY "sentry_code_organiz_4f4b09_idx" ON "sentry_code_review_event" ("organization_id", "trigger_at");
CREATE INDEX CONCURRENTLY "sentry_code_organiz_7ba32c_idx" ON "sentry_code_review_event" ("organization_id", "repository_id", "trigger_at");
CREATE INDEX CONCURRENTLY "sentry_code_organiz_76bbd1_idx" ON "sentry_code_review_event" ("organization_id", "repository_id", "pr_number");

@vaind vaind force-pushed the ref/delete-code-review-event branch from 7e4c976 to 756b38d Compare February 26, 2026 09:52
Recreate the CodeReviewEvent table with reviewer feedback applied:

- DefaultFieldsModel base class for date_added/date_updated
- FlexibleForeignKey for organization and repository (cascade deletion)
- RelocationScope.Organization (data preserved during org relocation)
- Backup test coverage in create_exhaustive_organization()

Migration is a clean auto-generated CreateModel — no manual edits.

Co-Authored-By: Claude <noreply@anthropic.com>
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