-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: Create new repository settings table #104645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| ), | ||
| ), | ||
| ( | ||
| "repository", | ||
| sentry.db.models.fields.foreignkey.FlexibleForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| to="sentry.repository", | ||
| unique=True, | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "sentry_repositorysettings", | ||
| }, | ||
| ), | ||
| ] | ||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting, today I learned
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense for ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Repositoryhas aconfigjson 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 tosentry_repositorydirectly.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
sentry/src/sentry/models/repository.py
Line 43 in e87d194
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