Browse Source

fix(models): Upgraded Org/Project/any snowflake id related ids to bigints (#37815)

Richard Ma 2 years ago
parent
commit
0d6423071f

+ 1 - 1
migrations_lockfile.txt

@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0313_sentry_functions_env_variables
+sentry: 0314_bit_int_for_org_and_project_id
 social_auth: 0001_initial

+ 193 - 0
src/sentry/migrations/0314_bit_int_for_org_and_project_id.py

@@ -0,0 +1,193 @@
+# Generated by Django 2.2.28 on 2022-07-25 20:49
+
+from django.db import migrations
+
+import sentry.db.models.fields.bounded
+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. For
+    # the most part, 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 dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops 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
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+
+    # please don't preform database_operations as they already have been applied, they were added so the tests could run
+    is_dangerous = True
+
+    # This is set to false only as database_operations are going to be ignored by sentry saas. Please do not set checked
+    # to false if you plan to alter the database
+    checked = False
+
+    # This flag is used to decide whether to run this migration in a transaction or not. Generally
+    # we don't want to run in a transaction here, since for long running operations like data
+    # back-fills this results in us locking an increasing number of rows until we finally commit.
+    atomic = False
+
+    dependencies = [
+        ("sentry", "0313_sentry_functions_env_variables"),
+    ]
+
+    operations = (
+        migrations.AlterField(
+            model_name="auditlogentry",
+            name="target_object",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(null=True),
+        ),
+        migrations.AlterField(
+            model_name="commit",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="commitauthor",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="commitfilechange",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="deploy",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="distribution",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="environment",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(),
+        ),
+        migrations.AlterField(
+            model_name="environment",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(null=True),
+        ),
+        migrations.AlterField(
+            model_name="eventuser",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="grouprelease",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="monitor",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="monitor",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="monitorcheckin",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="promptsactivity",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="promptsactivity",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="pullrequest",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="release",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(null=True),
+        ),
+        migrations.AlterField(
+            model_name="releasecommit",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="releasecommit",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(null=True),
+        ),
+        migrations.AlterField(
+            model_name="releaseenvironment",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(null=True),
+        ),
+        migrations.AlterField(
+            model_name="releasefile",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(null=True),
+        ),
+        migrations.AlterField(
+            model_name="releaseheadcommit",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="repository",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="servicehook",
+            name="actor_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.AlterField(
+            model_name="servicehook",
+            name="organization_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True, null=True),
+        ),
+        migrations.AlterField(
+            model_name="servicehook",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True, null=True),
+        ),
+        migrations.AlterField(
+            model_name="servicehookproject",
+            name="project_id",
+            field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+        ),
+        migrations.RunSQL(
+            sql="ALTER TABLE sentry_externalissue ALTER COLUMN organization_id TYPE bigint",
+            hints={"tables": ["sentry_externalissue"]},
+            reverse_sql="ALTER TABLE sentry_externalissue ALTER COLUMN organization_id TYPE int",
+        ),
+        migrations.RunSQL(
+            sql="ALTER TABLE sentry_externalissue ALTER COLUMN integration_id TYPE bigint",
+            hints={"tables": ["sentry_externalissue"]},
+            reverse_sql="ALTER TABLE sentry_externalissue ALTER COLUMN integration_id TYPE int",
+        ),
+        migrations.RunSQL(
+            sql="ALTER TABLE sentry_dashboardproject ALTER COLUMN project_id TYPE bigint",
+            hints={"tables": ["sentry_dashboardproject"]},
+            reverse_sql="ALTER TABLE sentry_dashboardproject ALTER COLUMN project_id TYPE int",
+        ),
+        migrations.RunSQL(
+            sql="ALTER TABLE sentry_dashboardproject ALTER COLUMN dashboard_id TYPE bigint",
+            hints={"tables": ["sentry_dashboardproject"]},
+            reverse_sql="ALTER TABLE sentry_dashboardproject ALTER COLUMN dashboard_id TYPE int",
+        ),
+    )

+ 2 - 1
src/sentry/models/auditlogentry.py

@@ -2,6 +2,7 @@ from django.db import models
 from django.utils import timezone
 
 from sentry.db.models import (
+    BoundedBigIntegerField,
     BoundedPositiveIntegerField,
     FlexibleForeignKey,
     GzippedDictField,
@@ -23,7 +24,7 @@ class AuditLogEntry(Model):
     )
     # if the entry was created via an api key
     actor_key = FlexibleForeignKey("sentry.ApiKey", null=True, blank=True)
-    target_object = BoundedPositiveIntegerField(null=True)
+    target_object = BoundedBigIntegerField(null=True)
     target_user = FlexibleForeignKey(
         "sentry.User",
         null=True,

+ 2 - 1
src/sentry/models/commit.py

@@ -7,6 +7,7 @@ from django.utils import timezone
 
 from sentry.db.models import (
     BaseManager,
+    BoundedBigIntegerField,
     BoundedPositiveIntegerField,
     FlexibleForeignKey,
     Model,
@@ -32,7 +33,7 @@ class CommitManager(BaseManager):
 class Commit(Model):
     __include_in_export__ = False
 
-    organization_id = BoundedPositiveIntegerField(db_index=True)
+    organization_id = BoundedBigIntegerField(db_index=True)
     repository_id = BoundedPositiveIntegerField()
     key = models.CharField(max_length=64)
     date_added = models.DateTimeField(default=timezone.now)

+ 2 - 2
src/sentry/models/commitauthor.py

@@ -1,6 +1,6 @@
 from django.db import models
 
-from sentry.db.models import BoundedPositiveIntegerField, Model, sane_repr
+from sentry.db.models import BoundedBigIntegerField, Model, sane_repr
 from sentry.db.models.manager import BaseManager
 
 
@@ -17,7 +17,7 @@ class CommitAuthorManager(BaseManager):
 class CommitAuthor(Model):
     __include_in_export__ = False
 
-    organization_id = BoundedPositiveIntegerField(db_index=True)
+    organization_id = BoundedBigIntegerField(db_index=True)
     name = models.CharField(max_length=128, null=True)
     email = models.CharField(max_length=200)
     external_id = models.CharField(max_length=164, null=True)

+ 2 - 2
src/sentry/models/commitfilechange.py

@@ -5,7 +5,7 @@ from django.db.models.signals import post_save
 
 from sentry.db.models import (
     BaseManager,
-    BoundedPositiveIntegerField,
+    BoundedBigIntegerField,
     FlexibleForeignKey,
     Model,
     sane_repr,
@@ -22,7 +22,7 @@ class CommitFileChangeManager(BaseManager):
 class CommitFileChange(Model):
     __include_in_export__ = False
 
-    organization_id = BoundedPositiveIntegerField(db_index=True)
+    organization_id = BoundedBigIntegerField(db_index=True)
     commit = FlexibleForeignKey("sentry.Commit")
     filename = models.TextField()
     type = models.CharField(

+ 7 - 2
src/sentry/models/deploy.py

@@ -9,7 +9,12 @@ from django.utils import timezone
 
 from sentry import features
 from sentry.app import locks
-from sentry.db.models import BoundedPositiveIntegerField, FlexibleForeignKey, Model
+from sentry.db.models import (
+    BoundedBigIntegerField,
+    BoundedPositiveIntegerField,
+    FlexibleForeignKey,
+    Model,
+)
 from sentry.types.activity import ActivityType
 from sentry.types.releaseactivity import ReleaseActivityType
 from sentry.utils.retries import TimedRetryPolicy
@@ -18,7 +23,7 @@ from sentry.utils.retries import TimedRetryPolicy
 class Deploy(Model):
     __include_in_export__ = False
 
-    organization_id = BoundedPositiveIntegerField(db_index=True)
+    organization_id = BoundedBigIntegerField(db_index=True)
     release = FlexibleForeignKey("sentry.Release")
     environment_id = BoundedPositiveIntegerField(db_index=True)
     date_finished = models.DateTimeField(default=timezone.now, db_index=True)

+ 2 - 2
src/sentry/models/distribution.py

@@ -1,13 +1,13 @@
 from django.db import models
 from django.utils import timezone
 
-from sentry.db.models import BoundedPositiveIntegerField, FlexibleForeignKey, Model, sane_repr
+from sentry.db.models import BoundedBigIntegerField, FlexibleForeignKey, Model, sane_repr
 
 
 class Distribution(Model):
     __include_in_export__ = False
 
-    organization_id = BoundedPositiveIntegerField(db_index=True)
+    organization_id = BoundedBigIntegerField(db_index=True)
     release = FlexibleForeignKey("sentry.Release")
     name = models.CharField(max_length=64)
     date_added = models.DateTimeField(default=timezone.now)

+ 3 - 3
src/sentry/models/environment.py

@@ -4,7 +4,7 @@ from django.db import IntegrityError, models, transaction
 from django.utils import timezone
 
 from sentry.constants import ENVIRONMENT_NAME_MAX_LENGTH, ENVIRONMENT_NAME_PATTERN
-from sentry.db.models import BoundedPositiveIntegerField, FlexibleForeignKey, Model, sane_repr
+from sentry.db.models import BoundedBigIntegerField, FlexibleForeignKey, Model, sane_repr
 from sentry.utils import metrics
 from sentry.utils.cache import cache
 from sentry.utils.hashlib import md5_text
@@ -28,10 +28,10 @@ class EnvironmentProject(Model):
 class Environment(Model):
     __include_in_export__ = False
 
-    organization_id = BoundedPositiveIntegerField()
+    organization_id = BoundedBigIntegerField()
     projects = models.ManyToManyField("sentry.Project", through=EnvironmentProject)
     # DEPRECATED, use projects
-    project_id = BoundedPositiveIntegerField(null=True)
+    project_id = BoundedBigIntegerField(null=True)
     name = models.CharField(max_length=64)
     date_added = models.DateTimeField(default=timezone.now)
 

+ 2 - 2
src/sentry/models/eventuser.py

@@ -6,7 +6,7 @@ from django.db import models
 from django.utils import timezone
 
 from sentry.constants import MAX_EMAIL_FIELD_LENGTH
-from sentry.db.models import BoundedPositiveIntegerField, Model, sane_repr
+from sentry.db.models import BoundedBigIntegerField, Model, sane_repr
 from sentry.utils.datastructures import BidirectionalMapping
 from sentry.utils.hashlib import md5_text
 
@@ -23,7 +23,7 @@ KEYWORD_MAP = BidirectionalMapping(
 class EventUser(Model):
     __include_in_export__ = False
 
-    project_id = BoundedPositiveIntegerField(db_index=True)
+    project_id = BoundedBigIntegerField(db_index=True)
     hash = models.CharField(max_length=32)
     ident = models.CharField(max_length=128, null=True)
     email = models.EmailField(null=True, max_length=MAX_EMAIL_FIELD_LENGTH)

Some files were not shown because too many files changed in this diff