Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ releases: 0004_cleanup_failed_safe_deletes

replays: 0007_organizationmember_replay_access

seer: 0010_drop_legacy_columns
seer: 0011_add_project_repository_fk_to_seer

sentry: 1086_add_source_to_external_actor
sentry: 1087_add_projectrepository

social_auth: 0003_social_auth_json_field

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class RepositoryProjectPathConfig(DefaultFieldsModelExisting):

repository = FlexibleForeignKey("sentry.Repository")
project = FlexibleForeignKey("sentry.Project", db_constraint=False)
project_repository = FlexibleForeignKey(
"sentry.ProjectRepository", null=True, on_delete=models.CASCADE
)
Comment thread
wedamija marked this conversation as resolved.
Comment thread
wedamija marked this conversation as resolved.
Comment thread
wedamija marked this conversation as resolved.

organization_integration_id = HybridCloudForeignKey(
"sentry.OrganizationIntegration", on_delete="CASCADE"
Expand Down
70 changes: 70 additions & 0 deletions src/sentry/migrations/1087_add_projectrepository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Generated by Django 5.2.12 on 2026-05-11 18:17

import django.db.models.deletion
import sentry.db.models.fields.bounded
import sentry.db.models.fields.foreignkey
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("sentry", "1086_add_source_to_external_actor"),
]

operations = [
migrations.CreateModel(
name="ProjectRepository",
fields=[
(
"id",
sentry.db.models.fields.bounded.BoundedBigAutoField(
primary_key=True, serialize=False
),
),
("date_updated", models.DateTimeField(auto_now=True)),
("date_added", models.DateTimeField(auto_now_add=True)),
("source", models.SmallIntegerField(default=0)),
(
"project",
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="sentry.project"
),
),
(
"repository",
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="sentry.repository"
),
),
],
options={
"db_table": "sentry_projectrepository",
"unique_together": {("project", "repository")},
},
),
migrations.AddField(
model_name="repositoryprojectpathconfig",
name="project_repository",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="sentry.projectrepository",
),
),
]
1 change: 1 addition & 0 deletions src/sentry/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
from .projectownership import * # NOQA
from .projectplatform import * # NOQA
from .projectredirect import * # NOQA
from .projectrepository import * # NOQA
from .projectsdk import * # NOQA
from .projectteam import * # NOQA
from .promptsactivity import * # NOQA
Expand Down
34 changes: 34 additions & 0 deletions src/sentry/models/projectrepository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import annotations

from django.db import models

from sentry.backup.scopes import RelocationScope
from sentry.db.models import FlexibleForeignKey, cell_silo_model, sane_repr
from sentry.db.models.base import DefaultFieldsModel


class ProjectRepositorySource(models.IntegerChoices):
MANUAL = 0, "manual"
SCM_ONBOARDING = 1, "scm_onboarding"
AUTO_EVENT = 2, "auto_event"
AUTO_NAME_MATCH = 3, "auto_name_match"
SEER_PREFERENCE = 4, "seer_preference"


@cell_silo_model
class ProjectRepository(DefaultFieldsModel):
__relocation_scope__ = RelocationScope.Excluded

project = FlexibleForeignKey("sentry.Project", on_delete=models.CASCADE)
repository = FlexibleForeignKey("sentry.Repository", on_delete=models.CASCADE)
source = models.SmallIntegerField(
choices=ProjectRepositorySource.choices,
default=ProjectRepositorySource.MANUAL,
)

class Meta:
app_label = "sentry"
db_table = "sentry_projectrepository"
unique_together = (("project", "repository"),)

__repr__ = sane_repr("project_id", "repository_id")
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 5.2.14 on 2026-05-11 21:32

import django.db.models.deletion
import sentry.db.models.fields.foreignkey
from django.db import migrations

from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("seer", "0010_drop_legacy_columns"),
("sentry", "1086_add_projectrepository"),
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
]
Comment thread
sentry[bot] marked this conversation as resolved.
Outdated

operations = [
migrations.AddField(
model_name="seerprojectrepository",
name="project_repository",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="sentry.projectrepository",
),
),
]
3 changes: 3 additions & 0 deletions src/sentry/seer/models/project_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class SeerProjectRepository(DefaultFieldsModel):

project = FlexibleForeignKey("sentry.Project", on_delete=models.CASCADE)
repository = FlexibleForeignKey("sentry.Repository", on_delete=models.CASCADE)
project_repository = FlexibleForeignKey(
"sentry.ProjectRepository", null=True, on_delete=models.CASCADE
)
Comment thread
wedamija marked this conversation as resolved.
branch_name = models.TextField(null=True, blank=True)
instructions = models.TextField(null=True, blank=True)

Expand Down
Loading