-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: Create OrganizationContributors table in region dbs #103839
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
base: master
Are you sure you want to change the base?
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,72 @@ | ||
| # Generated by Django 5.2.8 on 2025-11-21 21:54 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
| import sentry.db.models.fields.bounded | ||
| import sentry.db.models.fields.foreignkey | ||
| import sentry.db.models.fields.hybrid_cloud_foreign_key | ||
| 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", "1007_cleanup_failed_safe_deletes"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="OrganizationContributors", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| sentry.db.models.fields.bounded.BoundedBigAutoField( | ||
| primary_key=True, serialize=False | ||
| ), | ||
| ), | ||
| ( | ||
| "integration_id", | ||
| sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey( | ||
| "sentry.Integration", db_index=True, on_delete="CASCADE" | ||
| ), | ||
| ), | ||
| ("external_identifier", models.CharField(db_index=True, max_length=255)), | ||
| ("alias", models.CharField(blank=True, max_length=255, null=True)), | ||
| ("num_actions", sentry.db.models.fields.bounded.BoundedIntegerField(default=0)), | ||
| ("date_added", models.DateTimeField(auto_now_add=True)), | ||
| ("date_updated", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "organization", | ||
| sentry.db.models.fields.foreignkey.FlexibleForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, to="sentry.organization" | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "sentry_organizationcontributors", | ||
| "indexes": [ | ||
| models.Index(fields=["date_updated"], name="sentry_orgcont_date_upd_idx") | ||
| ], | ||
| "constraints": [ | ||
| models.UniqueConstraint( | ||
| fields=("organization_id", "integration_id", "external_identifier"), | ||
| name="sentry_orgcont_unique_org_cont", | ||
| ) | ||
| ], | ||
| }, | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from django.db import models | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from sentry.backup.scopes import RelocationScope | ||||||||||||||||||||||||||||||
| from sentry.db.models import BoundedIntegerField, FlexibleForeignKey, Model, region_silo_model | ||||||||||||||||||||||||||||||
| from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @region_silo_model | ||||||||||||||||||||||||||||||
| class OrganizationContributors(Model): | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| Tracks external contributors and their activity for an organization. | ||||||||||||||||||||||||||||||
| This model stores information about contributors associated with an | ||||||||||||||||||||||||||||||
| integration for a specific organization, including their external identity | ||||||||||||||||||||||||||||||
| and how many actions they have taken. | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| __relocation_scope__ = RelocationScope.Excluded | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| organization = FlexibleForeignKey("sentry.Organization", on_delete=models.CASCADE) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| integration_id = HybridCloudForeignKey("sentry.Integration", on_delete="CASCADE") | ||||||||||||||||||||||||||||||
|
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. I just want to check here - is there any potential problem with allowing people to remove these rows by deleting their integration? Could they circumvent billing, or could it cause us problems in understanding billing?
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. No, they won't be able to circumvent billing as the seat should be created after their 2nd action. As for understanding billing, it should be no different than deleting a uptime detector. The only difference is that Seer seats can only be ASSIGNED (not disabled, removed, or reallocated). |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| external_identifier = models.CharField(max_length=255, db_index=True) | ||||||||||||||||||||||||||||||
| alias = models.CharField(max_length=255, null=True, blank=True) | ||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+26
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. Does it make sense to have an FK to this table instead of having these fields? sentry/src/sentry/models/commitauthor.py Lines 27 to 40 in 153511a
Or is the format there totally different? |
||||||||||||||||||||||||||||||
| num_actions = BoundedIntegerField(default=0) | ||||||||||||||||||||||||||||||
|
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. Should the default here be 1? From the spec, it seems like we'll only create these rows when a user has taken an action |
||||||||||||||||||||||||||||||
| date_added = models.DateTimeField(auto_now_add=True) | ||||||||||||||||||||||||||||||
| date_updated = models.DateTimeField(auto_now=True) | ||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+29
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. You can use |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class Meta: | ||||||||||||||||||||||||||||||
| app_label = "sentry" | ||||||||||||||||||||||||||||||
|
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. Is it worth considering whether this should be part of a separate module? Is this specific to prevent? |
||||||||||||||||||||||||||||||
| db_table = "sentry_organizationcontributors" | ||||||||||||||||||||||||||||||
| constraints = [ | ||||||||||||||||||||||||||||||
| models.UniqueConstraint( | ||||||||||||||||||||||||||||||
| fields=["organization_id", "integration_id", "external_identifier"], | ||||||||||||||||||||||||||||||
| name="sentry_orgcont_unique_org_cont", | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| indexes = [ | ||||||||||||||||||||||||||||||
| models.Index( | ||||||||||||||||||||||||||||||
| fields=["date_updated"], | ||||||||||||||||||||||||||||||
|
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. Is this just for handling retention deletes? |
||||||||||||||||||||||||||||||
| name="sentry_orgcont_date_upd_idx", | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.