Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ releases: 0004_cleanup_failed_safe_deletes

replays: 0006_add_bulk_delete_job

sentry: 1012_add_event_id_to_open_period
sentry: 1013_add_repositorysettings_table

social_auth: 0003_social_auth_json_field

Expand Down
61 changes: 61 additions & 0 deletions src/sentry/migrations/1013_add_repositorysettings_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generated by Django 5.2.8 on 2025-12-09 22:43

import django.contrib.postgres.fields
import django.db.models.deletion
from django.db import migrations, models

import sentry.db.models.fields.bounded
import sentry.db.models.fields.foreignkey
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", "1012_add_event_id_to_open_period"),
]

operations = [
migrations.CreateModel(
name="RepositorySettings",
fields=[
(
"id",
sentry.db.models.fields.bounded.BoundedBigAutoField(
primary_key=True, serialize=False
),
),
("enabled_code_review", models.BooleanField(default=False)),
(
"code_review_triggers",
django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(max_length=32), default=list, size=None
),
),
Comment on lines +41 to +47
Copy link
Member

Choose a reason for hiding this comment

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

The Repository has a config json blob field. If you don't need to do filtering/aggregations on these fields you could use the JSON field. Alternatively, you could add these columns to sentry_repository directly.

Copy link
Contributor Author

@ajay-sentry ajay-sentry Dec 10, 2025

Choose a reason for hiding this comment

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

@markstory Spoke to integrations during office hours and we didn't wanna use the config blob for 2 reasons:

  1. That config field is a text field rather than a json column, and is marked as a legacy field in the code too:
    config = LegacyTextJSONField(default=dict)
  2. We wanted to keep the repository table clean of any settings, opting to do a join/expand for any list/get APIs that require this additional information. The current config column looked to just have a "name:" key/value for the most part (GitHub provider repos), other providers might've had different blobs but didn't explicitly scan many of em.

Some more context on what we're building can be found in the doc @suejung-sentry started here
https://www.notion.so/sentry/Seer-Settings-Backend-2bf8b10e4b5d80268863fb6107d5a374

(
"repository",
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="sentry.repository",
unique=True,
),
),
],
options={
"db_table": "sentry_repositorysettings",
},
),
]
1 change: 1 addition & 0 deletions src/sentry/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
from .releaseprojectenvironment import * # NOQA
from .releases.release_project import * # NOQA
from .repository import * # NOQA
from .repositorysettings import * # NOQA
from .rollbackorganization import * # NOQA
from .rollbackuser import * # NOQA
from .rule import * # NOQA
Expand Down
43 changes: 43 additions & 0 deletions src/sentry/models/repositorysettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from __future__ import annotations

from enum import StrEnum

from django.contrib.postgres.fields.array import ArrayField
from django.db import models

from sentry.backup.scopes import RelocationScope
from sentry.db.models import FlexibleForeignKey, Model, region_silo_model, sane_repr


class CodeReviewTrigger(StrEnum):
ON_COMMAND_PHRASE = "on_command_phrase"
ON_NEW_COMMIT = "on_new_commit"
ON_READY_FOR_REVIEW = "on_ready_for_review"

@classmethod
def as_choices(cls) -> tuple[tuple[str, str], ...]:
return tuple((trigger.value, trigger.value) for trigger in cls)


@region_silo_model
class RepositorySettings(Model):
"""
Stores (organization) repository specific settings.
"""

__relocation_scope__ = RelocationScope.Global

repository = FlexibleForeignKey(
"sentry.Repository", on_delete=models.CASCADE, unique=True, db_index=True
Copy link
Member

Choose a reason for hiding this comment

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

interesting, today I learned sentry.Repository should be capitalized here to match the model but lowercase in the migration above haha

Copy link
Member

Choose a reason for hiding this comment

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

Yeah django is funny like that.

)
enabled_code_review = models.BooleanField(default=False)
code_review_triggers = ArrayField(
models.CharField(max_length=32, choices=CodeReviewTrigger.as_choices()),
default=list,
)
Comment on lines +33 to +37
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense for enable_code_review to be on the Repository, and then have this table be

RepositorySetting
 - id
 - repository_id
 - trigger

unique (repository_id, trigger)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking keep it separate in the event we end up adding more repository settings, I think one thing that was brought up in the ecosystem office hours was some org setting that has been commonly asked for to also be a repository setting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is potentially something we can do w.r.t. having a single column where the presence of anything in the list means enabled and for what triggers, while an empty list could signal disabled, but I think that's a little less intuitive and relies on "triggers" being edible in the future too


class Meta:
app_label = "sentry"
db_table = "sentry_repositorysettings"

__repr__ = sane_repr("repository_id", "enabled_code_review")
10 changes: 10 additions & 0 deletions src/sentry/testutils/helpers/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
from sentry.models.projecttemplate import ProjectTemplate
from sentry.models.recentsearch import RecentSearch
from sentry.models.relay import Relay, RelayUsage
from sentry.models.repositorysettings import CodeReviewTrigger, RepositorySettings
from sentry.models.rule import NeglectedRule, RuleActivity, RuleActivityType
from sentry.models.savedsearch import SavedSearch, Visibility
from sentry.models.search_common import SearchType
Expand Down Expand Up @@ -639,6 +640,15 @@ def create_exhaustive_organization(
repo.external_id = "https://git.example.com:1234"
repo.save()

RepositorySettings.objects.create(
repository=repo,
enabled_code_review=True,
code_review_triggers=[
CodeReviewTrigger.ON_NEW_COMMIT,
CodeReviewTrigger.ON_READY_FOR_REVIEW,
],
)

# Group*
group = self.create_group(project=project)
group_search_view = GroupSearchView.objects.create(
Expand Down
Loading