diff --git a/codecov_auth/migrations/0001_initial.py b/codecov_auth/migrations/0001_initial.py deleted file mode 100644 index 5318fbac90..0000000000 --- a/codecov_auth/migrations/0001_initial.py +++ /dev/null @@ -1,169 +0,0 @@ -# Generated by Django 3.1.6 on 2021-04-08 19:21 - -import datetime -import uuid - -import django.contrib.postgres.fields -import django.contrib.postgres.fields.citext -import django.db.models.deletion -from django.conf import settings # noqa: F401 -from django.contrib.postgres.operations import CITextExtension -from django.db import migrations, models - -import core.models - - -class Migration(migrations.Migration): - initial = True - - dependencies = [] - - operations = [ - CITextExtension(), - migrations.CreateModel( - name="User", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("email", django.contrib.postgres.fields.citext.CITextField(null=True)), - ("name", models.TextField(null=True)), - ("is_staff", models.BooleanField(default=False, null=True)), - ("is_superuser", models.BooleanField(default=False, null=True)), - ( - "external_id", - models.UUIDField(default=uuid.uuid4, editable=False, unique=True), - ), - ], - options={ - "db_table": "users", - }, - ), - migrations.CreateModel( - name="Owner", - fields=[ - ("ownerid", models.AutoField(primary_key=True, serialize=False)), - ( - "service", - models.TextField( - choices=[ - ("github", "Github"), - ("gitlab", "Gitlab"), - ("bitbucket", "Bitbucket"), - ("github_enterprise", "Github Enterprise"), - ("gitlab_enterprise", "Gitlab Enterprise"), - ("bitbucket_server", "Bitbucket Server"), - ] - ), - ), - ( - "username", - django.contrib.postgres.fields.citext.CITextField( - null=True, unique=True - ), - ), - ("email", models.TextField(null=True)), - ("name", models.TextField(null=True)), - ("oauth_token", models.TextField(null=True)), - ("stripe_customer_id", models.TextField(null=True)), - ("stripe_subscription_id", models.TextField(null=True)), - ("createstamp", models.DateTimeField(null=True)), - ("service_id", models.TextField()), - ("parent_service_id", models.TextField(null=True)), - ("root_parent_service_id", models.TextField(null=True)), - ("private_access", models.BooleanField(null=True)), - ("staff", models.BooleanField(default=False, null=True)), - ("cache", models.JSONField(null=True)), - ("plan", models.TextField(default="users-free", null=True)), - ("plan_provider", models.TextField(null=True)), - ("plan_user_count", models.SmallIntegerField(default=5, null=True)), - ("plan_auto_activate", models.BooleanField(default=True, null=True)), - ( - "plan_activated_users", - django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(null=True), null=True, size=None - ), - ), - ("did_trial", models.BooleanField(null=True)), - ("free", models.SmallIntegerField(default=0)), - ("invoice_details", models.TextField(null=True)), - ("delinquent", models.BooleanField(null=True)), - ("yaml", models.JSONField(null=True)), - ( - "updatestamp", - core.models.DateTimeWithoutTZField(default=datetime.datetime.now), - ), - ( - "organizations", - django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(null=True), null=True, size=None - ), - ), - ( - "admins", - django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(null=True), null=True, size=None - ), - ), - ("integration_id", models.IntegerField(null=True)), - ( - "permission", - django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(null=True), null=True, size=None - ), - ), - ("student", models.BooleanField(default=False)), - ("student_created_at", core.models.DateTimeWithoutTZField(null=True)), - ("student_updated_at", core.models.DateTimeWithoutTZField(null=True)), - ( - "bot", - models.ForeignKey( - db_column="bot", - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="codecov_auth.owner", - ), - ), - ], - options={"db_table": "owners", "ordering": ["ownerid"]}, - ), - migrations.CreateModel( - name="Session", - fields=[ - ("sessionid", models.AutoField(primary_key=True, serialize=False)), - ( - "token", - models.UUIDField(default=uuid.uuid4, editable=False, unique=True), - ), - ("name", models.TextField(null=True)), - ("useragent", models.TextField(null=True)), - ("ip", models.TextField(null=True)), - ("lastseen", models.DateTimeField(null=True)), - ( - "type", - models.TextField(choices=[("api", "Api"), ("login", "Login")]), - ), - ( - "owner", - models.ForeignKey( - db_column="ownerid", - on_delete=django.db.models.deletion.CASCADE, - to="codecov_auth.owner", - ), - ), - ], - options={"db_table": "sessions", "ordering": ["-lastseen"]}, - ), - migrations.AddConstraint( - model_name="owner", - constraint=models.UniqueConstraint( - fields=("service", "username"), name="owner_service_username" - ), - ), - migrations.AddConstraint( - model_name="owner", - constraint=models.UniqueConstraint( - fields=("service", "service_id"), name="owner_service_ids" - ), - ), - ] diff --git a/codecov_auth/migrations/0002_auto_20210817_1346.py b/codecov_auth/migrations/0002_auto_20210817_1346.py deleted file mode 100644 index 2f7d93e731..0000000000 --- a/codecov_auth/migrations/0002_auto_20210817_1346.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 3.1.6 on 2021-08-17 13:46 - -import uuid - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0004_pull_user_provided_base_sha"), - ("codecov_auth", "0001_initial"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="plan_provider", - field=models.TextField(choices=[("github", "Github")], null=True), - ), - migrations.CreateModel( - name="RepositoryToken", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("token_type", models.CharField(max_length=50)), - ("valid_until", models.DateTimeField(null=True)), - ("key", models.CharField(max_length=40, unique=True)), - ( - "repository", - models.ForeignKey( - db_column="repoid", - on_delete=django.db.models.deletion.CASCADE, - related_name="tokens", - to="core.repository", - ), - ), - ], - options={"abstract": False}, - ), - ] diff --git a/codecov_auth/migrations/0003_auto_20210924_1003.py b/codecov_auth/migrations/0003_auto_20210924_1003.py deleted file mode 100644 index 6328372ba6..0000000000 --- a/codecov_auth/migrations/0003_auto_20210924_1003.py +++ /dev/null @@ -1,71 +0,0 @@ -# Generated by Django 3.1.13 on 2021-09-24 10:03 - -import uuid - -import django.contrib.postgres.fields -import django.db.models.deletion -from django.conf import settings # noqa: F401 -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [("codecov_auth", "0002_auto_20210817_1346")] - - operations = [ - migrations.AddField( - model_name="owner", name="business_email", field=models.TextField(null=True) - ), - migrations.AddField( - model_name="owner", - name="onboarding_completed", - field=models.BooleanField(default=False), - ), - migrations.CreateModel( - name="OwnerProfile", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ( - "type_projects", - django.contrib.postgres.fields.ArrayField( - base_field=models.TextField( - choices=[ - ("PERSONAL", "Personal"), - ("YOUR_ORG", "Your Org"), - ("OPEN_SOURCE", "Open Source"), - ("EDUCATIONAL", "Educational"), - ] - ), - default=list, - size=None, - ), - ), - ( - "goals", - django.contrib.postgres.fields.ArrayField( - base_field=models.TextField( - choices=[ - ("STARTING_WITH_TESTS", "Starting With Tests"), - ("IMPROVE_COVERAGE", "Improve Coverage"), - ("MAINTAIN_COVERAGE", "Maintain Coverage"), - ("OTHER", "Other"), - ] - ), - default=list, - size=None, - ), - ), - ("other_goal", models.TextField(null=True)), - ( - "owner", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to="codecov_auth.owner", - ), - ), - ], - options={"abstract": False}, - ), - ] diff --git a/codecov_auth/migrations/0004_auto_20210930_1429.py b/codecov_auth/migrations/0004_auto_20210930_1429.py deleted file mode 100644 index 566668d5e7..0000000000 --- a/codecov_auth/migrations/0004_auto_20210930_1429.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.1.13 on 2021-09-30 14:29 - -import django.contrib.postgres.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [("codecov_auth", "0003_auto_20210924_1003")] - - operations = [ - migrations.AlterField( - model_name="ownerprofile", - name="goals", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.TextField( - choices=[ - ("STARTING_WITH_TESTS", "Starting With Tests"), - ("IMPROVE_COVERAGE", "Improve Coverage"), - ("MAINTAIN_COVERAGE", "Maintain Coverage"), - ("TEAM_REQUIREMENTS", "Team Requirements"), - ("OTHER", "Other"), - ] - ), - default=list, - size=None, - ), - ) - ] diff --git a/codecov_auth/migrations/0005_auto_20211029_1709.py b/codecov_auth/migrations/0005_auto_20211029_1709.py deleted file mode 100644 index 3e496e9f96..0000000000 --- a/codecov_auth/migrations/0005_auto_20211029_1709.py +++ /dev/null @@ -1,13 +0,0 @@ -# Generated by Django 3.1.13 on 2021-10-29 17:09 - -from django.db import migrations - - -class Migration(migrations.Migration): - atomic = False - - dependencies = [("codecov_auth", "0004_auto_20210930_1429")] - - operations = [ - migrations.RunSQL("ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-basic';") - ] diff --git a/codecov_auth/migrations/0006_auto_20211123_1535.py b/codecov_auth/migrations/0006_auto_20211123_1535.py deleted file mode 100644 index d53dbc6769..0000000000 --- a/codecov_auth/migrations/0006_auto_20211123_1535.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 3.1.13 on 2021-11-23 15:35 - -import django.db.models.deletion -from django.conf import settings # noqa: F401 -from django.db import migrations, models - -import codecov_auth.models - - -class Migration(migrations.Migration): - dependencies = [("codecov_auth", "0005_auto_20211029_1709")] - - operations = [ - migrations.AlterField( - model_name="owner", - name="plan", - field=models.TextField(default="users-basic", null=True), - ), - migrations.AlterField( - model_name="ownerprofile", - name="owner", - field=models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - related_name="profile", - to="codecov_auth.owner", - ), - ), - migrations.AlterField( - model_name="repositorytoken", - name="key", - field=models.CharField( - default=codecov_auth.models._generate_key, - editable=False, - max_length=40, - unique=True, - ), - ), - migrations.AlterField( - model_name="repositorytoken", - name="valid_until", - field=models.DateTimeField(blank=True, null=True), - ), - ] diff --git a/codecov_auth/migrations/0007_auto_20211129_1228.py b/codecov_auth/migrations/0007_auto_20211129_1228.py deleted file mode 100644 index 1df753536f..0000000000 --- a/codecov_auth/migrations/0007_auto_20211129_1228.py +++ /dev/null @@ -1,13 +0,0 @@ -# Generated by Django 3.1.13 on 2021-11-29 12:28 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [("codecov_auth", "0006_auto_20211123_1535")] - - operations = [ - migrations.RunSQL( - "ALTER TABLE owners ALTER COLUMN plan SET DEFAULT 'users-basic';" - ) - ] diff --git a/codecov_auth/migrations/0008_auto_20220119_1811.py b/codecov_auth/migrations/0008_auto_20220119_1811.py deleted file mode 100644 index c11fb67268..0000000000 --- a/codecov_auth/migrations/0008_auto_20220119_1811.py +++ /dev/null @@ -1,13 +0,0 @@ -# Generated by Django 3.1.13 on 2022-01-19 18:11 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [("codecov_auth", "0007_auto_20211129_1228")] - - operations = [ - migrations.RunSQL( - "ALTER TABLE owners ALTER COLUMN onboarding_completed SET DEFAULT FALSE;" - ) - ] diff --git a/codecov_auth/migrations/0009_auto_20220511_1313.py b/codecov_auth/migrations/0009_auto_20220511_1313.py deleted file mode 100644 index 5f63bca6a1..0000000000 --- a/codecov_auth/migrations/0009_auto_20220511_1313.py +++ /dev/null @@ -1,76 +0,0 @@ -# Generated by Django 3.1.13 on 2022-05-11 13:13 - -import django.contrib.postgres.fields -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0008_auto_20220119_1811"), - ] - - operations = [ - migrations.RunSQL( - """-- - -- Alter field bot on Owner - -- - COMMIT; - """, - state_operations=[ - migrations.AlterField( - model_name="owner", - name="bot", - field=models.ForeignKey( - blank=True, - db_column="bot", - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="codecov_auth.owner", - ), - ), - ], - ), - migrations.AlterField( - model_name="owner", - name="integration_id", - field=models.IntegerField(blank=True, null=True), - ), - migrations.AlterField( - model_name="owner", - name="plan", - field=models.TextField(blank=True, default="users-basic", null=True), - ), - migrations.AlterField( - model_name="owner", - name="plan_activated_users", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(null=True), - blank=True, - null=True, - size=None, - ), - ), - migrations.AlterField( - model_name="owner", - name="plan_provider", - field=models.TextField( - blank=True, choices=[("github", "Github")], null=True - ), - ), - migrations.AlterField( - model_name="owner", - name="plan_user_count", - field=models.SmallIntegerField(blank=True, default=5, null=True), - ), - migrations.AlterField( - model_name="owner", - name="stripe_customer_id", - field=models.TextField(blank=True, null=True), - ), - migrations.AlterField( - model_name="owner", - name="stripe_subscription_id", - field=models.TextField(blank=True, null=True), - ), - ] diff --git a/codecov_auth/migrations/0010_owner_is_superuser.py b/codecov_auth/migrations/0010_owner_is_superuser.py deleted file mode 100644 index ad85c08ae5..0000000000 --- a/codecov_auth/migrations/0010_owner_is_superuser.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.13 on 2022-05-24 16:35 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0009_auto_20220511_1313"), - ] - - operations = [ - migrations.AddField( - model_name="owner", - name="is_superuser", - field=models.BooleanField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0011_new_enterprise_plans.py b/codecov_auth/migrations/0011_new_enterprise_plans.py deleted file mode 100644 index af6836d471..0000000000 --- a/codecov_auth/migrations/0011_new_enterprise_plans.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.2.12 on 2022-05-09 14:00 - -from django.db import migrations - - -class Migration(migrations.Migration): - atomic = False - - dependencies = [ - ("codecov_auth", "0010_owner_is_superuser"), - ] - - operations = [ - migrations.RunSQL( - "ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-enterprisey';" - ), - migrations.RunSQL( - "ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-enterprisem';" - ), - ] diff --git a/codecov_auth/migrations/0012_auto_20220531_1452.py b/codecov_auth/migrations/0012_auto_20220531_1452.py deleted file mode 100644 index 26828385fd..0000000000 --- a/codecov_auth/migrations/0012_auto_20220531_1452.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.13 on 2022-05-31 14:52 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0011_new_enterprise_plans"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="is_superuser", - field=models.BooleanField(default=False, null=True), - ), - ] diff --git a/codecov_auth/migrations/0013_alter_owner_organizations.py b/codecov_auth/migrations/0013_alter_owner_organizations.py deleted file mode 100644 index 19f02eecb9..0000000000 --- a/codecov_auth/migrations/0013_alter_owner_organizations.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.2.12 on 2022-06-22 12:05 - -import django.contrib.postgres.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0012_auto_20220531_1452"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="organizations", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(null=True), - blank=True, - null=True, - size=None, - ), - ), - ] diff --git a/codecov_auth/migrations/0014_alter_repositorytoken_token_type.py b/codecov_auth/migrations/0014_alter_repositorytoken_token_type.py deleted file mode 100644 index 28204b6cd9..0000000000 --- a/codecov_auth/migrations/0014_alter_repositorytoken_token_type.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.2.12 on 2022-08-16 17:37 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0013_alter_owner_organizations"), - ] - - operations = [ - migrations.AlterField( - model_name="repositorytoken", - name="token_type", - field=models.CharField( - choices=[("upload", "Upload"), ("profiling", "Profiling")], - max_length=50, - ), - ), - ] diff --git a/codecov_auth/migrations/0015_organizationleveltoken.py b/codecov_auth/migrations/0015_organizationleveltoken.py deleted file mode 100644 index 5fe0a0c7bc..0000000000 --- a/codecov_auth/migrations/0015_organizationleveltoken.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 3.2.12 on 2022-08-17 18:35 - -import uuid - -import django.db.models.deletion -from django.conf import settings # noqa: F401 -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0014_alter_repositorytoken_token_type"), - ] - - operations = [ - migrations.CreateModel( - name="OrganizationLevelToken", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("token", models.UUIDField(default=uuid.uuid4, unique=True)), - ("valid_until", models.DateTimeField(blank=True, null=True)), - ( - "token_type", - models.CharField(choices=[("upload", "Upload")], max_length=50), - ), - ( - "owner", - models.ForeignKey( - db_column="ownerid", - on_delete=django.db.models.deletion.CASCADE, - related_name="organization_tokens", - to="codecov_auth.owner", - ), - ), - ], - options={ - "abstract": False, - }, - ), - ] diff --git a/codecov_auth/migrations/0016_alter_owner_admins.py b/codecov_auth/migrations/0016_alter_owner_admins.py deleted file mode 100644 index c9763bf2b2..0000000000 --- a/codecov_auth/migrations/0016_alter_owner_admins.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.2.12 on 2022-08-22 09:43 - -import django.contrib.postgres.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0015_organizationleveltoken"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="admins", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(null=True), - blank=True, - null=True, - size=None, - ), - ), - ] diff --git a/codecov_auth/migrations/0017_alter_organizationleveltoken_token_type.py b/codecov_auth/migrations/0017_alter_organizationleveltoken_token_type.py deleted file mode 100644 index 2aa73b0c00..0000000000 --- a/codecov_auth/migrations/0017_alter_organizationleveltoken_token_type.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.2.12 on 2022-08-19 14:30 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0016_alter_owner_admins"), - ] - - operations = [ - migrations.AlterField( - model_name="organizationleveltoken", - name="token_type", - field=models.CharField( - choices=[("upload", "Upload")], default="upload", max_length=50 - ), - ), - ] diff --git a/codecov_auth/migrations/0018_usertoken.py b/codecov_auth/migrations/0018_usertoken.py deleted file mode 100644 index 7178dc8414..0000000000 --- a/codecov_auth/migrations/0018_usertoken.py +++ /dev/null @@ -1,46 +0,0 @@ -# Generated by Django 3.2.12 on 2022-09-07 17:38 - -import uuid - -import django.db.models.deletion -from django.conf import settings # noqa: F401 -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0017_alter_organizationleveltoken_token_type"), - ] - - operations = [ - migrations.CreateModel( - name="UserToken", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("name", models.CharField(max_length=100)), - ("token", models.UUIDField(default=uuid.uuid4, unique=True)), - ("valid_until", models.DateTimeField(blank=True, null=True)), - ( - "token_type", - models.CharField( - choices=[("api", "Api")], default="api", max_length=50 - ), - ), - ( - "owner", - models.ForeignKey( - db_column="ownerid", - on_delete=django.db.models.deletion.CASCADE, - related_name="user_tokens", - to="codecov_auth.owner", - ), - ), - ], - options={ - "abstract": False, - }, - ), - ] diff --git a/codecov_auth/migrations/0019_alter_repositorytoken_token_type.py b/codecov_auth/migrations/0019_alter_repositorytoken_token_type.py deleted file mode 100644 index 8190d81720..0000000000 --- a/codecov_auth/migrations/0019_alter_repositorytoken_token_type.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.2.12 on 2022-12-06 04:19 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0018_usertoken"), - ] - - operations = [ - migrations.AlterField( - model_name="repositorytoken", - name="token_type", - field=models.CharField( - choices=[ - ("upload", "Upload"), - ("profiling", "Profiling"), - ("static_analysis", "Static Analysis"), - ], - max_length=50, - ), - ), - ] diff --git a/codecov_auth/migrations/0020_ownerprofile_default_org.py b/codecov_auth/migrations/0020_ownerprofile_default_org.py deleted file mode 100644 index de9fdb881e..0000000000 --- a/codecov_auth/migrations/0020_ownerprofile_default_org.py +++ /dev/null @@ -1,32 +0,0 @@ -# Generated by Django 3.2.12 on 2023-01-19 19:06 - -import django.db.models.deletion -from django.conf import settings # noqa: F401 -from django.db import migrations, models - - -class Migration(migrations.Migration): - # BEGIN; - # -- - # -- Add field default_org to ownerprofile - # -- - # ALTER TABLE "codecov_auth_ownerprofile" ADD COLUMN "default_org_id" integer NULL CONSTRAINT "codecov_auth_ownerpr_default_org_id_da545ea8_fk_owners_ow" REFERENCES "owners"("ownerid") DEFERRABLE INITIALLY DEFERRED; SET CONSTRAINTS "codecov_auth_ownerpr_default_org_id_da545ea8_fk_owners_ow" IMMEDIATE; - # CREATE INDEX "codecov_auth_ownerprofile_default_org_id_da545ea8" ON "codecov_auth_ownerprofile" ("default_org_id"); - # COMMIT; - - dependencies = [ - ("codecov_auth", "0019_alter_repositorytoken_token_type"), - ] - - operations = [ - migrations.AddField( - model_name="ownerprofile", - name="default_org", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="profiles_with_default", - to="codecov_auth.owner", - ), - ), - ] diff --git a/codecov_auth/migrations/0021_owner_max_upload_limit.py b/codecov_auth/migrations/0021_owner_max_upload_limit.py deleted file mode 100644 index c6ce8eaabf..0000000000 --- a/codecov_auth/migrations/0021_owner_max_upload_limit.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-13 19:56 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0020_ownerprofile_default_org"), - ] - - operations = [ - migrations.AddField( - model_name="owner", - name="max_upload_limit", - field=models.IntegerField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0022_alter_owner_max_upload_limit.py b/codecov_auth/migrations/0022_alter_owner_max_upload_limit.py deleted file mode 100644 index f6a494e1aa..0000000000 --- a/codecov_auth/migrations/0022_alter_owner_max_upload_limit.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-13 20:12 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0021_owner_max_upload_limit"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="max_upload_limit", - field=models.IntegerField(default=150, null=True), - ), - ] diff --git a/codecov_auth/migrations/0023_auto_20230214_1129.py b/codecov_auth/migrations/0023_auto_20230214_1129.py deleted file mode 100644 index 9dbdb76676..0000000000 --- a/codecov_auth/migrations/0023_auto_20230214_1129.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-14 11:29 - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0022_alter_owner_max_upload_limit"), - ] - - operations = [ - migrations.RunSQL( - "ALTER TABLE owners ALTER COLUMN max_upload_limit SET DEFAULT 150;" - ), - RiskyRunSQL( - "UPDATE owners SET max_upload_limit=150 WHERE max_upload_limit is null;" - ), - ] diff --git a/codecov_auth/migrations/0024_alter_owner_max_upload_limit.py b/codecov_auth/migrations/0024_alter_owner_max_upload_limit.py deleted file mode 100644 index fe960ef400..0000000000 --- a/codecov_auth/migrations/0024_alter_owner_max_upload_limit.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-23 11:44 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0023_auto_20230214_1129"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="max_upload_limit", - field=models.IntegerField(blank=True, default=150, null=True), - ), - ] diff --git a/codecov_auth/migrations/0025_owner_stripe_coupon_id.py b/codecov_auth/migrations/0025_owner_stripe_coupon_id.py deleted file mode 100644 index c60a2606ff..0000000000 --- a/codecov_auth/migrations/0025_owner_stripe_coupon_id.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-22 19:50 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field stripe_coupon_id to owner - -- - ALTER TABLE "owners" ADD COLUMN "stripe_coupon_id" text NULL; - COMMIT; - """ - - dependencies = [ - ("codecov_auth", "0024_alter_owner_max_upload_limit"), - ] - - operations = [ - migrations.AddField( - model_name="owner", - name="stripe_coupon_id", - field=models.TextField(blank=True, null=True), - ), - ] diff --git a/codecov_auth/migrations/0026_alter_owner_plan_user_count.py b/codecov_auth/migrations/0026_alter_owner_plan_user_count.py deleted file mode 100644 index 1c49b2586a..0000000000 --- a/codecov_auth/migrations/0026_alter_owner_plan_user_count.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.1.7 on 2023-03-09 20:55 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0025_owner_stripe_coupon_id"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="plan_user_count", - field=models.SmallIntegerField(blank=True, default=1, null=True), - ), - ] diff --git a/codecov_auth/migrations/0027_auto_20230307_1751.py b/codecov_auth/migrations/0027_auto_20230307_1751.py deleted file mode 100644 index f69089b05a..0000000000 --- a/codecov_auth/migrations/0027_auto_20230307_1751.py +++ /dev/null @@ -1,14 +0,0 @@ -# Generated by Django 4.1.7 on 2023-03-07 17:51 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0026_alter_owner_plan_user_count"), - ] - - operations = [ - migrations.RunSQL("ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-sentrym';"), - migrations.RunSQL("ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-sentryy';"), - ] diff --git a/codecov_auth/migrations/0028_owner_sentry_user_data_owner_sentry_user_id.py b/codecov_auth/migrations/0028_owner_sentry_user_data_owner_sentry_user_id.py deleted file mode 100644 index 3d13a5379d..0000000000 --- a/codecov_auth/migrations/0028_owner_sentry_user_data_owner_sentry_user_id.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.1.7 on 2023-03-07 22:04 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0027_auto_20230307_1751"), - ] - - operations = [ - migrations.AddField( - model_name="owner", - name="sentry_user_data", - field=models.JSONField(null=True), - ), - migrations.AddField( - model_name="owner", - name="sentry_user_id", - field=models.TextField(blank=True, null=True, unique=True), - ), - ] diff --git a/codecov_auth/migrations/0029_ownerprofile_terms_agreement_and_more.py b/codecov_auth/migrations/0029_ownerprofile_terms_agreement_and_more.py deleted file mode 100644 index 75b3a5efce..0000000000 --- a/codecov_auth/migrations/0029_ownerprofile_terms_agreement_and_more.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.1.7 on 2023-03-17 22:01 - -from django.db import migrations, models - -import core.models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0028_owner_sentry_user_data_owner_sentry_user_id"), - ] - - operations = [ - migrations.AddField( - model_name="ownerprofile", - name="terms_agreement", - field=models.BooleanField(null=True), - ), - migrations.AddField( - model_name="ownerprofile", - name="terms_agreement_at", - field=core.models.DateTimeWithoutTZField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0030_owner_trial_end_date_owner_trial_start_date.py b/codecov_auth/migrations/0030_owner_trial_end_date_owner_trial_start_date.py deleted file mode 100644 index 003dbc6348..0000000000 --- a/codecov_auth/migrations/0030_owner_trial_end_date_owner_trial_start_date.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.1.7 on 2023-06-20 17:14 - -from django.db import migrations - -import core.models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0029_ownerprofile_terms_agreement_and_more"), - ] - - operations = [ - migrations.AddField( - model_name="owner", - name="trial_end_date", - field=core.models.DateTimeWithoutTZField(null=True), - ), - migrations.AddField( - model_name="owner", - name="trial_start_date", - field=core.models.DateTimeWithoutTZField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0031_user_owner_user.py b/codecov_auth/migrations/0031_user_owner_user.py deleted file mode 100644 index e80b4c91cc..0000000000 --- a/codecov_auth/migrations/0031_user_owner_user.py +++ /dev/null @@ -1,67 +0,0 @@ -# Generated by Django 4.1.7 on 2023-05-22 17:53 - - -import django.contrib.postgres.fields.citext -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0030_owner_trial_end_date_owner_trial_start_date"), - ] - - operations = [ - # NOTE: this migration had to be moved to the `0001_initial` migration - # since there are internal Django migrations that need to refer to this - # model via AUTH_USER_MODEL. - # It is not actually applied there since our `legacy_migrations` override - # the `migrate` command and mark 0001_initial migrations as fake. The - # raw SQL to create this table is in `legacy_migrations` and needs to be applied - # manually before running this migration. We have a raw SQL migration below to - # create the table if it does not already exist. - # - # migrations.CreateModel( - # name='User', - # fields=[ - # ('id', models.BigAutoField(primary_key=True, serialize=False)), - # ('created_at', models.DateTimeField(auto_now_add=True)), - # ('updated_at', models.DateTimeField(auto_now=True)), - # ('email', django.contrib.postgres.fields.citext.CITextField(null=True)), - # ('name', models.TextField(null=True)), - # ('is_staff', models.BooleanField(default=False, null=True)), - # ('is_superuser', models.BooleanField(default=False, null=True)), - # ('external_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)), - # ], - # options={ - # 'db_table': 'users', - # }, - # ), - migrations.RunSQL( - """ - CREATE TABLE IF NOT EXISTS "users" ( - "id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, - "external_id" uuid NOT NULL UNIQUE, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "email" citext NULL, - "name" text NULL, - "is_staff" boolean NULL, - "is_superuser" boolean NULL - ); - """, - reverse_sql="DROP TABLE users", - ), - migrations.AddField( - model_name="owner", - name="user", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="owners", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/codecov_auth/migrations/0032_owner_trial_status.py b/codecov_auth/migrations/0032_owner_trial_status.py deleted file mode 100644 index 8f9d485a11..0000000000 --- a/codecov_auth/migrations/0032_owner_trial_status.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 4.1.7 on 2023-07-20 00:28 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0031_user_owner_user"), - ] - - operations = [ - migrations.RunSQL("ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-trial';"), - migrations.AddField( - model_name="owner", - name="trial_status", - field=models.CharField( - choices=[ - ("not_started", "Not Started"), - ("ongoing", "Ongoing"), - ("expired", "Expired"), - ("cannot_trial", "Cannot Trial"), - ], - max_length=50, - null=True, - ), - ), - ] diff --git a/codecov_auth/migrations/0033_sentryuser.py b/codecov_auth/migrations/0033_sentryuser.py deleted file mode 100644 index 6ac44a00cb..0000000000 --- a/codecov_auth/migrations/0033_sentryuser.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-06 16:05 - -import uuid - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0032_owner_trial_status"), - ] - - operations = [ - migrations.CreateModel( - name="SentryUser", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("access_token", models.TextField(null=True)), - ("refresh_token", models.TextField(null=True)), - ("sentry_id", models.TextField(unique=True)), - ("email", models.TextField(null=True)), - ("name", models.TextField(null=True)), - ( - "user", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="sentry_user", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - options={ - "abstract": False, - }, - ), - ] diff --git a/codecov_auth/migrations/0034_alter_owner_trial_status.py b/codecov_auth/migrations/0034_alter_owner_trial_status.py deleted file mode 100644 index 28d842f7a3..0000000000 --- a/codecov_auth/migrations/0034_alter_owner_trial_status.py +++ /dev/null @@ -1,40 +0,0 @@ -# Generated by Django 4.1.7 on 2023-07-27 00:38 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Alter field trial_status on owner - -- - -- (no-op) - COMMIT; - """ - - dependencies = [ - ("codecov_auth", "0033_sentryuser"), - ] - - operations = [ - migrations.AlterField( - model_name="owner", - name="trial_status", - field=models.CharField( - choices=[ - ("not_started", "Not Started"), - ("ongoing", "Ongoing"), - ("expired", "Expired"), - ("cannot_trial", "Cannot Trial"), - ], - default="not_started", - max_length=50, - null=True, - ), - ), - RiskyRunSQL( - "alter table owners alter column trial_status set default 'not_started';" - ), - ] diff --git a/codecov_auth/migrations/0035_owner_pretrial_users_count.py b/codecov_auth/migrations/0035_owner_pretrial_users_count.py deleted file mode 100644 index 692e913904..0000000000 --- a/codecov_auth/migrations/0035_owner_pretrial_users_count.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 4.1.7 on 2023-07-27 23:40 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddField - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field pretrial_users_count to owner - -- - ALTER TABLE "owners" ADD COLUMN "pretrial_users_count" smallint NULL; - COMMIT; - """ - - dependencies = [ - ("codecov_auth", "0034_alter_owner_trial_status"), - ] - - operations = [ - RiskyAddField( - model_name="owner", - name="pretrial_users_count", - field=models.SmallIntegerField(blank=True, null=True), - ), - ] diff --git a/codecov_auth/migrations/0036_add_user_terms_agreement.py b/codecov_auth/migrations/0036_add_user_terms_agreement.py deleted file mode 100644 index b8f4527b0d..0000000000 --- a/codecov_auth/migrations/0036_add_user_terms_agreement.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 4.2.2 on 2023-08-30 13:27 - -from django.db import migrations, models - -import core.models - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field terms_agreement to user - -- - ALTER TABLE "users" ADD COLUMN "terms_agreement" boolean NULL; - -- - -- Add field terms_agreement_at to user - -- - ALTER TABLE "users" ADD COLUMN "terms_agreement_at" timestamp NULL; - COMMIT; - """ - - dependencies = [ - ("codecov_auth", "0035_owner_pretrial_users_count"), - ] - - operations = [ - migrations.AddField( - model_name="user", - name="terms_agreement", - field=models.BooleanField(null=True), - ), - migrations.AddField( - model_name="user", - name="terms_agreement_at", - field=core.models.DateTimeWithoutTZField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0037_owner_uses_invoice.py b/codecov_auth/migrations/0037_owner_uses_invoice.py deleted file mode 100644 index 068906645e..0000000000 --- a/codecov_auth/migrations/0037_owner_uses_invoice.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.2 on 2023-08-17 20:59 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddField - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0036_add_user_terms_agreement"), - ] - - operations = [ - RiskyAddField( - model_name="owner", - name="uses_invoice", - field=models.BooleanField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0038_alter_owner_uses_invoice.py b/codecov_auth/migrations/0038_alter_owner_uses_invoice.py deleted file mode 100644 index d9f32e1077..0000000000 --- a/codecov_auth/migrations/0038_alter_owner_uses_invoice.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.2.2 on 2023-08-28 18:27 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAlterField, RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0037_owner_uses_invoice"), - ] - - operations = [ - RiskyAlterField( - model_name="owner", - name="uses_invoice", - field=models.BooleanField(default=False, null=True), - ), - RiskyRunSQL( - """ - UPDATE "owners" SET "uses_invoice" = false WHERE "uses_invoice" IS NULL; - ALTER TABLE "owners" ALTER COLUMN "uses_invoice" SET DEFAULT false; - """ - ), - ] diff --git a/codecov_auth/migrations/0039_alter_owner_uses_invoice.py b/codecov_auth/migrations/0039_alter_owner_uses_invoice.py deleted file mode 100644 index 484f577a72..0000000000 --- a/codecov_auth/migrations/0039_alter_owner_uses_invoice.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.2 on 2023-08-28 17:42 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAlterField - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0038_alter_owner_uses_invoice"), - ] - - operations = [ - RiskyAlterField( - model_name="owner", - name="uses_invoice", - field=models.BooleanField(default=False, null=False), - ), - ] diff --git a/codecov_auth/migrations/0040_oktauser.py b/codecov_auth/migrations/0040_oktauser.py deleted file mode 100644 index 2d1b8e051c..0000000000 --- a/codecov_auth/migrations/0040_oktauser.py +++ /dev/null @@ -1,40 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-25 18:08 - -import uuid - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0039_alter_owner_uses_invoice"), - ] - - operations = [ - migrations.CreateModel( - name="OktaUser", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("access_token", models.TextField(null=True)), - ("okta_id", models.TextField(unique=True)), - ("email", models.TextField(null=True)), - ("name", models.TextField(null=True)), - ( - "user", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="okta_user", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - options={ - "abstract": False, - }, - ), - ] diff --git a/codecov_auth/migrations/0041_auto_20230918_1825.py b/codecov_auth/migrations/0041_auto_20230918_1825.py deleted file mode 100644 index cfd30b7ab2..0000000000 --- a/codecov_auth/migrations/0041_auto_20230918_1825.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 4.2.2 on 2023-09-18 18:25 - -from django.db import migrations - - -class Migration(migrations.Migration): - # BEGIN; - # -- - # -- Raw SQL operation - # -- - # ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-litem'; - # -- - # -- Raw SQL operation - # -- - # ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-litey'; - # COMMIT; - - dependencies = [ - ("codecov_auth", "0040_oktauser"), - ] - - operations = [ - migrations.RunSQL("ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-litem';"), - migrations.RunSQL("ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-litey';"), - ] diff --git a/codecov_auth/migrations/0042_owner_trial_fired_by.py b/codecov_auth/migrations/0042_owner_trial_fired_by.py deleted file mode 100644 index caa927264e..0000000000 --- a/codecov_auth/migrations/0042_owner_trial_fired_by.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.2.3 on 2023-09-19 09:28 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0041_auto_20230918_1825"), - ] - - operations = [ - migrations.AddField( - model_name="owner", - name="trial_fired_by", - field=models.IntegerField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0043_sync_user_terms_agreement.py b/codecov_auth/migrations/0043_sync_user_terms_agreement.py deleted file mode 100644 index f4694abd6e..0000000000 --- a/codecov_auth/migrations/0043_sync_user_terms_agreement.py +++ /dev/null @@ -1,33 +0,0 @@ -# Generated by Django 4.2.2 on 2023-09-18 14:51 - - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0042_owner_trial_fired_by"), - ] - - operations = [ - RiskyRunSQL( - sql=""" - UPDATE users - SET - terms_agreement = subquery.terms_agreement, - terms_agreement_at = subquery.terms_agreement_at - FROM ( - SELECT - owners.user_id, - codecov_auth_ownerprofile.terms_agreement, - codecov_auth_ownerprofile.terms_agreement_at - FROM owners - INNER JOIN codecov_auth_ownerprofile - ON codecov_auth_ownerprofile.owner_id = owners.ownerid - ) subquery - WHERE subquery.user_id = users.id; - """, - reverse_sql=migrations.RunSQL.noop, - ) - ] diff --git a/codecov_auth/migrations/0044_remove_owner_agreements_and_alter_user_agreements.py b/codecov_auth/migrations/0044_remove_owner_agreements_and_alter_user_agreements.py deleted file mode 100644 index 0aa617927f..0000000000 --- a/codecov_auth/migrations/0044_remove_owner_agreements_and_alter_user_agreements.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.2.3 on 2023-09-19 20:52 - -from django.db import migrations, models - -import core.models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0043_sync_user_terms_agreement"), - ] - - operations = [ - migrations.AlterField( - model_name="user", - name="terms_agreement", - field=models.BooleanField(blank=True, default=False, null=True), - ), - migrations.AlterField( - model_name="user", - name="terms_agreement_at", - field=core.models.DateTimeWithoutTZField(blank=True, null=True), - ), - ] diff --git a/codecov_auth/migrations/0045_remove_ownerprofile_terms_agreement.py b/codecov_auth/migrations/0045_remove_ownerprofile_terms_agreement.py deleted file mode 100644 index 37b8b231d7..0000000000 --- a/codecov_auth/migrations/0045_remove_ownerprofile_terms_agreement.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 4.2.3 on 2023-09-21 14:24 - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRemoveField - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Remove field terms_agreement from ownerprofile - -- - ALTER TABLE "codecov_auth_ownerprofile" DROP COLUMN "terms_agreement" CASCADE; - -- - -- Remove field terms_agreement_at from ownerprofile - -- - ALTER TABLE "codecov_auth_ownerprofile" DROP COLUMN "terms_agreement_at" CASCADE; - COMMIT; - """ - - dependencies = [ - ("codecov_auth", "0044_remove_owner_agreements_and_alter_user_agreements"), - ] - - operations = [ - RiskyRemoveField( - model_name="ownerprofile", - name="terms_agreement", - ), - RiskyRemoveField( - model_name="ownerprofile", - name="terms_agreement_at", - ), - ] diff --git a/codecov_auth/migrations/0046_dedupe_owner_admin_values.py b/codecov_auth/migrations/0046_dedupe_owner_admin_values.py deleted file mode 100644 index 1a7b0691c5..0000000000 --- a/codecov_auth/migrations/0046_dedupe_owner_admin_values.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 4.2.3 on 2023-09-19 19:48 - - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0045_remove_ownerprofile_terms_agreement"), - ] - - operations = [ - RiskyRunSQL( - sql=""" - UPDATE owners - SET admins = ARRAY ( - SELECT v - FROM unnest(admins) WITH ORDINALITY t(v,ord) - GROUP BY 1 - ORDER BY min(ord) - ); - """, - reverse_sql=migrations.RunSQL.noop, - ) - ] diff --git a/codecov_auth/migrations/0047_auto_20231009_1257.py b/codecov_auth/migrations/0047_auto_20231009_1257.py deleted file mode 100644 index b598e96e12..0000000000 --- a/codecov_auth/migrations/0047_auto_20231009_1257.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 4.2.3 on 2023-10-09 12:57 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0046_dedupe_owner_admin_values"), - ] - - operations = [ - migrations.RunSQL( - "ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-teamm';", - reverse_sql=migrations.RunSQL.noop, - ), - migrations.RunSQL( - "ALTER TYPE plans ADD VALUE IF NOT EXISTS 'users-teamy';", - reverse_sql=migrations.RunSQL.noop, - ), - ] diff --git a/codecov_auth/migrations/0048_githubappinstallation.py b/codecov_auth/migrations/0048_githubappinstallation.py deleted file mode 100644 index e95e4966f1..0000000000 --- a/codecov_auth/migrations/0048_githubappinstallation.py +++ /dev/null @@ -1,60 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-17 13:37 - -import uuid - -import django.contrib.postgres.fields -import django.db.models.deletion -import django_prometheus.models -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0047_auto_20231009_1257"), - ] - - # BEGIN; - # -- - # -- Create model GithubAppInstallation - # -- - # CREATE TABLE "codecov_auth_githubappinstallation" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "external_id" uuid NOT NULL, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "installation_id" integer NOT NULL, "name" text NOT NULL, "repository_service_ids" text[] NULL, "owner_id" integer NOT NULL); - # ALTER TABLE "codecov_auth_githubappinstallation" ADD CONSTRAINT "codecov_auth_githuba_owner_id_82ba29b1_fk_owners_ow" FOREIGN KEY ("owner_id") REFERENCES "owners" ("ownerid") DEFERRABLE INITIALLY DEFERRED; - # CREATE INDEX "codecov_auth_githubappinstallation_owner_id_82ba29b1" ON "codecov_auth_githubappinstallation" ("owner_id"); - # COMMIT; - - operations = [ - migrations.CreateModel( - name="GithubAppInstallation", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("installation_id", models.IntegerField()), - ("name", models.TextField(default="codecov_app_installation")), - ( - "repository_service_ids", - django.contrib.postgres.fields.ArrayField( - base_field=models.TextField(), null=True, size=None - ), - ), - ( - "owner", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="github_app_installations", - to="codecov_auth.owner", - ), - ), - ], - options={ - "abstract": False, - }, - bases=( - django_prometheus.models.ExportModelOperationsMixin( - "codecov_auth.github_app_installation" - ), - models.Model, - ), - ), - ] diff --git a/codecov_auth/migrations/0049_ownerprofile_customer_intent.py b/codecov_auth/migrations/0049_ownerprofile_customer_intent.py deleted file mode 100644 index 6069105f49..0000000000 --- a/codecov_auth/migrations/0049_ownerprofile_customer_intent.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 4.2.7 on 2024-02-09 19:24 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0048_githubappinstallation"), - ] - - # BEGIN; - # -- - # -- Add field customer_intent to ownerprofile - # -- - # ALTER TABLE "codecov_auth_ownerprofile" ADD COLUMN "customer_intent" text NULL; - # COMMIT; - operations = [ - migrations.AddField( - model_name="ownerprofile", - name="customer_intent", - field=models.TextField( - choices=[("BUSINESS", "Business"), ("PERSONAL", "Personal")], null=True - ), - ), - ] diff --git a/codecov_auth/migrations/0050_remove_ownerprofile_customer_intent.py b/codecov_auth/migrations/0050_remove_ownerprofile_customer_intent.py deleted file mode 100644 index cbd2e5b806..0000000000 --- a/codecov_auth/migrations/0050_remove_ownerprofile_customer_intent.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.2.7 on 2024-02-13 21:48 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0049_ownerprofile_customer_intent"), - ] - - # BEGIN; - # -- - # -- Remove field customer_intent from ownerprofile - # -- - # ALTER TABLE "codecov_auth_ownerprofile" DROP COLUMN "customer_intent" CASCADE; - # COMMIT; - operations = [ - migrations.RemoveField( - model_name="ownerprofile", - name="customer_intent", - ), - ] diff --git a/codecov_auth/migrations/0051_user_customer_intent.py b/codecov_auth/migrations/0051_user_customer_intent.py deleted file mode 100644 index 9ee1b42880..0000000000 --- a/codecov_auth/migrations/0051_user_customer_intent.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 4.2.7 on 2024-02-14 14:52 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0050_remove_ownerprofile_customer_intent"), - ] - - # BEGIN; - # -- - # -- Add field customer_intent to user - # -- - # ALTER TABLE "users" ADD COLUMN "customer_intent" text NULL; - # COMMIT; - operations = [ - migrations.AddField( - model_name="user", - name="customer_intent", - field=models.TextField( - choices=[("BUSINESS", "Business"), ("PERSONAL", "Personal")], null=True - ), - ), - ] diff --git a/codecov_auth/migrations/0052_githubappinstallation_app_id_and_more.py b/codecov_auth/migrations/0052_githubappinstallation_app_id_and_more.py deleted file mode 100644 index 699c00cc5f..0000000000 --- a/codecov_auth/migrations/0052_githubappinstallation_app_id_and_more.py +++ /dev/null @@ -1,33 +0,0 @@ -# Generated by Django 4.2.7 on 2024-02-19 14:56 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - # BEGIN; - # -- - # -- Add field app_id to githubappinstallation - # -- - # ALTER TABLE "codecov_auth_githubappinstallation" ADD COLUMN "app_id" integer NULL; - # -- - # -- Add field pem_path to githubappinstallation - # -- - # ALTER TABLE "codecov_auth_githubappinstallation" ADD COLUMN "pem_path" text NULL; - # COMMIT; - - dependencies = [ - ("codecov_auth", "0051_user_customer_intent"), - ] - - operations = [ - migrations.AddField( - model_name="githubappinstallation", - name="app_id", - field=models.IntegerField(null=True), - ), - migrations.AddField( - model_name="githubappinstallation", - name="pem_path", - field=models.TextField(null=True), - ), - ] diff --git a/codecov_auth/migrations/0053_ownerinstallationnametousefortask_and_more.py b/codecov_auth/migrations/0053_ownerinstallationnametousefortask_and_more.py deleted file mode 100644 index e37358e508..0000000000 --- a/codecov_auth/migrations/0053_ownerinstallationnametousefortask_and_more.py +++ /dev/null @@ -1,62 +0,0 @@ -# Generated by Django 4.2.7 on 2024-02-21 16:03 - -import uuid - -import django.db.models.deletion -import django_prometheus.models -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0052_githubappinstallation_app_id_and_more"), - ] - - # BEGIN; - # -- - # -- Create model OwnerInstallationNameToUseForTask - # -- - # CREATE TABLE "codecov_auth_ownerinstallationnametousefortask" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "external_id" uuid NOT NULL, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "installation_name" text NOT NULL, "task_name" text NOT NULL, "owner_id" integer NOT NULL); - # -- - # -- Create constraint single_task_name_per_owner on model ownerinstallationnametousefortask - # -- - # CREATE UNIQUE INDEX "single_task_name_per_owner" ON "codecov_auth_ownerinstallationnametousefortask" ("owner_id", "task_name"); - # ALTER TABLE "codecov_auth_ownerinstallationnametousefortask" ADD CONSTRAINT "codecov_auth_ownerin_owner_id_8bf0ce9b_fk_owners_ow" FOREIGN KEY ("owner_id") REFERENCES "owners" ("ownerid") DEFERRABLE INITIALLY DEFERRED; - # CREATE INDEX "codecov_auth_ownerinstalla_owner_id_8bf0ce9b" ON "codecov_auth_ownerinstallationnametousefortask" ("owner_id"); - # COMMIT; - - operations = [ - migrations.CreateModel( - name="OwnerInstallationNameToUseForTask", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("installation_name", models.TextField()), - ("task_name", models.TextField()), - ( - "owner", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="installation_name_to_use_for_tasks", - to="codecov_auth.owner", - ), - ), - ], - bases=( - django_prometheus.models.ExportModelOperationsMixin( - "codecov_auth.github_app_installation" - ), - models.Model, - ), - ), - migrations.AddConstraint( - model_name="ownerinstallationnametousefortask", - constraint=models.UniqueConstraint( - models.F("owner_id"), - models.F("task_name"), - name="single_task_name_per_owner", - ), - ), - ] diff --git a/codecov_auth/migrations/0054_update_owners_column_defaults.py b/codecov_auth/migrations/0054_update_owners_column_defaults.py deleted file mode 100644 index 9e5a580ec6..0000000000 --- a/codecov_auth/migrations/0054_update_owners_column_defaults.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 4.2.11 on 2024-03-28 19:25 - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [ - ("codecov_auth", "0053_ownerinstallationnametousefortask_and_more"), - ] - - operations = [ - RiskyRunSQL( - "ALTER TABLE owners ALTER COLUMN plan_user_count SET DEFAULT 1;", - reverse_sql="ALTER TABLE owners ALTER COLUMN plan_user_count SET DEFAULT NULL;", - ), - RiskyRunSQL( - "ALTER TABLE owners ALTER COLUMN updatestamp SET DEFAULT now();", - reverse_sql="ALTER TABLE owners ALTER COLUMN updatestamp SET DEFAULT NULL;", - ), - RiskyRunSQL( - "ALTER TABLE owners ALTER COLUMN is_superuser SET DEFAULT false;", - reverse_sql="ALTER TABLE owners ALTER COLUMN is_superuser SET DEFAULT NULL;", - ), - RiskyRunSQL( - "ALTER TABLE owners ALTER COLUMN createstamp SET DEFAULT now();", - reverse_sql="ALTER TABLE owners ALTER COLUMN createstamp SET DEFAULT NULL;", - ), - RiskyRunSQL( - "UPDATE owners SET plan_user_count=1 WHERE plan_user_count IS NULL;", - reverse_sql=migrations.RunSQL.noop, - ), - RiskyRunSQL( - "UPDATE owners SET updatestamp=now() WHERE updatestamp IS NULL;", - reverse_sql=migrations.RunSQL.noop, - ), - RiskyRunSQL( - "UPDATE owners SET is_superuser=false WHERE is_superuser IS NULL;", - reverse_sql=migrations.RunSQL.noop, - ), - ] diff --git a/codecov_auth/migrations/__init__.py b/codecov_auth/migrations/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/codecov_auth/models.py b/codecov_auth/models.py index cd96cb672d..b30e6f5e49 100644 --- a/codecov_auth/models.py +++ b/codecov_auth/models.py @@ -1,2 +1 @@ from shared.django_apps.codecov_auth.models import * -from shared.django_apps.codecov_auth.models import _generate_key # noqa: F401 diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py deleted file mode 100644 index 9c9c616ff3..0000000000 --- a/core/migrations/0001_initial.py +++ /dev/null @@ -1,334 +0,0 @@ -# Generated by Django 3.1.6 on 2021-04-08 19:33 - -import datetime -import uuid - -import django.contrib.postgres.fields -import django.contrib.postgres.fields.citext -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - -import core.encoders -import core.models - - -class Migration(migrations.Migration): - initial = True - - dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)] - - operations = [ - migrations.CreateModel( - name="Commit", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("commitid", models.TextField()), - ( - "timestamp", - core.models.DateTimeWithoutTZField(default=datetime.datetime.now), - ), - ( - "updatestamp", - core.models.DateTimeWithoutTZField(default=datetime.datetime.now), - ), - ("ci_passed", models.BooleanField(null=True)), - ("totals", models.JSONField(null=True)), - ( - "report", - models.JSONField( - encoder=core.encoders.ReportJSONEncoder, null=True - ), - ), - ("merged", models.BooleanField(null=True)), - ("deleted", models.BooleanField(null=True)), - ("notified", models.BooleanField(null=True)), - ("branch", models.TextField(null=True)), - ("pullid", models.IntegerField(null=True)), - ("message", models.TextField(null=True)), - ("parent_commit_id", models.TextField(db_column="parent", null=True)), - ( - "state", - models.TextField( - choices=[ - ("complete", "Complete"), - ("pending", "Pending"), - ("error", "Error"), - ("skipped", "Skipped"), - ], - null=True, - ), - ), - ( - "author", - models.ForeignKey( - db_column="author", - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="codecov_auth.owner", - ), - ), - ], - options={"db_table": "commits"}, - ), - migrations.CreateModel( - name="Version", - fields=[("version", models.TextField(primary_key=True, serialize=False))], - options={"db_table": "version"}, - ), - migrations.CreateModel( - name="Repository", - fields=[ - ("repoid", models.AutoField(primary_key=True, serialize=False)), - ("name", django.contrib.postgres.fields.citext.CITextField()), - ("service_id", models.TextField()), - ("private", models.BooleanField()), - ("updatestamp", models.DateTimeField(auto_now=True)), - ("active", models.BooleanField(null=True)), - ("language", models.TextField(blank=True, null=True)), - ("branch", models.TextField(default="master")), - ("upload_token", models.UUIDField(default=uuid.uuid4, unique=True)), - ("yaml", models.JSONField(null=True)), - ("cache", models.JSONField(null=True)), - ( - "image_token", - models.TextField(default=core.models._gen_image_token, null=True), - ), - ("using_integration", models.BooleanField(null=True)), - ("hookid", models.TextField(null=True)), - ("activated", models.BooleanField(default=False, null=True)), - ("deleted", models.BooleanField(default=False)), - ( - "author", - models.ForeignKey( - db_column="ownerid", - on_delete=django.db.models.deletion.CASCADE, - to="codecov_auth.owner", - ), - ), - ( - "bot", - models.ForeignKey( - db_column="bot", - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="bot_repos", - to="codecov_auth.owner", - ), - ), - ( - "fork", - models.ForeignKey( - blank=True, - db_column="forkid", - null=True, - on_delete=django.db.models.deletion.DO_NOTHING, - to="core.repository", - ), - ), - ], - options={"db_table": "repos", "ordering": ["-repoid"]}, - ), - migrations.CreateModel( - name="Pull", - fields=[ - ("pullid", models.IntegerField(primary_key=True, serialize=False)), - ("issueid", models.IntegerField(null=True)), - ( - "state", - models.TextField( - choices=[ - ("open", "Open"), - ("merged", "Merged"), - ("closed", "Closed"), - ], - default="open", - ), - ), - ("title", models.TextField(null=True)), - ("base", models.TextField(null=True)), - ("head", models.TextField(null=True)), - ("compared_to", models.TextField(null=True)), - ("commentid", models.TextField(null=True)), - ( - "updatestamp", - core.models.DateTimeWithoutTZField(default=datetime.datetime.now), - ), - ("diff", models.JSONField(null=True)), - ("flare", models.JSONField(null=True)), - ( - "author", - models.ForeignKey( - db_column="author", - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="codecov_auth.owner", - ), - ), - ( - "repository", - models.ForeignKey( - db_column="repoid", - on_delete=django.db.models.deletion.CASCADE, - related_name="pull_requests", - to="core.repository", - ), - ), - ], - options={"db_table": "pulls", "ordering": ["-pullid"]}, - ), - migrations.CreateModel( - name="CommitNotification", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ( - "notification_type", - models.TextField( - choices=[ - ("comment", "Comment"), - ("gitter", "Gitter"), - ("hipchat", "Hipchat"), - ("irc", "Irc"), - ("slack", "Slack"), - ("status_changes", "Status Changes"), - ("status_patch", "Status Patch"), - ("status_project", "Status Project"), - ("webhook", "Webhook"), - ] - ), - ), - ( - "decoration_type", - models.TextField( - choices=[("standard", "Standard"), ("upgrade", "Upgrade")], - null=True, - ), - ), - ( - "state", - models.TextField( - choices=[ - ("pending", "Pending"), - ("success", "Success"), - ("error", "Error"), - ], - null=True, - ), - ), - ( - "created_at", - core.models.DateTimeWithoutTZField(default=datetime.datetime.now), - ), - ( - "updated_at", - core.models.DateTimeWithoutTZField(default=datetime.datetime.now), - ), - ( - "commit", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="notifications", - to="core.commit", - ), - ), - ], - options={"db_table": "commit_notifications"}, - ), - migrations.AddField( - model_name="commit", - name="repository", - field=models.ForeignKey( - db_column="repoid", - on_delete=django.db.models.deletion.CASCADE, - related_name="commits", - to="core.repository", - ), - ), - migrations.CreateModel( - name="Branch", - fields=[ - ( - "name", - models.TextField( - db_column="branch", primary_key=True, serialize=False - ), - ), - ( - "authors", - django.contrib.postgres.fields.ArrayField( - base_field=models.IntegerField(blank=True, null=True), - blank=True, - db_column="authors", - null=True, - size=None, - ), - ), - ("head", models.TextField()), - ("base", models.TextField(null=True)), - ("updatestamp", models.DateTimeField(auto_now=True)), - ( - "repository", - models.ForeignKey( - db_column="repoid", - on_delete=django.db.models.deletion.CASCADE, - related_name="branches", - to="core.repository", - ), - ), - ], - options={"db_table": "branches"}, - ), - migrations.AddConstraint( - model_name="repository", - constraint=models.UniqueConstraint( - fields=("author", "name"), name="repos_slug" - ), - ), - migrations.AddConstraint( - model_name="repository", - constraint=models.UniqueConstraint( - fields=("author", "service_id"), name="repos_service_ids" - ), - ), - migrations.AddIndex( - model_name="pull", - index=models.Index( - condition=models.Q(state="open"), - fields=["repository"], - name="pulls_repoid_state_open", - ), - ), - migrations.AddConstraint( - model_name="pull", - constraint=models.UniqueConstraint( - fields=("repository", "pullid"), name="pulls_repoid_pullid" - ), - ), - migrations.AddIndex( - model_name="commit", - index=models.Index( - fields=["repository", "-timestamp"], - name="commits_repoid_timestamp_desc", - ), - ), - migrations.AddIndex( - model_name="commit", - index=models.Index( - condition=models.Q(_negated=True, deleted=True), - fields=["repository", "pullid"], - name="commits_on_pull", - ), - ), - migrations.AddConstraint( - model_name="commit", - constraint=models.UniqueConstraint( - fields=("repository", "commitid"), name="commits_repoid_commitid" - ), - ), - migrations.AddConstraint( - model_name="branch", - constraint=models.UniqueConstraint( - fields=("name", "repository"), name="branches_repoid_branch" - ), - ), - ] diff --git a/core/migrations/0002_auto_20210517_1223.py b/core/migrations/0002_auto_20210517_1223.py deleted file mode 100644 index 1939634858..0000000000 --- a/core/migrations/0002_auto_20210517_1223.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.6 on 2021-05-17 12:23 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [("core", "0001_initial")] - - operations = [ - migrations.AlterField( - model_name="repository", - name="active", - field=models.BooleanField(default=False, null=True), - ), - RiskyRunSQL("UPDATE repos SET active=false WHERE active is null;"), - ] diff --git a/core/migrations/0003_auto_20210520_0841.py b/core/migrations/0003_auto_20210520_0841.py deleted file mode 100644 index d7dcc9dfa8..0000000000 --- a/core/migrations/0003_auto_20210520_0841.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 3.1.6 on 2021-05-20 08:41 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [("core", "0002_auto_20210517_1223")] - - operations = [ - migrations.AlterField( - model_name="repository", - name="language", - field=models.TextField( - blank=True, - choices=[ - ("javascript", "Javascript"), - ("shell", "Shell"), - ("python", "Python"), - ("ruby", "Ruby"), - ("perl", "Perl"), - ("dart", "Dart"), - ("java", "Java"), - ("c", "C"), - ("clojure", "Clojure"), - ("d", "D"), - ("fortran", "Fortran"), - ("go", "Go"), - ("groovy", "Groovy"), - ("kotlin", "Kotlin"), - ("php", "Php"), - ("r", "R"), - ("scala", "Scala"), - ("swift", "Swift"), - ("objective-c", "Objective C"), - ("xtend", "Xtend"), - ], - null=True, - ), - ), - RiskyRunSQL("ALTER TABLE repos ALTER COLUMN active SET DEFAULT FALSE;"), - RiskyRunSQL("UPDATE repos SET active=false WHERE active is null;"), - ] diff --git a/core/migrations/0004_pull_user_provided_base_sha.py b/core/migrations/0004_pull_user_provided_base_sha.py deleted file mode 100644 index f308cf3f5a..0000000000 --- a/core/migrations/0004_pull_user_provided_base_sha.py +++ /dev/null @@ -1,15 +0,0 @@ -# Generated by Django 3.1.6 on 2021-06-23 19:34 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [("core", "0003_auto_20210520_0841")] - - operations = [ - migrations.AddField( - model_name="pull", - name="user_provided_base_sha", - field=models.TextField(null=True), - ) - ] diff --git a/core/migrations/0005_auto_20210916_0313.py b/core/migrations/0005_auto_20210916_0313.py deleted file mode 100644 index 4df2656ab6..0000000000 --- a/core/migrations/0005_auto_20210916_0313.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.1.13 on 2021-09-16 03:13 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [("core", "0004_pull_user_provided_base_sha")] - - operations = [ - migrations.AddField( - model_name="pull", - name="id", - field=models.BigAutoField(primary_key=True, serialize=False), - preserve_default=False, - ), - migrations.AlterField( - model_name="pull", name="pullid", field=models.IntegerField() - ), - ] diff --git a/core/migrations/0006_version_v4_6_2.py b/core/migrations/0006_version_v4_6_2.py deleted file mode 100644 index c416dada6e..0000000000 --- a/core/migrations/0006_version_v4_6_2.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import migrations - - -def add_version(apps, schema): - version = apps.get_model("core", "Version") - version.objects.all().delete() - v = version(version="v4.6.2") - v.save() - - -class Migration(migrations.Migration): - dependencies = [("core", "0005_auto_20210916_0313")] - - operations = [migrations.RunPython(add_version)] diff --git a/core/migrations/0007_version_v4_6_3.py b/core/migrations/0007_version_v4_6_3.py deleted file mode 100644 index 3f93c825de..0000000000 --- a/core/migrations/0007_version_v4_6_3.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import migrations - - -def add_version(apps, schema): - version = apps.get_model("core", "Version") - version.objects.all().delete() - v = version(version="v4.6.3") - v.save() - - -class Migration(migrations.Migration): - dependencies = [("core", "0006_version_v4_6_2")] - - operations = [migrations.RunPython(add_version)] diff --git a/core/migrations/0008_version_v4_6_4.py b/core/migrations/0008_version_v4_6_4.py deleted file mode 100644 index c9a0128112..0000000000 --- a/core/migrations/0008_version_v4_6_4.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import migrations - - -def add_version(apps, schema): - version = apps.get_model("core", "Version") - version.objects.all().delete() - v = version(version="v4.6.4") - v.save() - - -class Migration(migrations.Migration): - dependencies = [("core", "0007_version_v4_6_3")] - - operations = [migrations.RunPython(add_version)] diff --git a/core/migrations/0009_version_v4_6_5.py b/core/migrations/0009_version_v4_6_5.py deleted file mode 100644 index eec07e26d0..0000000000 --- a/core/migrations/0009_version_v4_6_5.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import migrations - - -def add_version(apps, schema): - version = apps.get_model("core", "Version") - version.objects.all().delete() - v = version(version="v4.6.5") - v.save() - - -class Migration(migrations.Migration): - dependencies = [("core", "0008_version_v4_6_4")] - - operations = [migrations.RunPython(add_version)] diff --git a/core/migrations/0010_add_new_langs.py b/core/migrations/0010_add_new_langs.py deleted file mode 100644 index cb8229a7f8..0000000000 --- a/core/migrations/0010_add_new_langs.py +++ /dev/null @@ -1,84 +0,0 @@ -# Generated by Django 3.1.13 on 2022-04-06 17:23 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - atomic = False - - dependencies = [("core", "0009_version_v4_6_5")] - - operations = [ - migrations.AlterModelOptions( - name="repository", - options={"ordering": ["-repoid"], "verbose_name_plural": "Repositories"}, - ), - migrations.AlterField( - model_name="repository", - name="language", - field=models.TextField( - blank=True, - choices=[ - ("javascript", "Javascript"), - ("shell", "Shell"), - ("python", "Python"), - ("ruby", "Ruby"), - ("perl", "Perl"), - ("dart", "Dart"), - ("java", "Java"), - ("c", "C"), - ("clojure", "Clojure"), - ("d", "D"), - ("fortran", "Fortran"), - ("go", "Go"), - ("groovy", "Groovy"), - ("kotlin", "Kotlin"), - ("php", "Php"), - ("r", "R"), - ("scala", "Scala"), - ("swift", "Swift"), - ("objective-c", "Objective C"), - ("xtend", "Xtend"), - ("typescript", "Typescript"), - ("haskell", "Haskell"), - ("rust", "Rust"), - ("lua", "Lua"), - ("matlab", "Matlab"), - ("assembly", "Assembly"), - ("scheme", "Scheme"), - ("powershell", "Powershell"), - ("apex", "Apex"), - ("verilog", "Verilog"), - ("common lisp", "Common Lisp"), - ("erlang", "Erlang"), - ("julia", "Julia"), - ("prolog", "Prolog"), - ("vue", "Vue"), - ("c++", "Cpp"), - ("c#", "C Sharp"), - ("f#", "F Sharp"), - ], - null=True, - ), - ), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'typescript';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'haskell';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'rust';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'lua';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'matlab';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'assembly';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'scheme';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'powershell';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'apex';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'verilog';"), - migrations.RunSQL( - "ALTER TYPE languages ADD VALUE IF NOT exists 'common lisp';" - ), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'erlang';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'julia';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'prolog';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'vue';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'c++';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'c#';"), - migrations.RunSQL("ALTER TYPE languages ADD VALUE IF NOT exists 'f#';"), - ] diff --git a/core/migrations/0011_add_decoration_type.py b/core/migrations/0011_add_decoration_type.py deleted file mode 100644 index 6d0baccaa5..0000000000 --- a/core/migrations/0011_add_decoration_type.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.1.13 on 2022-04-27 10:53 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - atomic = False - dependencies = [ - ("core", "0010_add_new_langs"), - ] - - operations = [ - migrations.AlterField( - model_name="commitnotification", - name="decoration_type", - field=models.TextField( - choices=[ - ("standard", "Standard"), - ("upgrade", "Upgrade"), - ("upload_limit", "Upload Limit"), - ], - null=True, - ), - ), - migrations.RunSQL( - "ALTER TYPE decorations ADD VALUE IF NOT exists 'upload_limit';" - ), - ] diff --git a/core/migrations/0012_auto_20220511_1732.py b/core/migrations/0012_auto_20220511_1732.py deleted file mode 100644 index f6402f3af6..0000000000 --- a/core/migrations/0012_auto_20220511_1732.py +++ /dev/null @@ -1,36 +0,0 @@ -# Generated by Django 3.1.13 on 2022-05-11 17:32 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("core", "0011_add_decoration_type"), - ] - - operations = [ - migrations.RunSQL( - """-- - -- Alter field bot on Repository - -- - COMMIT; - """, - state_operations=[ - migrations.AlterField( - model_name="repository", - name="bot", - field=models.ForeignKey( - blank=True, - db_column="bot", - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="bot_repos", - to="codecov_auth.owner", - ), - ), - ], - ), - ] diff --git a/core/migrations/0013_repository_repos_service_id_author.py b/core/migrations/0013_repository_repos_service_id_author.py deleted file mode 100644 index 054d14d8fa..0000000000 --- a/core/migrations/0013_repository_repos_service_id_author.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.2.12 on 2022-05-03 02:57 - -from django.contrib.postgres.operations import AddIndexConcurrently -from django.db import migrations, models - - -class Migration(migrations.Migration): - atomic = False - dependencies = [ - ("core", "0012_auto_20220511_1732"), - ] - - operations = [ - AddIndexConcurrently( - model_name="repository", - index=models.Index( - fields=["service_id", "author"], name="repos_service_id_author" - ), - ), - ] diff --git a/core/migrations/0014_pull_pulls_author_updatestamp.py b/core/migrations/0014_pull_pulls_author_updatestamp.py deleted file mode 100644 index dbc08263da..0000000000 --- a/core/migrations/0014_pull_pulls_author_updatestamp.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.2.12 on 2022-07-11 13:34 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddIndex - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Create index pulls_author_updatestamp on field(s) author, updatestamp of model pull - -- - CREATE INDEX "pulls_author_updatestamp" ON "pulls" ("author", "updatestamp"); - COMMIT; - """ - - dependencies = [ - ("core", "0013_repository_repos_service_id_author"), - ] - - operations = [ - RiskyAddIndex( - model_name="pull", - index=models.Index( - fields=["author", "updatestamp"], name="pulls_author_updatestamp" - ), - ), - ] diff --git a/core/migrations/0015_commiterror.py b/core/migrations/0015_commiterror.py deleted file mode 100644 index b97c312e3f..0000000000 --- a/core/migrations/0015_commiterror.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 3.2.12 on 2022-08-09 15:14 - -import uuid - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0014_pull_pulls_author_updatestamp"), - ] - - operations = [ - migrations.CreateModel( - name="CommitError", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("error_code", models.CharField(max_length=100)), - ("error_params", models.JSONField(default=dict)), - ( - "commit", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="errors", - to="core.commit", - ), - ), - ], - options={ - "abstract": False, - }, - ), - ] diff --git a/core/migrations/0016_version_v4_6_6.py b/core/migrations/0016_version_v4_6_6.py deleted file mode 100644 index 1a578b4d76..0000000000 --- a/core/migrations/0016_version_v4_6_6.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import migrations - - -def add_version(apps, schema): - version = apps.get_model("core", "Version") - version.objects.all().delete() - v = version(version="v4.6.6") - v.save() - - -class Migration(migrations.Migration): - dependencies = [("core", "0015_commiterror")] - - operations = [migrations.RunPython(add_version)] diff --git a/core/migrations/0017_branch_branches_repoid_updatestamp.py b/core/migrations/0017_branch_branches_repoid_updatestamp.py deleted file mode 100644 index b492250ea2..0000000000 --- a/core/migrations/0017_branch_branches_repoid_updatestamp.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 3.2.12 on 2023-01-13 16:44 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddIndex - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Create index branches_repoid_updatestamp on field(s) repository, -updatestamp of model branch - -- - CREATE INDEX "branches_repoid_updatestamp" ON "branches" ("repoid", "updatestamp" DESC); - COMMIT; - """ - - dependencies = [ - ("core", "0016_version_v4_6_6"), - ] - - operations = [ - RiskyAddIndex( - model_name="branch", - index=models.Index( - fields=["repository", "-updatestamp"], - name="branches_repoid_updatestamp", - ), - ), - ] diff --git a/core/migrations/0018_commit_all_commits_on_pull.py b/core/migrations/0018_commit_all_commits_on_pull.py deleted file mode 100644 index f78cb994ce..0000000000 --- a/core/migrations/0018_commit_all_commits_on_pull.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.2.12 on 2023-01-26 17:52 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddIndex - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Create index all_commits_on_pull on field(s) repository, pullid of model commit - -- - CREATE INDEX "all_commits_on_pull" ON "commits" ("repoid", "pullid"); - COMMIT; - """ - - dependencies = [ - ("core", "0017_branch_branches_repoid_updatestamp"), - ] - - operations = [ - RiskyAddIndex( - model_name="commit", - index=models.Index( - fields=["repository", "pullid"], name="all_commits_on_pull" - ), - ), - ] diff --git a/core/migrations/0019_commit_commits_repoid_branch_state_ts.py b/core/migrations/0019_commit_commits_repoid_branch_state_ts.py deleted file mode 100644 index 1f5b1e2fb2..0000000000 --- a/core/migrations/0019_commit_commits_repoid_branch_state_ts.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-01 15:04 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddIndex - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Create index commits_repoid_branch_state_ts on field(s) repository, branch, state, -timestamp of model commit - -- - CREATE INDEX "commits_repoid_branch_state_ts" ON "commits" ("repoid", "branch", "state", "timestamp" DESC); - COMMIT; - """ - - dependencies = [ - ("core", "0018_commit_all_commits_on_pull"), - ] - - operations = [ - RiskyAddIndex( - model_name="commit", - index=models.Index( - fields=["repository", "branch", "state", "-timestamp"], - name="commits_repoid_branch_state_ts", - ), - ), - ] diff --git a/core/migrations/0020_commit_commits_repoid_commitid_short_and_more.py b/core/migrations/0020_commit_commits_repoid_commitid_short_and_more.py deleted file mode 100644 index 1d0d3fa6b2..0000000000 --- a/core/migrations/0020_commit_commits_repoid_commitid_short_and_more.py +++ /dev/null @@ -1,60 +0,0 @@ -# Generated by Django 4.1.7 on 2023-03-10 18:24 - -import django.contrib.postgres.indexes -import django.db.models.functions.text -from django.contrib.postgres.operations import BtreeGinExtension, TrigramExtension -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddIndex - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Creates extension pg_trgm - -- - CREATE EXTENSION IF NOT EXISTS "pg_trgm"; - -- - -- Creates extension btree_gin - -- - CREATE EXTENSION IF NOT EXISTS "btree_gin"; - -- - -- Create index commits_repoid_commitid_short on F(repository), Substr(Lower(F(commitid)), Value(1), Value(7)) on model commit - -- - CREATE INDEX "commits_repoid_commitid_short" ON "commits" ("repoid", (SUBSTRING(LOWER("commitid"), 1, 7))); - -- - -- Create index commit_message_gin_trgm on F(repository), OpClass(Upper(F(message)), name=gin_trgm_ops) on model commit - -- - CREATE INDEX "commit_message_gin_trgm" ON "commits" USING gin ("repoid", (UPPER("message")) gin_trgm_ops); - COMMIT; - """ - - dependencies = [ - ("core", "0019_commit_commits_repoid_branch_state_ts"), - ] - - operations = [ - TrigramExtension(), - BtreeGinExtension(), - RiskyAddIndex( - model_name="commit", - index=models.Index( - models.F("repository"), - django.db.models.functions.text.Substr( - django.db.models.functions.text.Lower("commitid"), 1, 7 - ), - name="commits_repoid_commitid_short", - ), - ), - RiskyAddIndex( - model_name="commit", - index=django.contrib.postgres.indexes.GinIndex( - models.F("repository"), - django.contrib.postgres.indexes.OpClass( - django.db.models.functions.text.Upper("message"), - name="gin_trgm_ops", - ), - name="commit_message_gin_trgm", - ), - ), - ] diff --git a/core/migrations/0021_pull_behind_by_pull_behind_by_commit.py b/core/migrations/0021_pull_behind_by_pull_behind_by_commit.py deleted file mode 100644 index 79eb3d82d1..0000000000 --- a/core/migrations/0021_pull_behind_by_pull_behind_by_commit.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.1.7 on 2023-04-04 11:45 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0020_commit_commits_repoid_commitid_short_and_more"), - ] - - operations = [ - migrations.AddField( - model_name="pull", - name="behind_by", - field=models.IntegerField(null=True), - ), - migrations.AddField( - model_name="pull", - name="behind_by_commit", - field=models.TextField(null=True), - ), - ] diff --git a/core/migrations/0022_pull_pulls_repoid_pullid_ts.py b/core/migrations/0022_pull_pulls_repoid_pullid_ts.py deleted file mode 100644 index 14632bd244..0000000000 --- a/core/migrations/0022_pull_pulls_repoid_pullid_ts.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 4.1.7 on 2023-04-24 18:59 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddIndex - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Create index pulls_repoid_pullid_ts on field(s) repository, pullid, updatestamp of model pull - -- - CREATE INDEX "pulls_repoid_pullid_ts" ON "pulls" ("repoid", "pullid", "updatestamp"); - COMMIT; - """ - - dependencies = [ - ("core", "0021_pull_behind_by_pull_behind_by_commit"), - ] - - operations = [ - RiskyAddIndex( - model_name="pull", - index=models.Index( - fields=["repository", "pullid", "updatestamp"], - name="pulls_repoid_pullid_ts", - ), - ), - ] diff --git a/core/migrations/0023_alter_commitnotification_decoration_type.py b/core/migrations/0023_alter_commitnotification_decoration_type.py deleted file mode 100644 index 792915fdfa..0000000000 --- a/core/migrations/0023_alter_commitnotification_decoration_type.py +++ /dev/null @@ -1,46 +0,0 @@ -# Generated by Django 4.1.7 on 2023-05-10 07:35 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - # -- - # -- Alter field decoration_type on commitnotification - # -- - # -- (no-op) - # -- - # -- Raw SQL operation - # -- - # ALTER TYPE decorations ADD VALUE IF NOT exists 'passing_empty_upload'; - # -- - # -- Raw SQL operation - # -- - # ALTER TYPE decorations ADD VALUE IF NOT exists 'failing_empty_upload'; - - atomic = False - dependencies = [ - ("core", "0022_pull_pulls_repoid_pullid_ts"), - ] - - operations = [ - migrations.AlterField( - model_name="commitnotification", - name="decoration_type", - field=models.TextField( - choices=[ - ("standard", "Standard"), - ("upgrade", "Upgrade"), - ("upload_limit", "Upload Limit"), - ("passing_empty_upload", "Passing Empty Upload"), - ("failing_empty_upload", "Failing Empty Upload"), - ], - null=True, - ), - ), - migrations.RunSQL( - "ALTER TYPE decorations ADD VALUE IF NOT exists 'passing_empty_upload';" - ), - migrations.RunSQL( - "ALTER TYPE decorations ADD VALUE IF NOT exists 'failing_empty_upload';" - ), - ] diff --git a/core/migrations/0024_alter_commit_timestamp_alter_commit_updatestamp_and_more.py b/core/migrations/0024_alter_commit_timestamp_alter_commit_updatestamp_and_more.py deleted file mode 100644 index 516f08d4f1..0000000000 --- a/core/migrations/0024_alter_commit_timestamp_alter_commit_updatestamp_and_more.py +++ /dev/null @@ -1,48 +0,0 @@ -# Generated by Django 4.1.7 on 2023-05-29 15:24 - -import django.utils.timezone -from django.db import migrations, models - -import core.models - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0023_alter_commitnotification_decoration_type"), - ] - - operations = [ - migrations.AlterField( - model_name="commit", - name="timestamp", - field=core.models.DateTimeWithoutTZField(default=django.utils.timezone.now), - ), - migrations.AlterField( - model_name="commit", - name="updatestamp", - field=core.models.DateTimeWithoutTZField(default=django.utils.timezone.now), - ), - migrations.AlterField( - model_name="commitnotification", - name="notification_type", - field=models.TextField( - choices=[ - ("comment", "Comment"), - ("gitter", "Gitter"), - ("hipchat", "Hipchat"), - ("irc", "Irc"), - ("slack", "Slack"), - ("status_changes", "Status Changes"), - ("status_patch", "Status Patch"), - ("status_project", "Status Project"), - ("webhook", "Webhook"), - ("codecov_slack_app", "Codecov Slack App"), - ] - ), - ), - migrations.AlterField( - model_name="pull", - name="updatestamp", - field=core.models.DateTimeWithoutTZField(default=django.utils.timezone.now), - ), - ] diff --git a/core/migrations/0025_v5_0_1.py b/core/migrations/0025_v5_0_1.py deleted file mode 100644 index 8464509af4..0000000000 --- a/core/migrations/0025_v5_0_1.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.db import migrations - - -def add_version(apps, schema): - version = apps.get_model("core", "Version") - version.objects.all().delete() - v = version(version="v5.0.1") - v.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0024_alter_commit_timestamp_alter_commit_updatestamp_and_more") - ] - - operations = [migrations.RunPython(add_version)] diff --git a/core/migrations/0026_auto_20230605_1134.py b/core/migrations/0026_auto_20230605_1134.py deleted file mode 100644 index 83a199172f..0000000000 --- a/core/migrations/0026_auto_20230605_1134.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.1.7 on 2023-06-05 11:34 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0025_v5_0_1"), - ] - - operations = [ - migrations.RunSQL( - """ - ALTER TYPE notifications ADD VALUE IF NOT exists 'codecov_slack_app'; - """ - ), - ] diff --git a/core/migrations/0027_alter_commit_report_rename_report_commit__report_and_more.py b/core/migrations/0027_alter_commit_report_rename_report_commit__report_and_more.py deleted file mode 100644 index 256d24c809..0000000000 --- a/core/migrations/0027_alter_commit_report_rename_report_commit__report_and_more.py +++ /dev/null @@ -1,46 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-18 07:33 - -from django.db import migrations, models - -import core.encoders - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0026_auto_20230605_1134"), - ] - - # BEGIN; - # -- - # -- Alter field report on commit - # -- - # -- (no-op) - # -- - # -- Rename field report on commit to _report - # -- - # -- (no-op) - # -- - # -- Add field _report_storage_path to commit - # -- - # ALTER TABLE "commits" ADD COLUMN "report_storage_path" varchar(200) NULL; - # COMMIT; - - operations = [ - migrations.AlterField( - model_name="commit", - name="report", - field=models.JSONField( - db_column="report", encoder=core.encoders.ReportJSONEncoder, null=True - ), - ), - migrations.RenameField( - model_name="commit", - old_name="report", - new_name="_report", - ), - migrations.AddField( - model_name="commit", - name="_report_storage_path", - field=models.URLField(db_column="report_storage_path", null=True), - ), - ] diff --git a/core/migrations/0028_repository_webhook_secret.py b/core/migrations/0028_repository_webhook_secret.py deleted file mode 100644 index d41a8cb84b..0000000000 --- a/core/migrations/0028_repository_webhook_secret.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-24 16:38 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddField - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field webhook_secret to repository - -- - ALTER TABLE "repos" ADD COLUMN "webhook_secret" text NULL; - COMMIT; - """ - - dependencies = [ - ("core", "0027_alter_commit_report_rename_report_commit__report_and_more"), - ] - - operations = [ - RiskyAddField( - model_name="repository", - name="webhook_secret", - field=models.TextField(null=True), - ), - ] diff --git a/core/migrations/0029_constants_delete_version.py b/core/migrations/0029_constants_delete_version.py deleted file mode 100644 index 34b2539cd4..0000000000 --- a/core/migrations/0029_constants_delete_version.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-27 15:39 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0028_repository_webhook_secret"), - ] - - operations = [ - migrations.CreateModel( - name="Constants", - fields=[ - ("key", models.CharField(primary_key=True, serialize=False)), - ("value", models.CharField()), - ], - options={ - "db_table": "constants", - }, - ), - ] diff --git a/core/migrations/0030_auto_20230727_1539.py b/core/migrations/0030_auto_20230727_1539.py deleted file mode 100644 index 9cc1af28cc..0000000000 --- a/core/migrations/0030_auto_20230727_1539.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-27 15:39 - -from uuid import uuid4 - -from django.db import migrations - - -def generate_constants(apps, schema_editor): - Constants = apps.get_model("core", "Constants") - version = Constants(key="version", value="23.7.27") - install_id = Constants(key="install_id", value=uuid4()) - version.save() - install_id.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0029_constants_delete_version"), - ] - - operations = [migrations.RunPython(generate_constants)] diff --git a/core/migrations/0031_auto_20230731_1627.py b/core/migrations/0031_auto_20230731_1627.py deleted file mode 100644 index 616ef65d2c..0000000000 --- a/core/migrations/0031_auto_20230731_1627.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-31 16:27 - -from django.db import migrations - - -def update_version(apps, schema_editor): - version = apps.get_model("core", "Version") - version.objects.all().delete() - v = version(version="23.7.27") - v.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0030_auto_20230727_1539"), - ] - - operations = [migrations.RunPython(update_version)] diff --git a/core/migrations/0032_auto_20230731_1641.py b/core/migrations/0032_auto_20230731_1641.py deleted file mode 100644 index 171f5e741d..0000000000 --- a/core/migrations/0032_auto_20230731_1641.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-31 16:41 - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0031_auto_20230731_1627"), - ] - - operations = [ - RiskyRunSQL( - """ - create or replace function branches_update() returns trigger as $$ - declare _ownerid int; - begin - -- update repos cache if main branch - update repos - set updatestamp = now() - where repoid = new.repoid - and branch = new.branch - returning ownerid into _ownerid; - - if found then - -- default branch updated, so we can update the owners timestamp - -- to refresh the team list - update owners - set updatestamp=now() - where ownerid=_ownerid; - end if; - - return null; - end; - $$ language plpgsql; - """ - ) - ] diff --git a/core/migrations/0033_alter_pull_flare_rename_flare_pull__flare_and_more.py b/core/migrations/0033_alter_pull_flare_rename_flare_pull__flare_and_more.py deleted file mode 100644 index 59573ade70..0000000000 --- a/core/migrations/0033_alter_pull_flare_rename_flare_pull__flare_and_more.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 4.2.2 on 2023-08-03 09:07 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0032_auto_20230731_1641"), - ] - - # BEGIN; - # -- - # -- Alter field flare on pull - # -- - # -- (no-op) - # -- - # -- Rename field flare on pull to _flare - # -- - # -- (no-op) - # -- - # -- Add field _flare_storage_path to pull - # -- - # ALTER TABLE "pulls" ADD COLUMN "flare_storage_path" varchar(200) NULL; - # COMMIT; - - operations = [ - migrations.AlterField( - model_name="pull", - name="flare", - field=models.JSONField(db_column="flare", null=True), - ), - migrations.RenameField( - model_name="pull", - old_name="flare", - new_name="_flare", - ), - migrations.AddField( - model_name="pull", - name="_flare_storage_path", - field=models.URLField(db_column="flare_storage_path", null=True), - ), - ] diff --git a/core/migrations/0034_remove_repository_cache.py b/core/migrations/0034_remove_repository_cache.py deleted file mode 100644 index d0a454008f..0000000000 --- a/core/migrations/0034_remove_repository_cache.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.2.2 on 2023-08-14 13:23 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ( - "core", - "0033_alter_pull_flare_rename_flare_pull__flare_and_more", - ), - ] - - operations = [ - migrations.RunSQL( - sql=migrations.RunSQL.noop, - state_operations=[ - migrations.RemoveField( - model_name="repository", - name="cache", - ) - ], - ) - ] diff --git a/core/migrations/0035_auto_20230907_2123.py b/core/migrations/0035_auto_20230907_2123.py deleted file mode 100644 index 3b08bd7fdb..0000000000 --- a/core/migrations/0035_auto_20230907_2123.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.2.2 on 2023-09-07 21:23 - -from django.db import migrations - - -class Migration(migrations.Migration): - def add_version(apps, schema): - Constants = apps.get_model("core", "Constants") - version = Constants.objects.get(key="version") - version.value = "23.9.5" - version.save() - - dependencies = [ - ("core", "0034_remove_repository_cache"), - ] - - operations = [migrations.RunPython(add_version)] diff --git a/core/migrations/0036_auto_20231003_1342.py b/core/migrations/0036_auto_20231003_1342.py deleted file mode 100644 index 1cfeb78ff2..0000000000 --- a/core/migrations/0036_auto_20231003_1342.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.3 on 2023-10-03 13:42 - -from django.db import migrations - - -def update_version(apps, schema): - Constants = apps.get_model("core", "Constants") - version = Constants.objects.get(key="version") - version.value = "23.10.2" - version.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0035_auto_20230907_2123"), - ] - - operations = [migrations.RunPython(update_version)] diff --git a/core/migrations/0037_alter_commitnotification_decoration_type.py b/core/migrations/0037_alter_commitnotification_decoration_type.py deleted file mode 100644 index ebf889692b..0000000000 --- a/core/migrations/0037_alter_commitnotification_decoration_type.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 4.2.3 on 2023-10-06 16:06 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0036_auto_20231003_1342"), - ] - - operations = [ - migrations.AlterField( - model_name="commitnotification", - name="decoration_type", - field=models.TextField( - choices=[ - ("standard", "Standard"), - ("upgrade", "Upgrade"), - ("upload_limit", "Upload Limit"), - ("passing_empty_upload", "Passing Empty Upload"), - ("failing_empty_upload", "Failing Empty Upload"), - ("processing_upload", "Processing Upload"), - ], - null=True, - ), - ), - migrations.RunSQL( - "ALTER TYPE decorations ADD VALUE IF NOT exists 'processing_upload';" - ), - ] diff --git a/core/migrations/0038_increment_version.py b/core/migrations/0038_increment_version.py deleted file mode 100644 index 21459c4938..0000000000 --- a/core/migrations/0038_increment_version.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.3 on 2023-11-03 13:24 - -from django.db import migrations - - -def update_version(apps, schema): - Constants = apps.get_model("core", "Constants") - version = Constants.objects.get(key="version") - version.value = "23.11.2" - version.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0037_alter_commitnotification_decoration_type"), - ] - - operations = [migrations.RunPython(update_version)] diff --git a/core/migrations/0039_pull_pulls_repoid_id.py b/core/migrations/0039_pull_pulls_repoid_id.py deleted file mode 100644 index 07dd6247f5..0000000000 --- a/core/migrations/0039_pull_pulls_repoid_id.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 4.2.3 on 2023-10-30 16:16 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddIndex - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Create index pulls_repoid_id on field(s) repository, id of model pull - -- - CREATE INDEX "pulls_repoid_id" ON "pulls" ("repoid", "id"); - COMMIT; - """ - - dependencies = [ - ("core", "0038_increment_version"), - ] - - operations = [ - RiskyAddIndex( - model_name="pull", - index=models.Index(fields=["repository", "id"], name="pulls_repoid_id"), - ), - ] diff --git a/core/migrations/0040_increment_version.py b/core/migrations/0040_increment_version.py deleted file mode 100644 index 592154ca67..0000000000 --- a/core/migrations/0040_increment_version.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.7 on 2023-12-04 21:13 - -from django.db import migrations - - -def update_version(apps, schema): - Constants = apps.get_model("core", "Constants") - version = Constants.objects.get(key="version") - version.value = "23.12.4" - version.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0039_pull_pulls_repoid_id"), - ] - - operations = [migrations.RunPython(update_version)] diff --git a/core/migrations/0041_pull_bundle_analysis_commentid.py b/core/migrations/0041_pull_bundle_analysis_commentid.py deleted file mode 100644 index f7c2edb3ec..0000000000 --- a/core/migrations/0041_pull_bundle_analysis_commentid.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 4.2.7 on 2023-12-27 17:00 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddField - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field bundle_analysis_commentid to pull - -- - ALTER TABLE "pulls" ADD COLUMN "bundle_analysis_commentid" text NULL; - COMMIT; - """ - - dependencies = [ - ("core", "0040_increment_version"), - ] - - operations = [ - RiskyAddField( - model_name="pull", - name="bundle_analysis_commentid", - field=models.TextField(null=True), - ), - ] diff --git a/core/migrations/0042_repository_languages.py b/core/migrations/0042_repository_languages.py deleted file mode 100644 index ee067ee5fd..0000000000 --- a/core/migrations/0042_repository_languages.py +++ /dev/null @@ -1,31 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-09 18:54 - -import django.contrib.postgres.fields -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddField - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field languages to repository - -- - ALTER TABLE "repos" ADD COLUMN "languages" varchar[] DEFAULT '{}' NOT NULL; - ALTER TABLE "repos" ALTER COLUMN "languages" DROP DEFAULT; - COMMIT; - """ - - dependencies = [ - ("core", "0041_pull_bundle_analysis_commentid"), - ] - - operations = [ - RiskyAddField( - model_name="repository", - name="languages", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.CharField(), blank=True, default=[], size=None - ), - ), - ] diff --git a/core/migrations/0043_repository_bundle_analysis_enabled.py b/core/migrations/0043_repository_bundle_analysis_enabled.py deleted file mode 100644 index 99dbb0178a..0000000000 --- a/core/migrations/0043_repository_bundle_analysis_enabled.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-09 21:10 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddField - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field bundle_analysis_enabled to repository - -- - ALTER TABLE "repos" ADD COLUMN "bundle_analysis_enabled" boolean DEFAULT false NOT NULL; - ALTER TABLE "repos" ALTER COLUMN "bundle_analysis_enabled" DROP DEFAULT; - COMMIT; - """ - - dependencies = [ - ("core", "0042_repository_languages"), - ] - - operations = [ - RiskyAddField( - model_name="repository", - name="bundle_analysis_enabled", - field=models.BooleanField(default=False), - ), - ] diff --git a/core/migrations/0044_alter_repository_bundle_analysis_enabled_and_more.py b/core/migrations/0044_alter_repository_bundle_analysis_enabled_and_more.py deleted file mode 100644 index c370cbc9a5..0000000000 --- a/core/migrations/0044_alter_repository_bundle_analysis_enabled_and_more.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-10 12:28 - -import django.contrib.postgres.fields -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAlterField - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Alter field bundle_analysis_enabled on repository - -- - ALTER TABLE "repos" ALTER COLUMN "bundle_analysis_enabled" DROP NOT NULL; - -- - -- Alter field languages on repository - -- - ALTER TABLE "repos" ALTER COLUMN "languages" DROP NOT NULL; - COMMIT; - """ - - dependencies = [ - ("core", "0043_repository_bundle_analysis_enabled"), - ] - - operations = [ - RiskyAlterField( - model_name="repository", - name="bundle_analysis_enabled", - field=models.BooleanField(default=False, null=True), - ), - RiskyAlterField( - model_name="repository", - name="languages", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.CharField(), - blank=True, - default=[], - null=True, - size=None, - ), - ), - ] diff --git a/core/migrations/0045_repository_languages_last_updated.py b/core/migrations/0045_repository_languages_last_updated.py deleted file mode 100644 index 2b2f0d3bea..0000000000 --- a/core/migrations/0045_repository_languages_last_updated.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-11 05:32 - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyAddField - -import core.models - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field languages_last_updated to repository - -- - ALTER TABLE "repos" ADD COLUMN "languages_last_updated" timestamp NULL; - COMMIT; - """ - - dependencies = [ - ("core", "0044_alter_repository_bundle_analysis_enabled_and_more"), - ] - - operations = [ - RiskyAddField( - model_name="repository", - name="languages_last_updated", - field=core.models.DateTimeWithoutTZField(blank=True, null=True), - ), - ] diff --git a/core/migrations/0046_repository_coverage_enabled.py b/core/migrations/0046_repository_coverage_enabled.py deleted file mode 100644 index 90fda0cc72..0000000000 --- a/core/migrations/0046_repository_coverage_enabled.py +++ /dev/null @@ -1,33 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-15 20:36 - -from django.db import migrations, models -from shared.django_apps.migration_utils import RiskyAddField, RiskyRunSQL - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field coverage_enabled to repository - -- - ALTER TABLE "repos" ADD COLUMN "coverage_enabled" boolean DEFAULT false NULL; - ALTER TABLE "repos" ALTER COLUMN "coverage_enabled" DROP DEFAULT; - -- - -- Raw SQL operation - -- - UPDATE repos SET coverage_enabled=true WHERE active=true; - COMMIT; - """ - - dependencies = [ - ("core", "0045_repository_languages_last_updated"), - ] - - operations = [ - RiskyAddField( - model_name="repository", - name="coverage_enabled", - field=models.BooleanField(default=False, null=True), - ), - RiskyRunSQL("UPDATE repos SET coverage_enabled=true WHERE active=true;"), - ] diff --git a/core/migrations/0047_increment_version.py b/core/migrations/0047_increment_version.py deleted file mode 100644 index 3740abc00d..0000000000 --- a/core/migrations/0047_increment_version.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-31 18:04 - -from django.db import migrations - - -def update_version(apps, schema): - Constants = apps.get_model("core", "Constants") - version = Constants.objects.get(key="version") - version.value = "24.2.1" - version.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0046_repository_coverage_enabled"), - ] - - operations = [migrations.RunPython(update_version)] diff --git a/core/migrations/0048_increment_version.py b/core/migrations/0048_increment_version.py deleted file mode 100644 index 932c80b62a..0000000000 --- a/core/migrations/0048_increment_version.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.11 on 2024-04-01 19:36 - -from django.db import migrations - - -def update_version(apps, schema): - Constants = apps.get_model("core", "Constants") - version = Constants.objects.get(key="version") - version.value = "24.4.1" - version.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("core", "0047_increment_version"), - ] - - operations = [migrations.RunPython(update_version)] diff --git a/core/migrations/__init__.py b/core/migrations/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/core/models.py b/core/models.py index 7c63f11ab9..3d4dfa9e16 100644 --- a/core/models.py +++ b/core/models.py @@ -1,2 +1 @@ from shared.django_apps.core.models import * -from shared.django_apps.core.models import _gen_image_token # noqa: F401 diff --git a/legacy_migrations/migrations/0001_initial.py b/legacy_migrations/migrations/0001_initial.py deleted file mode 100644 index ba2e60e085..0000000000 --- a/legacy_migrations/migrations/0001_initial.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 3.1.6 on 2021-03-15 20:15 - -from django.conf import settings # noqa: F401 -from django.db import migrations - -from .legacy_sql.main.main import run_sql as main_run_sql -from .legacy_sql.upgrades.main import run_sql as upgrade_run_sql - -BASE_VERSION = "base" - - -def forwards_func(apps, schema_editor): - Version = apps.get_model("core", "Version") - - schema_editor.execute("create table if not exists version (version text);") - - db_version = Version.objects.first() - current_version = db_version.version if db_version else BASE_VERSION - - if current_version == BASE_VERSION: - main_run_sql(schema_editor) - return - - upgrade_run_sql(schema_editor, current_version) - - -class Migration(migrations.Migration): - dependencies = [("core", "0001_initial")] - - operations = [migrations.RunPython(forwards_func)] diff --git a/legacy_migrations/migrations/0002_yaml_history_table.py b/legacy_migrations/migrations/0002_yaml_history_table.py deleted file mode 100644 index 2157b57cfd..0000000000 --- a/legacy_migrations/migrations/0002_yaml_history_table.py +++ /dev/null @@ -1,95 +0,0 @@ -# Generated by Django 3.2.12 on 2022-04-19 20:22 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - initial = True - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("legacy_migrations", "0001_initial"), - ] - - operations = [ - migrations.SeparateDatabaseAndState( - database_operations=[ - migrations.RunSQL( - sql=""" - create table if not exists yaml_history - ( - id serial primary key, - ownerid integer not null - references owners - on delete cascade, - timestamp timestamp with time zone not null, - author integer - references owners - on delete cascade, - message text, - source text not null, - diff text - ); - """, - reverse_sql="drop table yaml_history;", - ), - migrations.RunSQL( - sql=""" - create index if not exists yaml_history_ownerid_timestamp - on yaml_history (ownerid, timestamp); - """, - reverse_sql="drop index if exists yaml_history_ownerid_timestamp;", - ), - ], - state_operations=[ - migrations.CreateModel( - name="YamlHistory", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("timestamp", models.DateTimeField()), - ("message", models.TextField(blank=True, null=True)), - ("source", models.TextField()), - ("diff", models.TextField(null=True)), - ( - "author", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="authors", - db_column="author", - to="codecov_auth.owner", - ), - ), - ( - "ownerid", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="ownerids", - db_column="ownerid", - to="codecov_auth.owner", - ), - ), - ], - options={ - "db_table": "yaml_history", - }, - ), - migrations.AddIndex( - model_name="yamlhistory", - index=models.Index( - fields=["ownerid", "timestamp"], - name="yaml_histor_ownerid_74e79b_idx", - ), - ), - ], - ) - ] diff --git a/legacy_migrations/migrations/0003_auto_20230120_1837.py b/legacy_migrations/migrations/0003_auto_20230120_1837.py deleted file mode 100644 index 5e492a2d5d..0000000000 --- a/legacy_migrations/migrations/0003_auto_20230120_1837.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 3.2.12 on 2023-01-20 18:37 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("legacy_migrations", "0002_yaml_history_table"), - ] - - # These 2 triggers were wrong in the database and did not match what is found - # in the codebase. They were casting the values to ::text types which was breaking - # the case-insensitive comparisons of ::citext. These migrations just drop and - # recreate the triggers exactly as they appear in the `legacy_sql` files. - - operations = [ - migrations.RunSQL( - """ - drop trigger owners_before_update on owners; - - create trigger owners_before_update before update on owners - for each row - when (new.username is not null and new.username is distinct from old.username) - execute procedure owners_before_insert_or_update(); - """ - ), - migrations.RunSQL( - """ - drop trigger repos_before_update on repos; - - create trigger repos_before_update before update on repos - for each row - when (new.name is not null and new.name is distinct from old.name) - execute procedure repos_before_insert_or_update(); - """ - ), - ] diff --git a/legacy_migrations/migrations/0004_auto_20231024_1937.py b/legacy_migrations/migrations/0004_auto_20231024_1937.py deleted file mode 100644 index 5257083c46..0000000000 --- a/legacy_migrations/migrations/0004_auto_20231024_1937.py +++ /dev/null @@ -1,77 +0,0 @@ -# Generated by Django 4.2.3 on 2023-10-24 19:37 - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRunSQL - -# from `legacy_migrations/migrations/legacy_sql/main/triggers/commits.py` -original_function = """ -create or replace function commits_insert_pr_branch() returns trigger as $$ -begin - if new.pullid is not null and new.merged is not true then - begin - insert into pulls (repoid, pullid, author, head) - values (new.repoid, new.pullid, new.author, new.commitid); - exception when unique_violation then - end; - end if; - - if new.branch is not null then - begin - insert into branches (repoid, updatestamp, branch, authors, head) - values (new.repoid, new.timestamp, - new.branch, - case when new.author is not null then array[new.author] else null end, - new.commitid); - exception when unique_violation then - end; - end if; - - update repos - set updatestamp=now() - where repoid=new.repoid; - - return null; -end; -$$ language plpgsql; -""" - -# we're removing the `update repos` part since it can be very slow -replacement_function = """ -create or replace function commits_insert_pr_branch() returns trigger as $$ -begin - if new.pullid is not null and new.merged is not true then - begin - insert into pulls (repoid, pullid, author, head) - values (new.repoid, new.pullid, new.author, new.commitid); - exception when unique_violation then - end; - end if; - - if new.branch is not null then - begin - insert into branches (repoid, updatestamp, branch, authors, head) - values (new.repoid, new.timestamp, - new.branch, - case when new.author is not null then array[new.author] else null end, - new.commitid); - exception when unique_violation then - end; - end if; - - return null; -end; -$$ language plpgsql; -""" - - -class Migration(migrations.Migration): - dependencies = [ - ("legacy_migrations", "0003_auto_20230120_1837"), - ] - - operations = [ - RiskyRunSQL( - replacement_function, - reverse_sql=original_function, - ), - ] diff --git a/legacy_migrations/migrations/__init__.py b/legacy_migrations/migrations/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/legacy_migrations/migrations/legacy_sql/main/__init__.py b/legacy_migrations/migrations/legacy_sql/main/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/__init__.py b/legacy_migrations/migrations/legacy_sql/main/functions/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/aggregates.py b/legacy_migrations/migrations/legacy_sql/main/functions/aggregates.py deleted file mode 100644 index 9422991852..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/aggregates.py +++ /dev/null @@ -1,71 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - drop function if exists _pop_first_as_json(jsonb[]) cascade; - drop function if exists _max_coverage(jsonb[]) cascade; - drop function if exists _min_coverage(jsonb[]) cascade; - - create or replace function _pop_first_as_json(jsonb[]) returns jsonb as $$ - select $1[1]::jsonb; - $$ language sql immutable; - - - create or replace function _max_coverage(jsonb[], jsonb) returns jsonb[] as $$ - select case when $1 is null then array[$2] - when ($1[1]->>'c')::numeric > ($2->>'c')::numeric then $1 - else array[$2] end; - $$ language sql immutable; - - - create aggregate max_coverage(jsonb) ( - SFUNC = _max_coverage, - STYPE = jsonb[], - FINALFUNC = _pop_first_as_json - ); - - - create or replace function _min_coverage(jsonb[], jsonb) returns jsonb[] as $$ - select case when $1 is null then array[$2] - when ($1[1]->>'c')::numeric < ($2->>'c')::numeric then $1 - else array[$2] end; - $$ language sql immutable; - - - create aggregate min_coverage(jsonb) ( - SFUNC = _min_coverage, - STYPE = jsonb[], - FINALFUNC = _pop_first_as_json - ); - - - create or replace function ratio(int, int) returns text as $$ - select case when $2 = 0 then '0' else round(($1::numeric/$2::numeric)*100.0, 5)::text end; - $$ language sql immutable; - - - create or replace function _agg_report_totals(text[], jsonb) returns text[] as $$ - -- fnhmpcbdMs - select case when $1 is null - then array[$2->>0, $2->>1, $2->>2, $2->>3, - $2->>4, $2->>5, $2->>6, $2->>7, - $2->>8, $2->>9] - else array[($1[1]::int + ($2->>0)::int)::text, - ($1[2]::int + ($2->>1)::int)::text, - ($1[3]::int + ($2->>2)::int)::text, - ($1[4]::int + ($2->>3)::int)::text, - ($1[5]::int + ($2->>4)::int)::text, - ratio(($1[3]::int + ($2->>2)::int), ($1[2]::int + ($2->>1)::int)), - ($1[7]::int + ($2->>6)::int)::text, - ($1[8]::int + ($2->>7)::int)::text, - ($1[9]::int + ($2->>8)::int)::text, - ($1[10]::int + ($2->>9)::int)::text] end; - $$ language sql immutable; - - - create aggregate agg_totals(jsonb) ( - SFUNC = _agg_report_totals, - STYPE = text[] - ); - - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/array_append_unique.py b/legacy_migrations/migrations/legacy_sql/main/functions/array_append_unique.py deleted file mode 100644 index 85e6b7adca..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/array_append_unique.py +++ /dev/null @@ -1,11 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function array_append_unique(anyarray, anyelement) returns anyarray as $$ - select case when $2 is null - then $1 - else array_remove($1, $2) || array[$2] - end; - $$ language sql immutable; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/coverage.py b/legacy_migrations/migrations/legacy_sql/main/functions/coverage.py deleted file mode 100644 index 4d3b737668..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/coverage.py +++ /dev/null @@ -1,23 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function get_coverage(service, citext, citext, citext default null) returns jsonb as $$ - -- floor is temporary here - with d as ( - select floor((c.totals->>'c')::numeric) as c, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as r, - case when r.private then r.image_token else null end as t - from repos r - inner join owners o using (ownerid) - left join branches b using (repoid) - inner join commits c on b.repoid=c.repoid and c.commitid=b.head - where o.service = $1 - and o.username = $2 - and r.name = $3 - and b.branch = coalesce($4, r.branch) - limit 1 - ) select to_jsonb(d) from d; - $$ language sql stable; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_access_token.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_access_token.py deleted file mode 100644 index 9f0cd688cf..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_access_token.py +++ /dev/null @@ -1,14 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function get_access_token(int) returns jsonb as $$ - with data as ( - select ownerid, oauth_token, username - from owners o - where ownerid = $1 - and oauth_token is not null - limit 1 - ) select to_jsonb(data) from data; - $$ language sql stable strict; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_author.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_author.py deleted file mode 100644 index 1cd0686793..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_author.py +++ /dev/null @@ -1,13 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function get_author(int) returns jsonb as $$ - with data as ( - select service, service_id, username, email, name - from owners - where ownerid=$1 - limit 1 - ) select to_jsonb(data) from data; - $$ language sql stable strict; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_commit.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_commit.py deleted file mode 100644 index ffa3633f9f..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_commit.py +++ /dev/null @@ -1,139 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function get_commitid_from_short(int, text) returns text as $$ - select commitid - from commits - where repoid = $1 - and commitid like $2||'%%'; - $$ language sql immutable; - - - -- pull - create or replace function get_tip_of_pull(int, int) returns text as $$ - select head - from pulls - where repoid = $1 - and pullid = $2 - limit 1; - $$ language sql stable; - - - -- tips - create or replace function get_tip(int, text) returns text as $$ - select case when char_length($2) = 40 then $2 - else coalesce((select head from branches where repoid=$1 and branch=$2 limit 1), - (select commitid from commits where repoid=$1 and commitid like $2||'%%' limit 1)) end - limit 1; - $$ language sql stable; - - - -- branch - create or replace function get_tip_of_branch(int, text) returns text as $$ - select head - from branches - where repoid = $1 - and branch = $2 - limit 1; - $$ language sql stable; - - - create or replace function get_commit_totals(int, text) returns jsonb as $$ - select totals - from commits - where repoid = $1 - and commitid = $2 - limit 1; - $$ language sql stable; - - - create or replace function get_commit_totals(int, text, text) returns jsonb as $$ - select report->'files'->$3->1 - from commits - where repoid = $1 - and commitid = $2 - limit 1; - $$ language sql stable; - - - create or replace function get_commit(repoid integer, _commitid text) returns jsonb as $$ - with d as ( - select timestamp, commitid, branch, pullid::text, parent, - ci_passed, updatestamp, message, deleted, totals, - get_author(author) as author, state, merged, - get_commit_totals($1, c.parent) as parent_totals, notified, - report - from commits c - where c.repoid = $1 - and commitid = (case when char_length(_commitid) < 40 then get_commitid_from_short($1, _commitid) else _commitid end) - limit 1 - ) select to_jsonb(d) from d; - $$ language sql stable; - - - create or replace function get_commit_minimum(int, text) returns jsonb as $$ - with d as ( - select timestamp, commitid, ci_passed, message, - get_author(author) as author, totals - from commits - where repoid = $1 - and commitid = $2 - limit 1 - ) select to_jsonb(d) from d; - $$ language sql stable; - - - create or replace function get_commit_on_branch(int, text) returns jsonb as $$ - select get_commit($1, head) - from branches - where repoid = $1 and branch = $2 - limit 1; - $$ language sql stable; - - - create or replace function find_parent_commit(_repoid int, - _this_commitid text, - _this_timestamp timestamp, - _parent_commitids text[], - _branch text, - _pullid int) returns text as $$ - declare commitid_ text default null; - begin - if array_length(_parent_commitids, 1) > 0 then - -- first: find a direct decendant - select commitid into commitid_ - from commits - where repoid = _repoid - and array[commitid] <@ _parent_commitids - limit 1; - end if; - - if commitid_ is null then - -- second: find latest on branch - select commitid into commitid_ - from commits - where repoid = _repoid - and branch = _branch - and pullid is not distinct from _pullid - and commitid != _this_commitid - and ci_passed - and deleted is not true - and timestamp < _this_timestamp - order by timestamp desc - limit 1; - - if commitid_ is null then - -- third: use pull base - select base into commitid_ - from pulls - where repoid = _repoid - and pullid = _pullid - limit 1; - end if; - end if; - - return commitid_; - end; - $$ language plpgsql stable; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_customer.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_customer.py deleted file mode 100644 index 4eeca2ede2..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_customer.py +++ /dev/null @@ -1,133 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function get_gitlab_root_group(int) returns jsonb as $$ - /* get root group by following parent_service_id to highest level */ - with recursive tree as ( - select o.service_id, - o.parent_service_id, - o.ownerid, - 1 as depth - from owners o - where o.ownerid = $1 - and o.service = 'gitlab' - and o.parent_service_id is not null - - union all - - select o.service_id, - o.parent_service_id, - o.ownerid, - depth + 1 as depth - from tree t - join owners o - on o.service_id = t.parent_service_id - /* avoid infinite loop in case of cycling (2 > 5 > 3 > 2 > 5...) up to Gitlab max subgroup depth of 20 */ - where depth <= 20 - ), data as ( - select t.ownerid, - t.service_id - from tree t - where t.parent_service_id is null - ) - select to_jsonb(data) from data limit 1; - $$ language sql stable strict; - - create or replace function get_gitlab_repos_activated(int, text) returns int as $$ - declare _repos_activated int; - declare _decendents_owner_ids int[]; - begin - /* get array of owner ids for all subgroups under this group */ - select array( - with recursive tree as ( - /* seed the recursive query */ - select ownerid, - service_id, - array[]::text[] as ancestors_service_id, - 1 as depth - from owners - where parent_service_id is null - and service = 'gitlab' - and ownerid = $1 - - union all - - /* find the descendents */ - select owners.ownerid, - owners.service_id, - tree.ancestors_service_id || owners.parent_service_id, - depth + 1 as depth - from owners, tree - where owners.parent_service_id = tree.service_id - /* avoid infinite loop in case of cycling (2 > 5 > 3 > 2 > 5...) up to Gitlab max subgroup depth of 20 */ - and depth <= 20 - ) - select ownerid - from tree - where $2 = any(tree.ancestors_service_id) - ) into _decendents_owner_ids; - - /* get count of all repos that are active and private owned by this gitlab group and all of its subgroups */ - select count(*) into _repos_activated - from repos - where ownerid in (select unnest(array_append(_decendents_owner_ids, $1))) - and private - and activated; - - return _repos_activated; - end; - $$ language plpgsql stable; - - create or replace function get_repos_activated(int) returns int as $$ - declare _repos_activated int; - declare _service text; - declare _service_id text; - begin - select o.service, o.service_id into _service, _service_id - from owners o where o.ownerid = $1; - - if _service = 'gitlab' then - select get_gitlab_repos_activated($1, _service_id) into _repos_activated; - else - select count(*) into _repos_activated - from repos - where ownerid=$1 - and private - and activated; - end if; - - return _repos_activated; - end; - $$ language plpgsql stable; - - create or replace function get_customer(int) returns jsonb as $$ - with data as ( - select t.stripe_customer_id, - t.stripe_subscription_id, - t.ownerid::text, - t.service, - t.service_id, - t.plan_user_count, - t.plan_provider, - t.plan_auto_activate, - t.plan_activated_users, - t.plan, - t.email, - t.free, - t.did_trial, - t.invoice_details, - t.yaml, - t.student, - t.student_created_at, - t.student_updated_at, - b.username as bot_username, - get_users(t.admins) as admins, - get_repos_activated($1::int) as repos_activated - from owners t - LEFT JOIN owners b ON (b.ownerid = t.bot) - where t.ownerid = $1 - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable strict; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_graph_for.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_graph_for.py deleted file mode 100644 index 2cc54f7f10..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_graph_for.py +++ /dev/null @@ -1,240 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function sum_of_file_totals_filtering_sessionids(jsonb, int[]) returns text[] as $$ - -- sum totals for filtered flags - -- in [, , ], [1, 2] - -- out ( + ) = - with totals as ( - select $1->i as t from unnest($2) as i - ) select agg_totals(totals.t) from totals; - $$ language sql immutable; - - - create or replace function extract_totals(files jsonb, sessionids int[]) returns jsonb as $$ - -- return {"filename": , ...} - with files as ( - select case - when sessionids is not null then (select jsonb_agg(row(key, sum_of_file_totals_filtering_sessionids(value->2, sessionids))) from jsonb_each(files)) - else (select jsonb_agg(row(key, value->1)) from jsonb_each(files)) - end as data - ) select to_jsonb(data) from files; - $$ language sql immutable; - - - create or replace function list_sessionid_by_filtering_flags(sessions jsonb, flags text[]) returns int[] as $$ - -- return session index where flags overlap $1 - with indexes as ( - select (session.key)::int as key - from jsonb_each(sessions) as session - where (session.value->>'f')::text is not null - and flags <@ (select array_agg(trim(f::text, '"')) from jsonb_array_elements((session.value->'f')) f)::text[] - ) select array_agg(key) from indexes; - $$ language sql strict immutable; - - - create or replace function total_list_to_json(totals text[]) returns jsonb as $$ - select ('{"f":'||totals[1]||','|| - '"n":'||totals[2]||','|| - '"h":'||totals[3]||','|| - '"m":'||totals[4]||','|| - '"p":'||totals[5]||','|| - '"c":'||totals[6]||','|| - '"b":'||totals[7]||','|| - '"d":'||totals[8]||','|| - '"M":'||totals[9]||','|| - '"s":'||totals[10]||'}')::jsonb; - $$ language sql strict immutable; - - - create or replace function sum_session_totals(sessions jsonb, flags text[]) returns jsonb as $$ - -- sum totals for filtered flags - -- in {"0": {"t": }, "1": {"t": }, "2", {"t": }], [1, 2] - -- out ( + ) = - with totals as ( - select sessions->(i::text)->'t' as t from unnest(list_sessionid_by_filtering_flags(sessions, flags)) as i - ) select total_list_to_json(agg_totals(totals.t)) from totals; - $$ language sql strict immutable; - - - create or replace function get_graph_for_flare_pull(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, p.head as commitid, r.branch, - p.flare, - case when p.flare is null - then extract_totals(c.report->'files', list_sessionid_by_filtering_flags(c.report->'sessions', $4)) - else null - end as files_by_total, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join pulls p using (repoid) - inner join commits c on c.repoid = r.repoid and c.commitid = p.head - where r.repoid = $1 - and p.pullid = $2::int - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - - - create or replace function get_graph_for_flare_commit(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, c.commitid, r.branch, - extract_totals(c.report->'files', list_sessionid_by_filtering_flags(c.report->'sessions', $4)) as files_by_total, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join commits c using (repoid) - where r.repoid = $1 - and c.commitid = $2 - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - - - create or replace function get_graph_for_flare_branch(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, c.commitid, r.branch, - extract_totals(c.report->'files', list_sessionid_by_filtering_flags(c.report->'sessions', $4)) as files_by_total, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join branches b using (repoid) - inner join commits c on c.repoid = r.repoid and c.commitid = b.head - where r.repoid = $1 - and b.branch = case when $2 is null then r.branch else $2 end - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - - - create or replace function get_graph_for_totals_pull(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, r.branch, - p.base as base_commitid, - case when $4 is null - then (select totals from commits where repoid=p.repoid and commitid=p.base limit 1) - else (select sum_session_totals(report->'sessions', $4) - from commits - where repoid=$1 - and commitid=p.base - limit 1) - end as base_totals, - p.head as head_commitid, - case when $4 is null - then (select totals from commits where repoid=p.repoid and commitid=p.head limit 1) - else (select sum_session_totals(report->'sessions', $4) - from commits - where repoid=$1 - and commitid=p.head - limit 1) - end as head_totals, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join pulls p using (repoid) - where r.repoid = $1 - and p.pullid = $2::int - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - - - create or replace function get_graph_for_totals_commit(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, r.branch, - base.commitid as base_commitid, - case when $4 is null - then base.totals - else sum_session_totals(base.report->'sessions', $4) - end as base_totals, - head.commitid as head_commitid, - case when $4 is null - then head.totals - else sum_session_totals(head.report->'sessions', $4) - end as head_totals, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join commits head using (repoid) - left join commits base on base.repoid = r.repoid - and base.commitid = head.parent - where r.repoid = $1 - and head.commitid = $2 - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - - - create or replace function get_graph_for_totals_branch(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, r.branch, - base.commitid as base_commitid, - case when $4 is null - then base.totals - else sum_session_totals(base.report->'sessions', $4) - end as base_totals, - head.commitid as head_commitid, - case when $4 is null - then head.totals - else sum_session_totals(head.report->'sessions', $4) - end as head_totals, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join branches b using (repoid) - left join commits base on base.repoid = r.repoid - and base.commitid = b.base - inner join commits head on head.repoid = r.repoid - and head.commitid = b.head - where r.repoid = $1 - and b.branch = case when $2 is null then r.branch else $2 end - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - - - create or replace function get_graph_for_commits_pull(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, r.branch, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join pulls p using (repoid) - where r.repoid = $1 - and p.pullid = $2::int - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - - - create or replace function get_graph_for_commits_branch(int, text, text, text[]) returns jsonb as $$ - with data as ( - select r.repoid, r.service_id, r.branch, - coalesce((r.yaml->'coverage'->'range')::jsonb, - (o.yaml->'coverage'->'range')::jsonb) as coverage_range - from repos r - inner join owners o using (ownerid) - inner join branches b using (repoid) - where r.repoid = $1 - and b.branch = case when $2 is null then r.branch else $2 end - and (not r.private or r.image_token = $3) - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_ownerid.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_ownerid.py deleted file mode 100644 index 869f59cec0..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_ownerid.py +++ /dev/null @@ -1,93 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function get_ownerid_if_member(service, citext, int) returns int as $$ - select ownerid - from owners - where service=$1 - and username=$2::citext - and array[$3] <@ organizations - and private_access is true - limit 1; - $$ language sql stable strict; - - - create or replace function get_ownerid(service, text, citext, text, text) returns int as $$ - declare _ownerid int; - begin - - select ownerid into _ownerid - from owners - where service=$1 - and service_id=$2 - limit 1; - - if not found and $2 is not null then - insert into owners (service, service_id, username, name, email) - values ($1, $2, $3::citext, $4, $5) - returning ownerid into _ownerid; - end if; - - return _ownerid; - end; - $$ language plpgsql; - - - create or replace function try_to_auto_activate(int, int) returns boolean as $$ - update owners - set plan_activated_users = ( - case when coalesce(array_length(plan_activated_users, 1), 0) < plan_user_count -- we have credits - then array_append_unique(plan_activated_users, $2) -- add user - else plan_activated_users - end) - where ownerid=$1 - returning (plan_activated_users @> array[$2]); - $$ language sql volatile strict; - - - create or replace function get_owner(service, citext) returns jsonb as $$ - with data as ( - select service_id, service, ownerid::text, username, avatar_url, - updatestamp, plan, name, integration_id, free, - plan_activated_users, plan_auto_activate, plan_user_count - from owners - where service=$1 - and username=$2::citext - limit 1 - ) select to_jsonb(data) - from data - limit 1; - $$ language sql stable strict; - - - create or replace function get_teams(service, integer[]) returns jsonb as $$ - with data as ( - select service_id, service, ownerid::text, username, name - from owners - where service=$1 - and array[ownerid] <@ $2 - ) select jsonb_agg(data) from data; - $$ language sql stable strict; - - - create or replace function get_or_create_owner(service, text, text, text, text) returns int as $$ - declare _ownerid int; - begin - update owners - set username = $3, avatar_url = $4, parent_service_id = $5 - where service = $1 - and service_id = $2 - returning ownerid into _ownerid; - - if not found then - insert into owners (service, service_id, username, avatar_url, parent_service_id) - values ($1, $2, $3, $4, $5) - returning ownerid into _ownerid; - end if; - - return _ownerid; - - end; - $$ language plpgsql volatile; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_repo.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_repo.py deleted file mode 100644 index 2da4965f73..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_repo.py +++ /dev/null @@ -1,79 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - -- used for app/tasks - create or replace function get_repo(int) returns jsonb as $$ - with d as (select o.service, o.username, o.service_id as owner_service_id, r.ownerid::text, - r.name, r.repoid::text, r.service_id, r.updatestamp, - r.branch, r.private, hookid, image_token, b.username as bot_username, - r.yaml, o.yaml as org_yaml, r.using_integration, o.plan, - (r.cache->>'yaml') as _yaml_location, - case when r.using_integration then o.integration_id else null end as integration_id, - get_access_token(coalesce(r.bot, o.bot, o.ownerid)) as token, - case when private and activated is not true and forkid is not null - then (select rr.activated from repos rr where rr.repoid = r.forkid limit 1) - else activated end as activated - from repos r - inner join owners o using (ownerid) - left join owners b ON (r.bot=b.ownerid) - where r.repoid = $1 - limit 1) select to_jsonb(d) from d; - $$ language sql stable strict; - - - -- used for app/handlers - create or replace function get_repo(int, citext) returns jsonb as $$ - with repo as ( - select r.yaml, r.name, "language", repoid::text, r.private, r.deleted, r.active, r.cache, b.username as bot_username, - r.branch, r.service_id, r.updatestamp, upload_token, image_token, hookid, using_integration, - case when private and activated is not true and forkid is not null - then (select rr.activated from repos rr where rr.repoid = r.forkid limit 1) - else activated end as activated - from repos r - left join owners b ON (r.bot=b.ownerid) - where r.ownerid = $1 and r.name = $2::citext - limit 1 - ) select to_jsonb(repo) from repo; - $$ language sql stable; - - - -- used for app/handlers/upload - create or replace function get_repo_by_token(uuid) returns jsonb as $$ - with d as ( - select get_repo(r.repoid) as repo, o.service - from repos r - inner join owners o using (ownerid) - where r.upload_token = $1 - limit 1 - ) select to_jsonb(d) from d limit 1; - $$ language sql stable; - - - -- used for app/handlers/teams - create or replace function get_repos(int, int default 0, int default 5) returns jsonb as $$ - with _repos as ( - select private, cache, name, updatestamp, upload_token, branch, - language, repoid::text, get_repo(forkid) as fork, yaml, - case when private and activated is not true and forkid is not null - then (select rr.activated from repos rr where rr.repoid = r.forkid limit 1) - else activated end as activated - from repos r - where ownerid = $1 - and active - offset $2 - limit $3 - ) select coalesce(jsonb_agg(_repos), '[]'::jsonb) from _repos; - $$ language sql stable; - - - create or replace function get_repoid(service, citext, citext) returns int as $$ - select repoid - from repos r - inner join owners o using (ownerid) - where o.service = $1 - and o.username = $2::citext - and r.name = $3::citext - limit 1 - $$ language sql stable; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/get_user.py b/legacy_migrations/migrations/legacy_sql/main/functions/get_user.py deleted file mode 100644 index abdcba6bc1..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/get_user.py +++ /dev/null @@ -1,33 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function get_user(int) returns jsonb as $$ - with data as ( - select ownerid::text, private_access, staff, service, service_id, - username, organizations, avatar_url, - oauth_token, plan, permission, - free, email, name, createstamp - from owners - where ownerid=$1 - limit 1 - ) select to_jsonb(data) from data; - $$ language sql stable; - - - create or replace function get_username(int) returns citext as $$ - select username from owners where ownerid=$1 limit 1; - $$ language sql stable strict; - - - create or replace function get_users(int[]) returns jsonb as $$ - with data as ( - select service, service_id::text, ownerid::text, username, name, email, avatar_url - from owners - where array[ownerid] <@ $1 - limit array_length($1, 1) - ) select jsonb_agg(data) - from data - limit array_length($1, 1); - $$ language sql stable strict; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/insert_commit.py b/legacy_migrations/migrations/legacy_sql/main/functions/insert_commit.py deleted file mode 100644 index 7bafbd6e32..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/insert_commit.py +++ /dev/null @@ -1,29 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function insert_commit(int, text, text, int) returns void as $$ - begin - - update commits - set state='pending' - where repoid = $1 - and commitid = $2; - - if not found then - insert into commits (repoid, commitid, branch, pullid, merged, timestamp, state) - values ($1, $2, $3, $4, case when $4 is not null then false else null end, now(), 'pending') - on conflict (repoid, commitid) do update - set branch=$3, pullid=$4, - merged=(case when $4 is not null then false else null end), - state='pending'; - end if; - - update repos - set active=true, deleted=false, updatestamp=now() - where repoid = $1 - and (active is not true or deleted is true); - - end; - $$ language plpgsql volatile; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/main.py b/legacy_migrations/migrations/legacy_sql/main/functions/main.py deleted file mode 100644 index f404a7902a..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/main.py +++ /dev/null @@ -1,33 +0,0 @@ -from .aggregates import run_sql as aggregates_run_sql -from .array_append_unique import run_sql as array_append_unique_run_sql -from .coverage import run_sql as coverage_run_sql -from .get_access_token import run_sql as get_access_token_run_sql -from .get_author import run_sql as get_author_run_sql -from .get_commit import run_sql as get_commit_run_sql -from .get_customer import run_sql as get_customer_run_sql -from .get_graph_for import run_sql as get_graph_for_run_sql -from .get_ownerid import run_sql as get_ownerid_run_sql -from .get_repo import run_sql as get_repo_run_sql -from .get_user import run_sql as get_user_run_sql -from .insert_commit import run_sql as insert_commit_run_sql -from .refresh_repos import run_sql as refresh_repos_run_sql -from .update_json import run_sql as update_json_run_sql -from .verify_session import run_sql as verify_session_run_sql - - -def run_sql(schema_editor): - aggregates_run_sql(schema_editor) - update_json_run_sql(schema_editor) - get_author_run_sql(schema_editor) - array_append_unique_run_sql(schema_editor) - coverage_run_sql(schema_editor) - get_access_token_run_sql(schema_editor) - get_repo_run_sql(schema_editor) - get_user_run_sql(schema_editor) - get_customer_run_sql(schema_editor) - get_commit_run_sql(schema_editor) - get_ownerid_run_sql(schema_editor) - verify_session_run_sql(schema_editor) - refresh_repos_run_sql(schema_editor) - insert_commit_run_sql(schema_editor) - get_graph_for_run_sql(schema_editor) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/refresh_repos.py b/legacy_migrations/migrations/legacy_sql/main/functions/refresh_repos.py deleted file mode 100644 index 42105e8d38..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/refresh_repos.py +++ /dev/null @@ -1,160 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function refresh_teams(service, jsonb) returns int[] as $$ - declare ownerids int[]; - declare _ownerid int; - declare _team record; - begin - for _team in select d from jsonb_array_elements($2) d loop - update owners o - set username = (_team.d->>'username')::citext, - name = (_team.d->>'name')::text, - email = (_team.d->>'email')::text, - avatar_url = (_team.d->>'avatar_url')::text, - parent_service_id = (_team.d->>'parent_id')::text, - updatestamp = now() - where service = $1 - and service_id = (_team.d->>'id')::text - returning ownerid into _ownerid; - - if not found then - insert into owners (service, service_id, username, name, email, avatar_url, parent_service_id) - values ($1, - (_team.d->>'id')::text, - (_team.d->>'username')::citext, - (_team.d->>'name')::text, - (_team.d->>'email')::text, - (_team.d->>'avatar_url')::text, - (_team.d->>'parent_id')::text - ) - returning ownerid into _ownerid; - end if; - - select array_append(ownerids, _ownerid) into ownerids; - - end loop; - - return ownerids; - - end; - $$ language plpgsql volatile strict; - - - create or replace function refresh_repos(service, jsonb, int, boolean) returns text[] as $$ - declare _ text; - declare _branch text; - declare _forkid int; - declare _previous_ownerid int; - declare _ownerid int; - declare _repo record; - declare _repoid int; - declare _bot int; - declare repos text[]; - begin - - for _repo in select d from jsonb_array_elements($2) d loop - - select r.ownerid into _previous_ownerid - from repos r - inner join owners o using (ownerid) - where o.service = $1 - and r.service_id = (_repo.d->'repo'->>'service_id')::text - limit 1; - - -- owner - -- ===== - -- its import to check all three below. otherwise update the record. - select ownerid, bot, (yaml->'codecov'->>'branch')::text - into _ownerid, _bot, _branch - from owners - where service = $1 - and service_id = (_repo.d->'owner'->>'service_id')::text - and username = (_repo.d->'owner'->>'username')::citext - limit 1; - - if not found then - update owners - set username = (_repo.d->'owner'->>'username')::citext, - updatestamp = now() - where service = $1 - and service_id = (_repo.d->'owner'->>'service_id')::text - returning ownerid, bot, (yaml->'codecov'->>'branch')::text - into _ownerid, _bot, _branch; - - if not found then - insert into owners (service, service_id, username, bot) - values ($1, (_repo.d->'owner'->>'service_id')::text, (_repo.d->'owner'->>'username')::citext, $3) - returning ownerid, bot into _ownerid, _bot; - end if; - - end if; - - -- fork - -- ==== - if (_repo.d->'repo'->>'fork') is not null then - -- converts fork into array - select refresh_repos($1, (select jsonb_agg(d.d::jsonb)::jsonb - from (select (_repo.d->'repo'->>'fork')::jsonb d limit 1) d - limit 1), null, null) - into _ - limit 1; - - -- get owner - select r.repoid into _forkid - from repos r - inner join owners o using (ownerid) - where o.service = $1 - and o.username = (_repo.d->'repo'->'fork'->'owner'->>'username')::citext - and r.name = (_repo.d->'repo'->'fork'->'repo'->>'name')::citext - limit 1; - else - _forkid := null; - end if; - - -- update repo - -- =========== - if _previous_ownerid is not null then - -- repo already existed with this service_id, update it - update repos set - private = ((_repo.d)->'repo'->>'private')::boolean, - forkid = _forkid, - language = ((_repo.d)->'repo'->>'language')::languages, - ownerid = _ownerid, - using_integration=(using_integration or $4), - name = (_repo.d->'repo'->>'name')::citext, - deleted = false, - updatestamp=now() - where ownerid = _previous_ownerid - and service_id = (_repo.d->'repo'->>'service_id')::text - returning repoid - into _repoid; - - -- new repo - -- ======== - else - insert into repos (service_id, ownerid, private, forkid, name, branch, language, using_integration) - values ((_repo.d->'repo'->>'service_id')::text, - _ownerid, - (_repo.d->'repo'->>'private')::boolean, - _forkid, - (_repo.d->'repo'->>'name')::citext, - coalesce(_branch, (_repo.d->'repo'->>'branch')), - (_repo.d->'repo'->>'language')::languages, - $4) - returning repoid into _repoid; - - end if; - - -- return private repoids - if (_repo.d->'repo'->>'private')::boolean then - repos = array_append(repos, _repoid::text); - end if; - - end loop; - - return repos; - end; - $$ language plpgsql volatile; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/update_json.py b/legacy_migrations/migrations/legacy_sql/main/functions/update_json.py deleted file mode 100644 index 2e9dfe6fd5..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/update_json.py +++ /dev/null @@ -1,57 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function add_key_to_json(jsonb, text, jsonb) returns jsonb as $$ - select case when $1 is null and $3 is null then ('{"'||$2||'":null}')::jsonb - when $1 is null or $1::text = '{}' then ('{"'||$2||'":'||$3||'}')::jsonb - when $3 is null then (left($1::text, -1)||',"'||$2||'":null}')::jsonb - else (left($1::text, -1)||',"'||$2||'":'||$3::text||'}')::jsonb end; - $$ language sql stable; - - - create or replace function add_key_to_json(jsonb, text, integer) returns jsonb as $$ - select case when $1 is null and $3 is null then ('{"'||$2||'":null}')::jsonb - when $1 is null or $1::text = '{}' then ('{"'||$2||'":'||$3||'}')::jsonb - when $3 is null then (left($1::text, -1)||',"'||$2||'":null}')::jsonb - else (left($1::text, -1)||',"'||$2||'":'||$3::text||'}')::jsonb end; - $$ language sql stable; - - - create or replace function add_key_to_json(jsonb, text, text) returns jsonb as $$ - select case when $1 is null and $3 is null then ('{"'||$2||'":null}')::jsonb - when $1 is null or $1::text = '{}' then ('{"'||$2||'":"'||$3||'"}')::jsonb - when $3 is null then (left($1::text, -1)||',"'||$2||'":null}')::jsonb - else (left($1::text, -1)||',"'||$2||'":"'||$3::text||'"}')::jsonb end; - $$ language sql stable; - - - create or replace function remove_key_from_json(jsonb, text) returns jsonb as $$ - with drop_key as ( - select key, value::text - from jsonb_each($1::jsonb) - where key != $2::text and value is not null - ) select ('{'||array_to_string((select array_agg('"'||key||'":'||value) from drop_key), ',')||'}')::jsonb; - $$ language sql stable; - - - create or replace function update_json(jsonb, text, jsonb) returns jsonb as $$ - select case when $1 is not null then add_key_to_json(coalesce(remove_key_from_json($1, $2), '{}'::jsonb), $2, $3) - when $3 is null then ('{"'||$2||'":null}')::jsonb - else ('{"'||$2||'":'||coalesce($3::text, 'null')::text||'}')::jsonb end; - $$ language sql stable; - - - create or replace function update_json(jsonb, text, integer) returns jsonb as $$ - select case when $1 is not null then add_key_to_json(coalesce(remove_key_from_json($1, $2), '{}'::jsonb), $2, $3) - when $3 is null then ('{"'||$2||'":null}')::jsonb - else ('{"'||$2||'":'||$3::text||'}')::jsonb end; - $$ language sql stable; - - - create or replace function update_json(jsonb, text, text) returns jsonb as $$ - select case when $1 is not null then add_key_to_json(coalesce(remove_key_from_json($1, $2), '{}'::jsonb), $2, $3) - when $3 is null then ('{"'||$2||'":null}')::jsonb - else ('{"'||$2||'":"'||$3||'"}')::jsonb end; - $$ language sql stable; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/functions/verify_session.py b/legacy_migrations/migrations/legacy_sql/main/functions/verify_session.py deleted file mode 100644 index d743f1e27a..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/functions/verify_session.py +++ /dev/null @@ -1,15 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function verify_session(text, text, uuid, sessiontype) returns jsonb as $$ - -- try any members - update sessions - set lastseen = now(), - ip = $1, - useragent = $2 - where token = $3 - and type = $4 - returning get_user(ownerid); - $$ language sql volatile; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/main.py b/legacy_migrations/migrations/legacy_sql/main/main.py deleted file mode 100644 index 2164ad1a8a..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/main.py +++ /dev/null @@ -1,24 +0,0 @@ -from .functions.main import run_sql as functions_run_sql -from .tables.main import run_sql as tables_run_sql -from .triggers.main import run_sql as triggers_run_sql -from .types import run_sql as types_run_sql - - -def run_sql(schema_editor): - schema_editor.execute( - """ - create extension if not exists "uuid-ossp"; - create extension if not exists "citext"; - - create table if not exists version (version text); - - create or replace function random_string(int) returns char as $$ - select string_agg(((string_to_array('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', null))[floor(random()*62)+1])::text, '') - from generate_series(1, $1); - $$ language sql; - """ - ) - types_run_sql(schema_editor) - tables_run_sql(schema_editor) - functions_run_sql(schema_editor) - triggers_run_sql(schema_editor) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/__init__.py b/legacy_migrations/migrations/legacy_sql/main/tables/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/branches.py b/legacy_migrations/migrations/legacy_sql/main/tables/branches.py deleted file mode 100644 index e34e535f63..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/branches.py +++ /dev/null @@ -1,17 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create table branches( - repoid int references repos on delete cascade not null, - updatestamp timestamptz not null, - branch text not null, - base text, - head text not null, - authors int[] - ); - - create index branches_repoid on branches (repoid); - - create unique index branches_repoid_branch on branches (repoid, branch); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/commit_notifications.py b/legacy_migrations/migrations/legacy_sql/main/tables/commit_notifications.py deleted file mode 100644 index 975dc80c64..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/commit_notifications.py +++ /dev/null @@ -1,17 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create table commit_notifications( - id bigserial primary key, - commit_id bigint references commits(id) on delete cascade not null, - notification_type notifications not null, - decoration_type decorations, - created_at timestamp, - updated_at timestamp, - state commit_notification_state, - CONSTRAINT commit_notifications_commit_id_notification_type UNIQUE(commit_id, notification_type) - ); - - create index commit_notifications_commit_id on commit_notifications (commit_id); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/commits.py b/legacy_migrations/migrations/legacy_sql/main/tables/commits.py deleted file mode 100644 index 8c2d80becc..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/commits.py +++ /dev/null @@ -1,31 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create table commits( - commitid text not null, - id bigserial primary key, - timestamp timestamp not null, - repoid int references repos on delete cascade not null, - branch text, - pullid int, - author int references owners on delete set null, - ci_passed boolean, - updatestamp timestamp, - message text, - state commit_state, - merged boolean, - deleted boolean, - notified boolean, - version smallint, -- will be removed after migrations - parent text, - totals jsonb, - report jsonb - ); - - create unique index commits_repoid_commitid on commits (repoid, commitid); - - create index commits_repoid_timestamp_desc on commits (repoid, timestamp desc); - - create index commits_on_pull on commits (repoid, pullid) where deleted is not true; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/main.py b/legacy_migrations/migrations/legacy_sql/main/tables/main.py deleted file mode 100644 index d1cc1224d9..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/main.py +++ /dev/null @@ -1,21 +0,0 @@ -from .branches import run_sql as branches_run_sql -from .commit_notifications import run_sql as commit_notifications_run_sql -from .commits import run_sql as commits_run_sql -from .owners import run_sql as owners_run_sql -from .pulls import run_sql as pulls_run_sql -from .reports import run_sql as reports_run_sql -from .repos import run_sql as repos_run_sql -from .sessions import run_sql as sessions_run_sql -from .users import run_sql as users_run_sql - - -def run_sql(schema_editor): - users_run_sql(schema_editor) - owners_run_sql(schema_editor) - sessions_run_sql(schema_editor) - repos_run_sql(schema_editor) - branches_run_sql(schema_editor) - pulls_run_sql(schema_editor) - commits_run_sql(schema_editor) - commit_notifications_run_sql(schema_editor) - reports_run_sql(schema_editor) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/owners.py b/legacy_migrations/migrations/legacy_sql/main/tables/owners.py deleted file mode 100644 index 346e65bb92..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/owners.py +++ /dev/null @@ -1,51 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create table owners( - ownerid serial primary key, - service service not null, - username citext, - email text, - name text, - oauth_token text, - stripe_customer_id text, - stripe_subscription_id text, - createstamp timestamptz, - service_id text not null, - private_access boolean, - staff boolean default false, -- codecov staff - cache jsonb, -- {"stats": {}} - plan plans default null, - plan_provider plan_providers, - plan_user_count smallint, - plan_auto_activate boolean, - plan_activated_users int[], - did_trial boolean, - free smallint default 0 not null, - invoice_details text, - student boolean default false not null, - student_created_at timestamp default null, - student_updated_at timestamp default null, - -- bot int, SEE BELOW - delinquent boolean, - yaml jsonb, - updatestamp timestamp, - organizations int[], -- what teams I'm member of - admins int[], -- who can edit my billing - integration_id int, -- github integration id - permission int[] - ); - - create unique index owner_service_username on owners (service, username); - - create unique index owner_service_ids on owners (service, service_id); - - alter table owners add column bot int references owners on delete set null; - - alter table owners add column avatar_url text; - - alter table owners add column parent_service_id text; - - alter table owners add column root_parent_service_id text; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/pulls.py b/legacy_migrations/migrations/legacy_sql/main/tables/pulls.py deleted file mode 100644 index ca326f120a..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/pulls.py +++ /dev/null @@ -1,24 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create table pulls( - repoid int references repos on delete cascade not null, - pullid int not null, - issueid int, -- gitlab - updatestamp timestamp, - state pull_state not null default 'open', - title text, - base text, - compared_to text, - head text, - commentid text, - diff jsonb, - flare jsonb, -- only when pull is open - author int references owners on delete set null - ); - - create unique index pulls_repoid_pullid on pulls (repoid, pullid); - - create index pulls_repoid_state_open on pulls (repoid) where state = 'open'; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/reports.py b/legacy_migrations/migrations/legacy_sql/main/tables/reports.py deleted file mode 100644 index 84291c6439..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/reports.py +++ /dev/null @@ -1,142 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - -- EOF - -- - -- Create model CommitReport - -- - CREATE TABLE "reports_commitreport" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "commit_id" bigint NOT NULL - ); - -- - -- Create model ReportDetails - -- - CREATE TABLE "reports_reportdetails" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "files_array" jsonb[] NOT NULL, - "report_id" bigint NOT NULL UNIQUE - ); - -- - -- Create model ReportLevelTotals - -- - CREATE TABLE "reports_reportleveltotals" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "branches" integer NOT NULL, - "coverage" numeric(7, 2) NOT NULL, - "hits" integer NOT NULL, - "lines" integer NOT NULL, - "methods" integer NOT NULL, - "misses" integer NOT NULL, - "partials" integer NOT NULL, - "files" integer NOT NULL, - "report_id" bigint NOT NULL UNIQUE - ); - -- - -- Create model ReportSession - -- - CREATE TABLE "reports_upload" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "build_code" text NULL, - "build_url" text NULL, - "env" jsonb NULL, - "job_code" text NULL, - "name" varchar(100) NULL, - "provider" varchar(50) NULL, - "state" varchar(100) NOT NULL, - "storage_path" text NOT NULL, - "order_number" integer NULL, - "upload_extras" jsonb NOT NULL, - "upload_type" varchar(100) NOT NULL - ); - -- - -- Create model ReportSessionError - -- - CREATE TABLE "reports_uploaderror" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "error_code" varchar(100) NOT NULL, - "error_params" jsonb NOT NULL, - "upload_id" bigint NOT NULL - ); - -- - -- Create model ReportSessionFlagMembership - -- - CREATE TABLE "reports_uploadflagmembership" ( - "id" bigserial NOT NULL PRIMARY KEY - ); - -- - -- Create model RepositoryFlag - -- - CREATE TABLE "reports_repositoryflag" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "flag_name" varchar(255) NOT NULL, - "repository_id" integer NOT NULL - ); - -- - -- Create model SessionLevelTotals - -- - CREATE TABLE "reports_uploadleveltotals" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "branches" integer NOT NULL, - "coverage" numeric(7, 2) NOT NULL, - "hits" integer NOT NULL, - "lines" integer NOT NULL, - "methods" integer NOT NULL, - "misses" integer NOT NULL, - "partials" integer NOT NULL, - "files" integer NOT NULL, - "upload_id" bigint NOT NULL UNIQUE - ); - -- - -- Add field flag to reportsessionflagmembership - -- - ALTER TABLE "reports_uploadflagmembership" ADD COLUMN "flag_id" bigint NOT NULL; - -- - -- Add field report_session to reportsessionflagmembership - -- - ALTER TABLE "reports_uploadflagmembership" ADD COLUMN "upload_id" bigint NOT NULL; - -- - -- Add field flags to reportsession - -- - -- - -- Add field report to reportsession - -- - ALTER TABLE "reports_upload" ADD COLUMN "report_id" bigint NOT NULL; - ALTER TABLE "reports_commitreport" ADD CONSTRAINT "reports_commitreport_commit_id_06d0bd39_fk_commits_id" FOREIGN KEY ("commit_id") REFERENCES "commits" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_commitreport_commit_id_06d0bd39" ON "reports_commitreport" ("commit_id"); - ALTER TABLE "reports_reportdetails" ADD CONSTRAINT "reports_reportdetail_report_id_4681bfd3_fk_reports_c" FOREIGN KEY ("report_id") REFERENCES "reports_commitreport" ("id") DEFERRABLE INITIALLY DEFERRED; - ALTER TABLE "reports_reportleveltotals" ADD CONSTRAINT "reports_reportlevelt_report_id_b690dffa_fk_reports_c" FOREIGN KEY ("report_id") REFERENCES "reports_commitreport" ("id") DEFERRABLE INITIALLY DEFERRED; - ALTER TABLE "reports_uploaderror" ADD CONSTRAINT "reports_reportsessio_report_session_id_bb6563f1_fk_reports_r" FOREIGN KEY ("upload_id") REFERENCES "reports_upload" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_uploaderror_report_session_id_bb6563f1" ON "reports_uploaderror" ("upload_id"); - ALTER TABLE "reports_repositoryflag" ADD CONSTRAINT "reports_repositoryflag_repository_id_9b64b64c_fk_repos_repoid" FOREIGN KEY ("repository_id") REFERENCES "repos" ("repoid") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_repositoryflag_repository_id_9b64b64c" ON "reports_repositoryflag" ("repository_id"); - ALTER TABLE "reports_uploadleveltotals" ADD CONSTRAINT "reports_sessionlevel_report_session_id_e2cd6669_fk_reports_r" FOREIGN KEY ("upload_id") REFERENCES "reports_upload" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_uploadflagmembership_flag_id_59edee69" ON "reports_uploadflagmembership" ("flag_id"); - ALTER TABLE "reports_uploadflagmembership" ADD CONSTRAINT "reports_reportsessio_flag_id_59edee69_fk_reports_r" FOREIGN KEY ("flag_id") REFERENCES "reports_repositoryflag" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_uploadflagmembership_report_session_id_7d7f9546" ON "reports_uploadflagmembership" ("upload_id"); - ALTER TABLE "reports_uploadflagmembership" ADD CONSTRAINT "reports_reportsessio_report_session_id_7d7f9546_fk_reports_r" FOREIGN KEY ("upload_id") REFERENCES "reports_upload" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_upload_report_id_f6b4ffae" ON "reports_upload" ("report_id"); - ALTER TABLE "reports_upload" ADD CONSTRAINT "reports_reportsessio_report_id_f6b4ffae_fk_reports_c" FOREIGN KEY ("report_id") REFERENCES "reports_commitreport" ("id") DEFERRABLE INITIALLY DEFERRED; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/repos.py b/legacy_migrations/migrations/legacy_sql/main/tables/repos.py deleted file mode 100644 index 2623af5035..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/repos.py +++ /dev/null @@ -1,31 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create table repos( - repoid serial primary key, - ownerid int references owners on delete cascade not null, - service_id text not null, - name citext, - private boolean not null, - branch text default 'master' not null, - upload_token uuid unique default uuid_generate_v4(), - image_token text default random_string(10), - updatestamp timestamptz, - language languages, - active boolean, - deleted boolean default false not null, - activated boolean default false, - bot int references owners on delete set null, - yaml jsonb, - cache jsonb, -- {"totals": {}, "trends": [], "commit": {}, "yaml": ""} - hookid text, - using_integration boolean -- using github integration - ); - - create unique index repos_slug on repos (ownerid, name); - - create unique index repos_service_ids on repos (ownerid, service_id); - - alter table repos add column forkid int references repos; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/sessions.py b/legacy_migrations/migrations/legacy_sql/main/tables/sessions.py deleted file mode 100644 index 8cccb99874..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/sessions.py +++ /dev/null @@ -1,15 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create table sessions( - sessionid serial primary key, - token uuid unique default uuid_generate_v4() not null, - name text, - ownerid int references owners on delete cascade not null, - type sessiontype not null, - lastseen timestamptz, - useragent text, - ip text - ); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/tables/users.py b/legacy_migrations/migrations/legacy_sql/main/tables/users.py deleted file mode 100644 index 2fd0f0d032..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/tables/users.py +++ /dev/null @@ -1,15 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - CREATE TABLE IF NOT EXISTS "users" ( - "id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, - "external_id" uuid NOT NULL UNIQUE, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "email" citext NULL, - "name" text NULL, - "is_staff" boolean NULL, - "is_superuser" boolean NULL - ); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/triggers/__init__.py b/legacy_migrations/migrations/legacy_sql/main/triggers/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/legacy_migrations/migrations/legacy_sql/main/triggers/branches.py b/legacy_migrations/migrations/legacy_sql/main/triggers/branches.py deleted file mode 100644 index 2d377df3ba..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/triggers/branches.py +++ /dev/null @@ -1,32 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function branches_update() returns trigger as $$ - declare _ownerid int; - begin - -- update repos cache if main branch - update repos - set updatestamp = now(), - cache = update_json(cache::jsonb, 'commit', get_commit_minimum(new.repoid, new.head)::jsonb) - where repoid = new.repoid - and branch = new.branch - returning ownerid into _ownerid; - - if found then - -- default branch updated, so we can update the owners timestamp - -- to refresh the team list - update owners - set updatestamp=now() - where ownerid=_ownerid; - end if; - - return null; - end; - $$ language plpgsql; - - create trigger branch_update after update on branches - for each row - when (new.head is distinct from old.head) - execute procedure branches_update(); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/triggers/commits.py b/legacy_migrations/migrations/legacy_sql/main/triggers/commits.py deleted file mode 100644 index 231d9e1560..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/triggers/commits.py +++ /dev/null @@ -1,108 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function commits_update_heads() returns trigger as $$ - begin - - if new.pullid is not null and new.merged is not true then - -- update head of pulls - update pulls p - set updatestamp = now(), - head = case when head is not null - and (select timestamp > new.timestamp - from commits c - where c.repoid=new.repoid - and c.commitid=p.head - and c.deleted is not true - limit 1) - then head - else new.commitid - end, - author = coalesce(author, new.author) - where repoid = new.repoid - and pullid = new.pullid; - - end if; - - -- update head of branches - if new.branch is not null then - update branches - set updatestamp = now(), - authors = array_append_unique(coalesce(authors, '{}'::int[]), new.author), - head = case - when head is null then new.commitid - when ( - head != new.commitid - and new.timestamp >= coalesce((select timestamp - from commits - where commitid=head - and deleted is not true - and repoid=new.repoid - limit 1), '-infinity'::timestamp) - ) then new.commitid - else head end - where repoid = new.repoid - and branch = new.branch; - if not found then - insert into branches (repoid, updatestamp, branch, head, authors) - values (new.repoid, new.timestamp, new.branch, new.commitid, - case when new.author is not null then array[new.author] else null end); - end if; - end if; - - return null; - end; - $$ language plpgsql; - - create trigger commits_update_heads after update on commits - for each row - when (( - new.deleted is distinct from old.deleted - ) or ( - new.state = 'complete'::commit_state - and new.deleted is not true - and - ( - new.state is distinct from old.state - or new.pullid is distinct from old.pullid - or new.merged is distinct from old.merged - or new.branch is distinct from old.branch - ) - )) - execute procedure commits_update_heads(); - - - create or replace function commits_insert_pr_branch() returns trigger as $$ - begin - if new.pullid is not null and new.merged is not true then - begin - insert into pulls (repoid, pullid, author, head) - values (new.repoid, new.pullid, new.author, new.commitid); - exception when unique_violation then - end; - end if; - - if new.branch is not null then - begin - insert into branches (repoid, updatestamp, branch, authors, head) - values (new.repoid, new.timestamp, - new.branch, - case when new.author is not null then array[new.author] else null end, - new.commitid); - exception when unique_violation then - end; - end if; - - update repos - set updatestamp=now() - where repoid=new.repoid; - - return null; - end; - $$ language plpgsql; - - create trigger commits_insert_pr_branch after insert on commits - for each row - execute procedure commits_insert_pr_branch(); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/triggers/main.py b/legacy_migrations/migrations/legacy_sql/main/triggers/main.py deleted file mode 100644 index 1e00e5c556..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/triggers/main.py +++ /dev/null @@ -1,13 +0,0 @@ -from .branches import run_sql as branches_run_sql -from .commits import run_sql as commits_run_sql -from .owners import run_sql as owners_run_sql -from .pulls import run_sql as pulls_run_sql -from .repos import run_sql as repos_run_sql - - -def run_sql(schema_editor): - commits_run_sql(schema_editor) - branches_run_sql(schema_editor) - owners_run_sql(schema_editor) - repos_run_sql(schema_editor) - pulls_run_sql(schema_editor) diff --git a/legacy_migrations/migrations/legacy_sql/main/triggers/owners.py b/legacy_migrations/migrations/legacy_sql/main/triggers/owners.py deleted file mode 100644 index 4f47270e57..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/triggers/owners.py +++ /dev/null @@ -1,97 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function owner_yaml_updated() returns trigger as $$ - begin - if (new.yaml->'codecov'->'bot')::citext is distinct from 'null' then - new.bot = coalesce( - get_ownerid_if_member( - new.service, - (new.yaml->'codecov'->>'bot')::citext, - new.ownerid - ), - old.bot - ); - else - new.bot = null; - end if; - - -- update repo branches - update repos r - set branch = coalesce((r.yaml->'codecov'->>'branch'), (new.yaml->'codecov'->>'branch'), branch) - where ownerid = new.ownerid; - - return new; - end; - $$ language plpgsql; - - create trigger owner_yaml_updated before update on owners - for each row - when ( - ((new.yaml->'codecov'->>'bot')::text is distinct from (old.yaml->'codecov'->>'bot')::text) - or ((new.yaml->'codecov'->>'branch')::text is distinct from (old.yaml->'codecov'->>'branch')::text) - ) - execute procedure owner_yaml_updated(); - - - create or replace function owner_cache_state_update() returns trigger as $$ - declare _ownerid int; - begin - -- update cache of number of repos - for _ownerid in (select unnest from unnest(new.organizations)) loop - update owners o - set cache=update_json(cache, 'stats', update_json(cache->'stats', 'users', (select count(*) - from owners - where organizations @> array[_ownerid])::int)) - where ownerid=_ownerid; - end loop; - return null; - end; - $$ language plpgsql; - - create trigger owner_cache_state_update after update on owners - for each row - when (new.organizations is distinct from old.organizations) - execute procedure owner_cache_state_update(); - - create trigger owner_cache_state_insert after insert on owners - for each row - execute procedure owner_cache_state_update(); - - -- clear the user sessions when the token is set to null, requiring login - create or replace function owner_token_clered() returns trigger as $$ - begin - delete from sessions where ownerid=new.ownerid and type='login'; - return new; - end; - $$ language plpgsql; - - create trigger owner_token_clered after update on owners - for each row - when (new.oauth_token is distinct from old.oauth_token and new.oauth_token is null) - execute procedure owner_token_clered(); - - - create or replace function owners_before_insert_or_update() returns trigger as $$ - begin - -- user has changed name or deleted and invalidate sessions - with _owners as (update owners - set username = null - where service = new.service - and username = new.username::citext - returning ownerid) - delete from sessions where ownerid in (select ownerid from _owners); - return new; - end; - $$ language plpgsql; - - create trigger owners_before_insert before insert on owners - for each row - execute procedure owners_before_insert_or_update(); - - create trigger owners_before_update before update on owners - for each row - when (new.username is not null and new.username is distinct from old.username) - execute procedure owners_before_insert_or_update(); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/triggers/pulls.py b/legacy_migrations/migrations/legacy_sql/main/triggers/pulls.py deleted file mode 100644 index 00cc26a17c..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/triggers/pulls.py +++ /dev/null @@ -1,17 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function pulls_drop_flare() returns trigger as $$ - begin - new.flare = null; - return new; - end; - $$ language plpgsql; - - - create trigger pulls_before_update_drop_flare before update on pulls - for each row - when (new.state != 'open'::pull_state) - execute procedure pulls_drop_flare(); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/triggers/repos.py b/legacy_migrations/migrations/legacy_sql/main/triggers/repos.py deleted file mode 100644 index c99307a4e1..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/triggers/repos.py +++ /dev/null @@ -1,73 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function repo_yaml_update() returns trigger as $$ - declare _service service; - declare _branch text; - begin - select service, (yaml->'codecov'->>'branch') into _service, _branch - from owners - where ownerid=new.ownerid - limit 1; - - -- update repo bot and branch - update repos - set bot = case when (yaml->'codecov'->>'bot') is not null - then coalesce(get_ownerid_if_member(_service, (yaml->'codecov'->>'bot')::citext, ownerid), bot) - else null end, - branch = coalesce((yaml->'codecov'->>'branch'), _branch, branch) - where repoid=new.repoid; - return null; - end; - $$ language plpgsql; - - create trigger repo_yaml_update after update on repos - for each row - when ( - ((new.yaml->'codecov'->>'bot')::text is distinct from (old.yaml->'codecov'->>'bot')::text) - or ((new.yaml->'codecov'->>'branch')::text is distinct from (old.yaml->'codecov'->>'branch')::text) - ) - execute procedure repo_yaml_update(); - - - create or replace function repo_cache_state_update() returns trigger as $$ - begin - -- update cache of number of repos - update owners o - set cache=update_json(cache, 'stats', update_json(cache->'stats', 'repos', (select count(*) from repos r where r.ownerid=o.ownerid and active)::int)), - updatestamp=now() - where ownerid=new.ownerid; - return null; - end; - $$ language plpgsql; - - create trigger repo_cache_state_update after update on repos - for each row - when (new.active is distinct from old.active) - execute procedure repo_cache_state_update(); - - - create or replace function repos_before_insert_or_update() returns trigger as $$ - begin - -- repo name changed or deleted - update repos - set name = null, - deleted = true, - active = false, - activated = false - where ownerid = new.ownerid - and name = new.name; - return new; - end; - $$ language plpgsql; - - create trigger repos_before_insert before insert on repos - for each row - execute procedure repos_before_insert_or_update(); - - create trigger repos_before_update before update on repos - for each row - when (new.name is not null and new.name is distinct from old.name) - execute procedure repos_before_insert_or_update(); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/main/types.py b/legacy_migrations/migrations/legacy_sql/main/types.py deleted file mode 100644 index 0e799c9991..0000000000 --- a/legacy_migrations/migrations/legacy_sql/main/types.py +++ /dev/null @@ -1,26 +0,0 @@ -def run_sql(schema_editor): - schema_editor.execute( - """ - create type service as enum ('github', 'bitbucket', 'gitlab', 'github_enterprise', 'gitlab_enterprise', 'bitbucket_server'); - - create type plans as enum('5m', '5y', '25m', '25y', '50m', '50y', '100m', '100y', '250m', '250y', '500m', '500y', '1000m', '1000y', '1m', '1y', - 'v4-10m', 'v4-10y', 'v4-20m', 'v4-20y', 'v4-50m', 'v4-50y', 'v4-125m', 'v4-125y', 'v4-300m', 'v4-300y', - 'users', 'users-inappm', 'users-inappy', 'users-pr-inappm', 'users-pr-inappy', 'users-free'); - - create type sessiontype as enum('api', 'login'); - - create type languages as enum('javascript', 'shell', 'python', 'ruby', 'perl', 'dart', 'java', 'c', 'clojure', 'd', 'fortran', 'go', 'groovy', 'kotlin', 'php', 'r', 'scala', 'swift', 'objective-c', 'xtend'); - - create type pull_state as enum('open', 'closed', 'merged'); - - create type commit_state as enum('pending', 'complete', 'error', 'skipped'); - - create type plan_providers as enum('github'); - - create type notifications as enum('comment', 'gitter', 'hipchat', 'irc', 'slack', 'status_changes', 'status_patch', 'status_project', 'webhook', 'checks_patch', 'checks_project', 'checks_changes'); - - create type decorations as enum('standard', 'upgrade'); - - create type commit_notification_state as enum('pending', 'success', 'error'); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/main.py b/legacy_migrations/migrations/legacy_sql/upgrades/main.py deleted file mode 100644 index 33eac998f6..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/main.py +++ /dev/null @@ -1,55 +0,0 @@ -from .v440 import run_sql as v440_run_sql -from .v442 import run_sql as v442_run_sql -from .v443 import run_sql as v443_run_sql -from .v446 import run_sql as v446_run_sql -from .v447 import run_sql as v447_run_sql -from .v448 import run_sql as v448_run_sql -from .v449 import run_sql as v449_run_sql -from .v451 import run_sql as v451_run_sql -from .v452 import run_sql as v452_run_sql -from .v453 import run_sql as v453_run_sql -from .v454 import run_sql as v454_run_sql -from .v455 import run_sql as v455_run_sql -from .v461 import run_sql as v461_run_sql -from .v4410 import run_sql as v4410_run_sql -from .v4510 import run_sql as v4510_run_sql - -UPGRADE_MIGRATIONS_BY_VERSION = ( - ((4, 4, 0), v440_run_sql), - ((4, 4, 2), v442_run_sql), - ((4, 4, 3), v443_run_sql), - ((4, 4, 6), v446_run_sql), - ((4, 4, 7), v447_run_sql), - ((4, 4, 8), v448_run_sql), - ((4, 4, 9), v449_run_sql), - ((4, 4, 10), v4410_run_sql), - ((4, 5, 1), v451_run_sql), - ((4, 5, 2), v452_run_sql), - ((4, 5, 3), v453_run_sql), - ((4, 5, 4), v454_run_sql), - ((4, 5, 5), v455_run_sql), - ((4, 5, 10), v4510_run_sql), - ((4, 6, 1), v461_run_sql), -) - - -def _version_normalize(version): - return tuple(int(x or 0) for x in version.replace("v", "").split(".")) - - -def run_sql(schema_editor, current_version): - normalized_current_version = _version_normalize(current_version) - upgrade_migration_index_to_start_from = None - - for idx, (upgrade_version, _) in enumerate(UPGRADE_MIGRATIONS_BY_VERSION): - if upgrade_version > normalized_current_version: - upgrade_migration_index_to_start_from = idx - break - - if not upgrade_migration_index_to_start_from: - return - - for _, upgrade_migration in UPGRADE_MIGRATIONS_BY_VERSION[ - upgrade_migration_index_to_start_from: - ]: - upgrade_migration(schema_editor) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v440.py b/legacy_migrations/migrations/legacy_sql/upgrades/v440.py deleted file mode 100644 index ba30a10f7c..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v440.py +++ /dev/null @@ -1,353 +0,0 @@ -from ..main.functions.aggregates import run_sql as aggregates_run_sql -from ..main.functions.coverage import run_sql as coverage_run_sql -from ..main.functions.get_access_token import run_sql as get_access_token_run_sql -from ..main.functions.get_author import run_sql as get_author_run_sql -from ..main.functions.get_commit import run_sql as get_commit_run_sql -from ..main.functions.get_customer import run_sql as get_customer_run_sql -from ..main.functions.get_graph_for import run_sql as get_graph_for_run_sql -from ..main.functions.get_ownerid import run_sql as get_ownerid_run_sql -from ..main.functions.get_repo import run_sql as get_repo_run_sql -from ..main.functions.get_user import run_sql as get_user_run_sql -from ..main.functions.insert_commit import run_sql as insert_commit_run_sql -from ..main.functions.refresh_repos import run_sql as refresh_repos_run_sql -from ..main.functions.update_json import run_sql as update_json_run_sql -from ..main.functions.verify_session import run_sql as verify_session_run_sql - - -# v4.4.0 -def run_sql(schema_editor): - schema_editor.execute( - """ - ---- Column Updates ----- - drop trigger repo_yaml_update on repos; - drop trigger owner_yaml_updated on owners; - - alter table owners drop column if exists errors; - alter table owners drop column if exists yaml_repoid; - alter table commits drop column if exists logs; - alter table commits drop column if exists archived; - alter table pulls rename column totals to diff; - alter table pulls drop column if exists changes; - alter table pulls drop column if exists base_branch; - alter table pulls drop column if exists head_branch; - alter table repos alter column yaml set data type jsonb; - alter table repos alter column cache set data type jsonb; - alter table owners alter column cache set data type jsonb; - alter table owners alter column yaml set data type jsonb; - alter table commits alter column totals set data type jsonb; - alter table commits alter column report set data type jsonb; - alter table pulls alter column diff set data type jsonb; - alter table pulls alter column flare set data type jsonb; - alter table owners alter column integration_id set data type integer; - - create trigger repo_yaml_update after update on repos - for each row - when ( - ((new.yaml->'codecov'->>'bot')::text is distinct from (old.yaml->'codecov'->>'bot')::text) - or ((new.yaml->'codecov'->>'branch')::text is distinct from (old.yaml->'codecov'->>'branch')::text) - ) - execute procedure repo_yaml_update(); - - - create trigger owner_yaml_updated before update on owners - for each row - when ( - ((new.yaml->'codecov'->>'bot')::text is distinct from (old.yaml->'codecov'->>'bot')::text) - or ((new.yaml->'codecov'->>'branch')::text is distinct from (old.yaml->'codecov'->>'branch')::text) - ) - execute procedure owner_yaml_updated(); - - - drop trigger pulls_before_insert on pulls; - drop function pulls_insert(); - drop trigger pulls_before_update on pulls; - drop function pulls_update(); - - create or replace function pulls_drop_flare() returns trigger as $$ - begin - new.flare = null; - return new; - end; - $$ language plpgsql; - - create trigger pulls_before_update_drop_flare before update on pulls - for each row - when (new.state != 'open'::pull_state) - execute procedure pulls_drop_flare(); - - ---- Function Changes ----- - drop function if exists get_new_repos(int); - drop function if exists get_pull(int, int); - drop function if exists coverage(service, text, text, text, text); - drop function if exists extract_totals(version smallint, files json, sessionids integer[]); - drop function if exists get_commit(repoid, _commitid, path, tree_only); - drop function if exists get_commit_on_branch(integer, text, text, boolean); - drop function if exists get_totals_for_file(smallint, json); - drop function if exists refresh_teams(service, json, integer); - drop function if exists get_commit(integer, text, text, boolean); - - -- insert_commit.sql - drop function if exists insert_commit(integer, text, text, integer, json); - """ - ) - insert_commit_run_sql(schema_editor) - - schema_editor.execute( - """ - -- aggregates.sql - drop function if exists _pop_first_as_json(json[]) cascade; - drop function if exists _max_coverage(json[]) cascade; - drop function if exists _min_coverage(json[]) cascade; - drop function _max_coverage(json[], json); - drop function _min_coverage(json[], json); - drop aggregate agg_totals(json); - drop function _agg_report_totals(text[], json); - """ - ) - aggregates_run_sql(schema_editor) - - schema_editor.execute( - """ - -- coverage.sql - drop function if exists get_coverage(service,citext,citext,citext); - """ - ) - coverage_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_access_token.sql - drop function if exists get_access_token(int); - """ - ) - get_access_token_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_author.sql - drop function if exists get_author(int); - """ - ) - get_author_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_commit.sql - drop function if exists get_commit_totals(int, text); - drop function if exists get_commit_totals(int, text, text); - drop function if exists get_commit(repoid integer, _commitid text); - drop function if exists get_commit_minimum(int, text); - drop function if exists get_ - commit_on_branch(int, text); - """ - ) - get_commit_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_customer.sql - drop function if exists get_customer(int); - """ - ) - get_customer_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_graph_for.sql - drop function if exists sum_of_file_totals_filtering_sessionids(json, int[]); - drop function if exists extract_totals(files json, sessionids int[]); - drop function if exists list_sessionid_by_filtering_flags(sessions json, flags text[]); - drop function if exists total_list_to_json(totals text[]); - drop function if exists sum_session_totals(sessions json, flags text[]); - drop function if exists get_graph_for_flare_pull(int, text, text, text[]); - drop function if exists get_graph_for_flare_commit(int, text, text, text[]); - drop function if exists get_graph_for_flare_branch(int, text, text, text[]); - drop function if exists get_graph_for_totals_pull(int, text, text, text[]); - drop function if exists get_graph_for_totals_commit(int, text, text, text[]); - drop function if exists get_graph_for_totals_branch(int, text, text, text[]); - drop function if exists get_graph_for_commits_pull(int, text, text, text[]); - drop function if exists get_graph_for_commits_branch(int, text, text, text[]); - """ - ) - get_graph_for_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_ownerid.sql - drop function if exists get_owner(service, citext); - drop function if exists get_teams(service, integer[]); - """ - ) - get_ownerid_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_repo.sql - drop function if exists get_repo(int); - drop function if exists get_repo(int, citext); - drop function if exists get_repo_by_token(uuid); - drop function if exists get_repos(int, int, int); - """ - ) - get_repo_run_sql(schema_editor) - - schema_editor.execute( - """ - -- get_user.sql - drop function if exists get_user(int); - drop function if exists get_username(int); - drop function if exists get_users(int[]); - """ - ) - get_user_run_sql(schema_editor) - - schema_editor.execute( - """ - -- refresh_repos.sql - drop function if exists refresh_teams(service, json); - drop function if exists refresh_repos(service, json, int, boolean); - """ - ) - refresh_repos_run_sql(schema_editor) - - schema_editor.execute( - """ - -- update_json.sql - drop function if exists add_key_to_json(json, text, json); - drop function if exists add_key_to_json(json, text, integer); - drop function if exists add_key_to_json(json, text, text); - drop function if exists remove_key_from_json(json, text); - drop function if exists update_json(json, text, json); - drop function if exists update_json(json, text, integer); - drop function if exists update_json(json, text, text); - """ - ) - update_json_run_sql(schema_editor) - - schema_editor.execute( - """ - -- verify_session.sql - drop function if exists verify_session(text, text, uuid, sessiontype); - """ - ) - verify_session_run_sql(schema_editor) - - schema_editor.execute( - """ - -- Trigger Changes -- - create or replace function commits_update_heads() returns trigger as $$ - begin - - if new.pullid is not null and new.merged is not true then - -- update head of pulls - update pulls p - set updatestamp = now(), - head = case when head is not null - and (select timestamp > new.timestamp - from commits c - where c.repoid=new.repoid - and c.commitid=p.head - and c.deleted is not true - limit 1) - then head - else new.commitid - end, - author = coalesce(author, new.author) - where repoid = new.repoid - and pullid = new.pullid; - - end if; - - -- update head of branches - if new.branch is not null then - update branches - set updatestamp = now(), - authors = array_append_unique(coalesce(authors, '{}'::int[]), new.author), - head = case - when head is null then new.commitid - when ( - head != new.commitid - and new.timestamp >= coalesce((select timestamp - from commits - where commitid=head - and deleted is not true - and repoid=new.repoid - limit 1), '-infinity'::timestamp) - ) then new.commitid - else head end - where repoid = new.repoid - and branch = new.branch; - if not found then - insert into branches (repoid, updatestamp, branch, head, authors) - values (new.repoid, new.timestamp, new.branch, new.commitid, - case when new.author is not null then array[new.author] else null end); - end if; - end if; - - return null; - end; - $$ language plpgsql; - - create or replace function branches_update() returns trigger as $$ - declare _ownerid int; - begin - -- update repos cache if main branch - update repos - set updatestamp = now(), - cache = update_json(cache::jsonb, 'commit', get_commit_minimum(new.repoid, new.head)::jsonb) - where repoid = new.repoid - and branch = new.branch - returning ownerid into _ownerid; - - if found then - -- default branch updated, so we can update the owners timestamp - -- to refresh the team list - update owners - set updatestamp=now() - where ownerid=_ownerid; - end if; - - return null; - end; - $$ language plpgsql; - - - create or replace function repos_before_insert_or_update() returns trigger as $$ - begin - -- repo name changed or deleted - update repos - set name = null, - deleted = true, - active = false, - activated = false - where ownerid = new.ownerid - and name = new.name; - return new; - end; - $$ language plpgsql; - - - create index commits_on_pull on commits (repoid, pullid) where deleted is not true; - - alter table commits drop column chunks; - - drop trigger commits_update_heads on commits; - - create trigger commits_update_heads after update on commits - for each row - when (( - new.deleted is distinct from old.deleted - ) or ( - new.state = 'complete'::commit_state - and new.deleted is not true - and - ( - new.state is distinct from old.state - or new.pullid is distinct from old.pullid - or new.merged is distinct from old.merged - or new.branch is distinct from old.branch - ) - )) - execute procedure commits_update_heads(); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v4410.py b/legacy_migrations/migrations/legacy_sql/upgrades/v4410.py deleted file mode 100644 index 4223b56e61..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v4410.py +++ /dev/null @@ -1,29 +0,0 @@ -# v4.4.10 -def run_sql(schema_editor): - schema_editor.execute( - """ - create or replace function owner_yaml_updated() returns trigger as $$ - begin - if (new.yaml->'codecov'->'bot')::citext is distinct from 'null' then - new.bot = coalesce( - get_ownerid_if_member( - new.service, - (new.yaml->'codecov'->>'bot')::citext, - new.ownerid - ), - old.bot - ); - else - new.bot = null; - end if; - - -- update repo branches - update repos r - set branch = coalesce((r.yaml->'codecov'->>'branch'), (new.yaml->'codecov'->>'branch'), branch) - where ownerid = new.ownerid; - - return new; - end; - $$ language plpgsql; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v442.py b/legacy_migrations/migrations/legacy_sql/upgrades/v442.py deleted file mode 100644 index 7befcd0535..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v442.py +++ /dev/null @@ -1,104 +0,0 @@ -# v4.4.2 -def run_sql(schema_editor): - schema_editor.execute( - """ - ---- Column Updates ----- - alter table owners add column avatar_url text; - - - ---- Function Changes ----- - - -- get_ownerid.sql - create or replace function get_owner(service, citext) returns jsonb as $$ - with data as ( - select service_id, service, ownerid::text, username, avatar_url, - updatestamp, plan, name, integration_id, free, - plan_activated_users, plan_auto_activate, plan_user_count - from owners - where service=$1 - and username=$2::citext - limit 1 - ) select to_jsonb(data) - from data - limit 1; - $$ language sql stable strict; - - -- get_ownerid.sql - create or replace function get_or_create_owner(service, text, text, text) returns int as $$ - declare _ownerid int; - begin - update owners - set username = $3, avatar_url = $4 - where service = $1 - and service_id = $2 - returning ownerid into _ownerid; - - if not found then - insert into owners (service, service_id, username, avatar_url) - values ($1, $2, $3, $4) - returning ownerid into _ownerid; - end if; - - return _ownerid; - - end; - $$ language plpgsql volatile; - - -- get_user.sql - create or replace function get_user(int) returns jsonb as $$ - with data as ( - select ownerid::text, private_access, staff, service, service_id, - username, organizations, avatar_url, - oauth_token, plan, permission, - free, email, name, createstamp - from owners - where ownerid=$1 - limit 1 - ) select to_jsonb(data) from data; - $$ language sql stable; - - -- get_user.sql - create or replace function get_users(int[]) returns jsonb as $$ - with data as ( - select service, service_id::text, ownerid::text, username, name, email, avatar_url - from owners - where array[ownerid] <@ $1 - limit array_length($1, 1) - ) select jsonb_agg(data) - from data - limit array_length($1, 1); - $$ language sql stable strict; - - -- refresh_repos.sql - create or replace function refresh_teams(service, jsonb) returns int[] as $$ - declare ownerids int[]; - declare _ownerid int; - declare _team record; - begin - for _team in select d from jsonb_array_elements($2) d loop - update owners o - set username = (_team.d->>'username')::citext, - name = (_team.d->>'name')::text, - email = (_team.d->>'email')::text, - avatar_url = (_team.d->>'avatar_url')::text, - updatestamp = now() - where service = $1 - and service_id = (_team.d->>'id')::text - returning ownerid into _ownerid; - - if not found then - insert into owners (service, service_id, username, name, email, avatar_url) - values ($1, (_team.d->>'id')::text, (_team.d->>'username')::citext, (_team.d->>'name')::text, (_team.d->>'email')::text, (_team.d->>'avatar_url')::text) - returning ownerid into _ownerid; - end if; - - select array_append(ownerids, _ownerid) into ownerids; - - end loop; - - return ownerids; - - end; - $$ language plpgsql volatile strict; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v443.py b/legacy_migrations/migrations/legacy_sql/upgrades/v443.py deleted file mode 100644 index 59c1945cfc..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v443.py +++ /dev/null @@ -1,191 +0,0 @@ -# v4.4.3 -def run_sql(schema_editor): - schema_editor.execute( - """ - ---- Table Changes ----- - alter table owners add column parent_service_id text; - - - ----- Functions Created ----- - - -- get_customer.sql - create or replace function get_gitlab_root_group(int) returns jsonb as $$ - with recursive tree as ( - select o.service_id, - o.parent_service_id, - o.ownerid, - 1 as depth - from owners o - where o.ownerid = $1 - and o.service = 'gitlab' - and o.parent_service_id is not null - union all - select o.service_id, - o.parent_service_id, - o.ownerid, - depth + 1 as depth - from tree t - join owners o - on o.service_id = t.parent_service_id - where depth <= 20 - ), data as ( - select t.ownerid, - t.service_id - from tree t - where t.parent_service_id is null - ) - select to_jsonb(data) from data limit 1; - $$ language sql stable strict; - - -- get_customer.sql - create or replace function get_gitlab_repos_activated(int, text) returns int as $$ - declare _repos_activated int; - declare _decendents_owner_ids int[]; - begin - select array( - with recursive tree as ( - select ownerid, - service_id, - array[]::text[] as ancestors_service_id, - 1 as depth - from owners - where parent_service_id is null - and service = 'gitlab' - and ownerid = $1 - union all - select owners.ownerid, - owners.service_id, - tree.ancestors_service_id || owners.parent_service_id, - depth + 1 as depth - from owners, tree - where owners.parent_service_id = tree.service_id - and depth <= 20 - ) - select ownerid - from tree - where $2 = any(tree.ancestors_service_id) - ) into _decendents_owner_ids; - - select count(*) into _repos_activated - from repos - where ownerid in (select unnest(array_append(_decendents_owner_ids, $1))) - and private - and activated; - - return _repos_activated; - end; - $$ language plpgsql stable; - - -- get_customer.sql - create or replace function get_repos_activated(int) returns int as $$ - declare _repos_activated int; - declare _service text; - declare _service_id text; - begin - select o.service, o.service_id into _service, _service_id - from owners o where o.ownerid = $1; - - if _service = 'gitlab' then - select get_gitlab_repos_activated($1, _service_id) into _repos_activated; - else - select count(*) into _repos_activated - from repos - where ownerid=$1 - and private - and activated; - end if; - - return _repos_activated; - end; - $$ language plpgsql stable; - - - ---- Functions Modified ----- - - drop function if exists get_or_create_owner(service, text, text, text); -- signature change - - -- get_customer.sql - create or replace function get_customer(int) returns jsonb as $$ - with data as ( - select t.stripe_customer_id, - t.stripe_subscription_id, - t.ownerid::text, - t.service, - t.service_id, - t.plan_user_count, - t.plan_provider, - t.plan_auto_activate, - t.plan_activated_users, - t.plan, t.email, - t.free, t.did_trial, - t.invoice_details, - get_users(t.admins) as admins, - get_repos_activated($1) as repos_activated - from owners t - where t.ownerid = $1 - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable strict; - - -- refresh_repos.sql - create or replace function refresh_teams(service, jsonb) returns int[] as $$ - declare ownerids int[]; - declare _ownerid int; - declare _team record; - begin - for _team in select d from jsonb_array_elements($2) d loop - update owners o - set username = (_team.d->>'username')::citext, - name = (_team.d->>'name')::text, - email = (_team.d->>'email')::text, - avatar_url = (_team.d->>'avatar_url')::text, - parent_service_id = (_team.d->>'parent_id')::text, - updatestamp = now() - where service = $1 - and service_id = (_team.d->>'id')::text - returning ownerid into _ownerid; - - if not found then - insert into owners (service, service_id, username, name, email, avatar_url, parent_service_id) - values ($1, - (_team.d->>'id')::text, - (_team.d->>'username')::citext, - (_team.d->>'name')::text, - (_team.d->>'email')::text, - (_team.d->>'avatar_url')::text, - (_team.d->>'parent_id')::text - ) - returning ownerid into _ownerid; - end if; - - select array_append(ownerids, _ownerid) into ownerids; - - end loop; - - return ownerids; - - end; - $$ language plpgsql volatile strict; - - -- get_ownerid.sql - create or replace function get_or_create_owner(service, text, text, text, text) returns int as $$ - declare _ownerid int; - begin - update owners - set username = $3, avatar_url = $4, parent_service_id = $5 - where service = $1 - and service_id = $2 - returning ownerid into _ownerid; - - if not found then - insert into owners (service, service_id, username, avatar_url, parent_service_id) - values ($1, $2, $3, $4, $5) - returning ownerid into _ownerid; - end if; - - return _ownerid; - - end; - $$ language plpgsql volatile; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v446.py b/legacy_migrations/migrations/legacy_sql/upgrades/v446.py deleted file mode 100644 index d7e4253e32..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v446.py +++ /dev/null @@ -1,67 +0,0 @@ -# v4.4.6 -def run_sql(schema_editor): - schema_editor.execute( - """ - -- used for app/tasks - create or replace function get_repo(int) returns jsonb as $$ - with d as (select o.service, o.username, o.service_id as owner_service_id, r.ownerid::text, - r.name, r.repoid::text, r.service_id, r.updatestamp, - r.branch, r.private, hookid, image_token, b.username as bot_username, - r.yaml, o.yaml as org_yaml, r.using_integration, o.plan, - (r.cache->>'yaml') as _yaml_location, - case when r.using_integration then o.integration_id else null end as integration_id, - get_access_token(coalesce(r.bot, o.bot, o.ownerid)) as token, - case when private and activated is not true and forkid is not null - then (select rr.activated from repos rr where rr.repoid = r.forkid limit 1) - else activated end as activated - from repos r - inner join owners o using (ownerid) - left join owners b ON (r.bot=b.ownerid) - where r.repoid = $1 - limit 1) select to_jsonb(d) from d; - $$ language sql stable strict; - - - -- used for app/handlers - create or replace function get_repo(int, citext) returns jsonb as $$ - with repo as ( - select r.yaml, r.name, "language", repoid::text, r.private, r.deleted, r.active, r.cache, b.username as bot_username, - r.branch, r.service_id, r.updatestamp, upload_token, image_token, hookid, using_integration, - case when private and activated is not true and forkid is not null - then (select rr.activated from repos rr where rr.repoid = r.forkid limit 1) - else activated end as activated - from repos r - left join owners b ON (r.bot=b.ownerid) - where r.ownerid = $1 and r.name = $2::citext - limit 1 - ) select to_jsonb(repo) from repo; - $$ language sql stable; - - create or replace function get_customer(int) returns jsonb as $$ - with data as ( - select t.stripe_customer_id, - t.stripe_subscription_id, - t.ownerid::text, - t.service, - t.service_id, - t.plan_user_count, - t.plan_provider, - t.plan_auto_activate, - t.plan_activated_users, - t.plan, - t.email, - t.free, - t.did_trial, - t.invoice_details, - t.yaml, - b.username as bot_username, - get_users(t.admins) as admins, - get_repos_activated($1::int) as repos_activated - from owners t - LEFT JOIN owners b ON (b.ownerid = t.bot) - where t.ownerid = $1 - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable strict; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v447.py b/legacy_migrations/migrations/legacy_sql/upgrades/v447.py deleted file mode 100644 index e1a7d256cf..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v447.py +++ /dev/null @@ -1,25 +0,0 @@ -# v4.4.7 -def run_sql(schema_editor): - schema_editor.execute( - """ - drop trigger repo_yaml_update on repos; - drop trigger owner_yaml_updated on owners; - - create trigger repo_yaml_update after update on repos - for each row - when ( - ((new.yaml->'codecov'->>'bot')::text is distinct from (old.yaml->'codecov'->>'bot')::text) - or ((new.yaml->'codecov'->>'branch')::text is distinct from (old.yaml->'codecov'->>'branch')::text) - ) - execute procedure repo_yaml_update(); - - - create trigger owner_yaml_updated before update on owners - for each row - when ( - ((new.yaml->'codecov'->>'bot')::text is distinct from (old.yaml->'codecov'->>'bot')::text) - or ((new.yaml->'codecov'->>'branch')::text is distinct from (old.yaml->'codecov'->>'branch')::text) - ) - execute procedure owner_yaml_updated(); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v448.py b/legacy_migrations/migrations/legacy_sql/upgrades/v448.py deleted file mode 100644 index 14960bb385..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v448.py +++ /dev/null @@ -1,27 +0,0 @@ -# v4.4.8 -def run_sql(schema_editor): - schema_editor.execute( - """ - --- transaction friendly enum column upates. See: https://stackoverflow.com/questions/1771543/adding-a-new-value-to-an-existing-enum-type#7834949 -- - - - -- rename the old enum -- rename the old enum - alter type plans rename to plans__; -- alter type plans rename to plans__; - -- create the new enum -- -- create the new enum - create type plans as enum('5m', '5y', '25m', '25y', '50m', '50y', '100m', '100y', '250m', '250y', '500m', '500y', '1000m', '1000y', '1m', '1y', -- create type plans as enum('5m', '5y', '25m', '25y', '50m', '50y', '100m', '100y', '250m', '250y', '500m', '500y', '1000m', '1000y', '1m', '1y', - 'v4-10m', 'v4-10y', 'v4-20m', 'v4-20y', 'v4-50m', 'v4-50y', 'v4-125m', 'v4-125y', 'v4-300m', 'v4-300y', -- 'v4-10m', 'v4-10y', 'v4-20m', 'v4-20y', 'v4-50m', 'v4-50y', 'v4-125m', 'v4-125y', 'v4-300m', 'v4-300y', - 'users', 'users-inappm', 'users-inappy', 'users-free'); -- 'users', 'users-inappm', 'users-inappy', 'users-free'); - -- alter all enum columns - alter table owners - alter column plan type plans using plan::text::plans; - - - -- drop the old enum - drop type plans__; - - - ALTER TABLE ONLY owners ALTER COLUMN plan SET DEFAULT 'users-free'; -- ALTER TABLE ONLY owners ALTER COLUMN plan SET DEFAULT 'users-free'; - ALTER TABLE ONLY owners ALTER COLUMN plan_user_count SET DEFAULT 5; -- ALTER TABLE ONLY owners ALTER COLUMN plan_user_count SET DEFAULT 5; - ALTER TABLE ONLY owners ALTER COLUMN plan_auto_activate SET DEFAULT true; -- ALTER TABLE ONLY owners ALTER COLUMN plan_auto_activate SET DEFAULT true; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v449.py b/legacy_migrations/migrations/legacy_sql/upgrades/v449.py deleted file mode 100644 index 7bf480d97b..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v449.py +++ /dev/null @@ -1,41 +0,0 @@ -# v4.4.9 -def run_sql(schema_editor): - schema_editor.execute( - """ - alter table owners add column student boolean null; - alter table owners add column student_updated_at timestamp; - alter table owners add column student_created_at timestamp; - - - -- new get customer to return student status - create or replace function get_customer(int) returns jsonb as $$ - with data as ( - select t.stripe_customer_id, - t.stripe_subscription_id, - t.ownerid::text, - t.service, - t.service_id, - t.plan_user_count, - t.plan_provider, - t.plan_auto_activate, - t.plan_activated_users, - t.plan, - t.email, - t.free, - t.did_trial, - t.invoice_details, - t.yaml, - t.student, - t.student_created_at, - t.student_updated_at, - b.username as bot_username, - get_users(t.admins) as admins, - get_repos_activated($1::int) as repos_activated - from owners t - LEFT JOIN owners b ON (b.ownerid = t.bot) - where t.ownerid = $1 - limit 1 - ) select to_jsonb(data) from data limit 1; - $$ language sql stable strict; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v451.py b/legacy_migrations/migrations/legacy_sql/upgrades/v451.py deleted file mode 100644 index 0af6041576..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v451.py +++ /dev/null @@ -1,43 +0,0 @@ -# 4.5.1 -def run_sql(schema_editor): - schema_editor.execute( - """ - -- create enums used by commit_notifications table - create type notifications as enum('comment', 'gitter', 'hipchat', 'irc', 'slack', 'status_changes', 'status_patch', 'status_project', 'webhook', 'checks_patch', 'checks_project', 'checks_changes'); - create type decorations as enum('standard', 'upgrade'); - create type commit_notification_state as enum('pending', 'success', 'error'); - - -- Here we're commenting out all plan related migrations below because they break on enterprise - -- these migrations have been run already for production, but can break some production - -- deployments. Specifically the setting of the plan column to a new default causes problems with - -- web's ability to migrate effectively in some scenarios. - - -- If you're starting from scratch in dev, you will need to run the below migrations manually, - -- or comment out these migrations before starting up codecov.io for the first time. - - -- This isn't ideal, and will hopefully be addressed when we move all migrations to Django. - - -- Transaction friendly enum column upates. See: https://stackoverflow.com/questions/1771543/adding-a-new-value-to-an-existing-enum-type#7834949 - -- NOTE: we will not change the plan default yet - - -- first remove the default from plan column otherwise we'll get an error below with trying to cast the default - -- alter table owners alter column plan drop default; - - -- rename the old enum - -- alter type plans rename to plans__; - - -- create the new enum adding users-pr-inappm and users-pr-inappy plans - -- create type plans as enum('5m', '5y', '25m', '25y', '50m', '50y', '100m', '100y', '250m', '250y', '500m', '500y', '1000m', '1000y', '1m', '1y', - -- 'v4-10m', 'v4-10y', 'v4-20m', 'v4-20y', 'v4-50m', 'v4-50y', 'v4-125m', 'v4-125y', 'v4-300m', 'v4-300y', - -- 'users', 'users-inappm', 'users-inappy', 'users-pr-inappm', 'users-pr-inappy', 'users-free'); - - -- use the new enum - -- alter table owners alter column plan type plans using plan::text::plans; - - - --ALTER TABLE ONLY owners ALTER COLUMN plan SET DEFAULT 'users-free'; - - -- drop the old enum - -- drop type plans__; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v4510.py b/legacy_migrations/migrations/legacy_sql/upgrades/v4510.py deleted file mode 100644 index 5659ee811a..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v4510.py +++ /dev/null @@ -1,7 +0,0 @@ -# v4.5.10 -def run_sql(schema_editor): - schema_editor.execute( - """ - alter table owners add column root_parent_service_id text; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v452.py b/legacy_migrations/migrations/legacy_sql/upgrades/v452.py deleted file mode 100644 index eec8e575d6..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v452.py +++ /dev/null @@ -1,14 +0,0 @@ -# v4.5.2 -def run_sql(schema_editor): - schema_editor.execute( - """ - ALTER TABLE commits ADD COLUMN id bigint; - COMMIT; - -- EOF - CREATE SEQUENCE commits_id_seq OWNED BY commits.id; - COMMIT; - -- EOF - ALTER TABLE commits ALTER COLUMN id SET DEFAULT nextval('commits_id_seq'); - COMMIT; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v453.py b/legacy_migrations/migrations/legacy_sql/upgrades/v453.py deleted file mode 100644 index 21575d0aef..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v453.py +++ /dev/null @@ -1,20 +0,0 @@ -# v4.5.3 -def run_sql(schema_editor): - schema_editor.execute( - """ - CREATE UNIQUE INDEX IF NOT EXISTS commits_pkey on commits (id); - - create table commit_notifications( - id bigserial primary key, - commit_id bigint references commits(id) on delete cascade not null, - notification_type notifications not null, - decoration_type decorations, - created_at timestamp, - updated_at timestamp, - state commit_notification_state, - CONSTRAINT commit_notifications_commit_id_notification_type UNIQUE(commit_id, notification_type) - ); - - create index commit_notifications_commit_id on commit_notifications (commit_id); - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v454.py b/legacy_migrations/migrations/legacy_sql/upgrades/v454.py deleted file mode 100644 index cb9bb707b3..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v454.py +++ /dev/null @@ -1,148 +0,0 @@ -# v4.5.4 -def run_sql(schema_editor): - schema_editor.execute( - """ - ALTER TABLE commit_notifications drop CONSTRAINT IF EXISTS commit_notifications_commit_id_fkey; - ALTER TABLE commits drop CONSTRAINT IF EXISTS commits_pkey; - CREATE UNIQUE INDEX IF NOT EXISTS commits_pkey on commits (id); - ALTER TABLE commits ADD PRIMARY KEY USING INDEX commits_pkey; - ALTER TABLE commit_notifications ADD CONSTRAINT commit_notifications_commit_id_fkey FOREIGN KEY (commit_id) REFERENCES commits(id) ON DELETE CASCADE - -- EOF - BEGIN; - -- - -- Create model CommitReport - -- - CREATE TABLE "reports_commitreport" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "commit_id" bigint NOT NULL - ); - -- - -- Create model ReportDetails - -- - CREATE TABLE "reports_reportdetails" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "files_array" jsonb[] NOT NULL, - "report_id" bigint NOT NULL UNIQUE - ); - -- - -- Create model ReportLevelTotals - -- - CREATE TABLE "reports_reportleveltotals" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "branches" integer NOT NULL, - "coverage" numeric(7, 2) NOT NULL, - "hits" integer NOT NULL, - "lines" integer NOT NULL, - "methods" integer NOT NULL, - "misses" integer NOT NULL, - "partials" integer NOT NULL, - "files" integer NOT NULL, - "report_id" bigint NOT NULL UNIQUE - ); - -- - -- Create model ReportSession - -- - CREATE TABLE "reports_upload" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "build_code" text NULL, - "build_url" text NULL, - "env" jsonb NULL, - "job_code" text NULL, - "name" varchar(100) NULL, - "provider" varchar(50) NULL, - "state" varchar(100) NOT NULL, - "storage_path" text NOT NULL, - "order_number" integer NULL - ); - -- - -- Create model ReportSessionError - -- - CREATE TABLE "reports_uploaderror" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "error_code" varchar(100) NOT NULL, - "error_params" jsonb NOT NULL, - "report_session_id" bigint NOT NULL - ); - -- - -- Create model ReportSessionFlagMembership - -- - CREATE TABLE "reports_uploadflagmembership" ( - "id" bigserial NOT NULL PRIMARY KEY - ); - -- - -- Create model RepositoryFlag - -- - CREATE TABLE "reports_repositoryflag" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "flag_name" varchar(255) NOT NULL, - "repository_id" integer NOT NULL - ); - -- - -- Create model SessionLevelTotals - -- - CREATE TABLE "reports_sessionleveltotals" ( - "id" bigserial NOT NULL PRIMARY KEY, - "external_id" uuid NOT NULL, - "created_at" timestamp with time zone NOT NULL, - "updated_at" timestamp with time zone NOT NULL, - "branches" integer NOT NULL, - "coverage" numeric(7, 2) NOT NULL, - "hits" integer NOT NULL, - "lines" integer NOT NULL, - "methods" integer NOT NULL, - "misses" integer NOT NULL, - "partials" integer NOT NULL, - "files" integer NOT NULL, - "report_session_id" bigint NOT NULL UNIQUE - ); - -- - -- Add field flag to reportsessionflagmembership - -- - ALTER TABLE "reports_uploadflagmembership" ADD COLUMN "flag_id" bigint NOT NULL; - -- - -- Add field report_session to reportsessionflagmembership - -- - ALTER TABLE "reports_uploadflagmembership" ADD COLUMN "report_session_id" bigint NOT NULL; - -- - -- Add field flags to reportsession - -- - -- - -- Add field report to reportsession - -- - ALTER TABLE "reports_upload" ADD COLUMN "report_id" bigint NOT NULL; - ALTER TABLE "reports_commitreport" ADD CONSTRAINT "reports_commitreport_commit_id_06d0bd39_fk_commits_id" FOREIGN KEY ("commit_id") REFERENCES "commits" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_commitreport_commit_id_06d0bd39" ON "reports_commitreport" ("commit_id"); - ALTER TABLE "reports_reportdetails" ADD CONSTRAINT "reports_reportdetail_report_id_4681bfd3_fk_reports_c" FOREIGN KEY ("report_id") REFERENCES "reports_commitreport" ("id") DEFERRABLE INITIALLY DEFERRED; - ALTER TABLE "reports_reportleveltotals" ADD CONSTRAINT "reports_reportlevelt_report_id_b690dffa_fk_reports_c" FOREIGN KEY ("report_id") REFERENCES "reports_commitreport" ("id") DEFERRABLE INITIALLY DEFERRED; - ALTER TABLE "reports_uploaderror" ADD CONSTRAINT "reports_reportsessio_report_session_id_bb6563f1_fk_reports_r" FOREIGN KEY ("report_session_id") REFERENCES "reports_upload" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_uploaderror_report_session_id_bb6563f1" ON "reports_uploaderror" ("report_session_id"); - ALTER TABLE "reports_repositoryflag" ADD CONSTRAINT "reports_repositoryflag_repository_id_9b64b64c_fk_repos_repoid" FOREIGN KEY ("repository_id") REFERENCES "repos" ("repoid") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_repositoryflag_repository_id_9b64b64c" ON "reports_repositoryflag" ("repository_id"); - ALTER TABLE "reports_sessionleveltotals" ADD CONSTRAINT "reports_sessionlevel_report_session_id_e2cd6669_fk_reports_r" FOREIGN KEY ("report_session_id") REFERENCES "reports_upload" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_uploadflagmembership_flag_id_59edee69" ON "reports_uploadflagmembership" ("flag_id"); - ALTER TABLE "reports_uploadflagmembership" ADD CONSTRAINT "reports_reportsessio_flag_id_59edee69_fk_reports_r" FOREIGN KEY ("flag_id") REFERENCES "reports_repositoryflag" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_uploadflagmembership_report_session_id_7d7f9546" ON "reports_uploadflagmembership" ("report_session_id"); - ALTER TABLE "reports_uploadflagmembership" ADD CONSTRAINT "reports_reportsessio_report_session_id_7d7f9546_fk_reports_r" FOREIGN KEY ("report_session_id") REFERENCES "reports_upload" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_upload_report_id_f6b4ffae" ON "reports_upload" ("report_id"); - ALTER TABLE "reports_upload" ADD CONSTRAINT "reports_reportsessio_report_id_f6b4ffae_fk_reports_c" FOREIGN KEY ("report_id") REFERENCES "reports_commitreport" ("id") DEFERRABLE INITIALLY DEFERRED; - COMMIT; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v455.py b/legacy_migrations/migrations/legacy_sql/upgrades/v455.py deleted file mode 100644 index dc5c815898..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v455.py +++ /dev/null @@ -1,14 +0,0 @@ -# v4.5.5 -def run_sql(schema_editor): - schema_editor.execute( - """ - ALTER TABLE "reports_uploaderror" RENAME COLUMN "report_session_id" TO "upload_id"; - ALTER TABLE "reports_uploadflagmembership" RENAME COLUMN "report_session_id" TO "upload_id"; - ALTER TABLE "reports_sessionleveltotals" RENAME COLUMN "report_session_id" TO "upload_id"; - - ALTER TABLE "reports_upload" ADD COLUMN "upload_extras" jsonb NOT NULL; - ALTER TABLE "reports_upload" ADD COLUMN "upload_type" varchar(100) NOT NULL; - - ALTER TABLE "reports_sessionleveltotals" RENAME TO "reports_uploadleveltotals"; - """ - ) diff --git a/legacy_migrations/migrations/legacy_sql/upgrades/v461.py b/legacy_migrations/migrations/legacy_sql/upgrades/v461.py deleted file mode 100644 index a78b089085..0000000000 --- a/legacy_migrations/migrations/legacy_sql/upgrades/v461.py +++ /dev/null @@ -1,12 +0,0 @@ -# v4.6.1 -def run_sql(schema_editor): - schema_editor.execute( - """ - ALTER TABLE reports_uploadleveltotals ALTER COLUMN coverage DROP NOT NULL; - ALTER TABLE reports_reportleveltotals ALTER COLUMN coverage DROP NOT NULL; - - ALTER TABLE owners ALTER COLUMN student SET DEFAULT FALSE; - - UPDATE owners SET student=false WHERE student is NULL; - """ - ) diff --git a/reports/migrations/0001_initial.py b/reports/migrations/0001_initial.py deleted file mode 100644 index b9dcf7b87c..0000000000 --- a/reports/migrations/0001_initial.py +++ /dev/null @@ -1,208 +0,0 @@ -# Generated by Django 3.1.6 on 2021-04-08 19:33 - -import uuid - -import django.contrib.postgres.fields -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - initial = True - - dependencies = [("core", "0001_initial")] - - operations = [ - migrations.CreateModel( - name="CommitReport", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ( - "commit", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="reports", - to="core.commit", - ), - ), - ], - options={"abstract": False}, - ), - migrations.CreateModel( - name="ReportSession", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("build_code", models.TextField(null=True)), - ("build_url", models.TextField(null=True)), - ("env", models.JSONField(null=True)), - ("job_code", models.TextField(null=True)), - ("name", models.CharField(max_length=100, null=True)), - ("provider", models.CharField(max_length=50, null=True)), - ("state", models.CharField(max_length=100)), - ("storage_path", models.TextField()), - ("order_number", models.IntegerField(null=True)), - ("upload_type", models.CharField(max_length=100, default="uploaded")), - ("upload_extras", models.JSONField(default=dict)), - ], - options={"db_table": "reports_upload"}, - ), - migrations.CreateModel( - name="SessionLevelTotals", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("branches", models.IntegerField()), - ("coverage", models.DecimalField(decimal_places=2, max_digits=7)), - ("hits", models.IntegerField()), - ("lines", models.IntegerField()), - ("methods", models.IntegerField()), - ("misses", models.IntegerField()), - ("partials", models.IntegerField()), - ("files", models.IntegerField()), - ( - "report_session", - models.OneToOneField( - db_column="upload_id", - on_delete=django.db.models.deletion.CASCADE, - to="reports.reportsession", - ), - ), - ], - options={"db_table": "reports_uploadleveltotals"}, - ), - migrations.CreateModel( - name="RepositoryFlag", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("flag_name", models.CharField(max_length=255)), - ( - "repository", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="flags", - to="core.repository", - ), - ), - ], - options={"abstract": False}, - ), - migrations.CreateModel( - name="ReportSessionFlagMembership", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ( - "flag", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="reports.repositoryflag", - ), - ), - ( - "report_session", - models.ForeignKey( - db_column="upload_id", - on_delete=django.db.models.deletion.CASCADE, - to="reports.reportsession", - ), - ), - ], - options={"db_table": "reports_uploadflagmembership"}, - ), - migrations.CreateModel( - name="ReportSessionError", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("error_code", models.CharField(max_length=100)), - ("error_params", models.JSONField(default=dict)), - ( - "report_session", - models.ForeignKey( - db_column="upload_id", - on_delete=django.db.models.deletion.CASCADE, - related_name="errors", - to="reports.reportsession", - ), - ), - ], - options={"db_table": "reports_uploaderror"}, - ), - migrations.AddField( - model_name="reportsession", - name="flags", - field=models.ManyToManyField( - through="reports.ReportSessionFlagMembership", - to="reports.RepositoryFlag", - ), - ), - migrations.AddField( - model_name="reportsession", - name="report", - field=models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="sessions", - to="reports.commitreport", - ), - ), - migrations.CreateModel( - name="ReportLevelTotals", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("branches", models.IntegerField()), - ("coverage", models.DecimalField(decimal_places=2, max_digits=7)), - ("hits", models.IntegerField()), - ("lines", models.IntegerField()), - ("methods", models.IntegerField()), - ("misses", models.IntegerField()), - ("partials", models.IntegerField()), - ("files", models.IntegerField()), - ( - "report", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to="reports.commitreport", - ), - ), - ], - options={"abstract": False}, - ), - migrations.CreateModel( - name="ReportDetails", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ( - "files_array", - django.contrib.postgres.fields.ArrayField( - base_field=models.JSONField(), size=None - ), - ), - ( - "report", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to="reports.commitreport", - ), - ), - ], - options={"abstract": False}, - ), - ] diff --git a/reports/migrations/0002_auto_20211006_2211.py b/reports/migrations/0002_auto_20211006_2211.py deleted file mode 100644 index 7253189b39..0000000000 --- a/reports/migrations/0002_auto_20211006_2211.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.13 on 2021-10-06 22:11 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [("reports", "0001_initial")] - - operations = [ - migrations.RenameModel(old_name="ReportSessionError", new_name="UploadError"), - migrations.RenameModel( - old_name="ReportSessionFlagMembership", new_name="UploadFlagMembership" - ), - migrations.RenameModel( - old_name="SessionLevelTotals", new_name="UploadLevelTotals" - ), - ] diff --git a/reports/migrations/0003_auto_20211118_1150.py b/reports/migrations/0003_auto_20211118_1150.py deleted file mode 100644 index 6befe13a8c..0000000000 --- a/reports/migrations/0003_auto_20211118_1150.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.1.13 on 2021-11-18 11:50 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [("reports", "0002_auto_20211006_2211")] - - operations = [ - migrations.AddField( - model_name="reportsession", - name="state_id", - field=models.IntegerField( - choices=[(1, "uploaded"), (2, "processed"), (3, "error")], null=True - ), - ), - migrations.AddField( - model_name="reportsession", - name="upload_type_id", - field=models.IntegerField( - choices=[(1, "uploaded"), (2, "carryforwarded")], null=True - ), - ), - ] diff --git a/reports/migrations/0004_commitreport_code.py b/reports/migrations/0004_commitreport_code.py deleted file mode 100644 index 4aece450bd..0000000000 --- a/reports/migrations/0004_commitreport_code.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.12 on 2022-09-22 15:08 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("reports", "0003_auto_20211118_1150"), - ] - - operations = [ - migrations.AddField( - model_name="commitreport", - name="code", - field=models.CharField(max_length=100, null=True), - ), - ] diff --git a/reports/migrations/0005_auto_20221114_1428.py b/reports/migrations/0005_auto_20221114_1428.py deleted file mode 100644 index e5be5b19b3..0000000000 --- a/reports/migrations/0005_auto_20221114_1428.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 3.2.12 on 2022-11-14 14:28 - -import uuid - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("reports", "0004_commitreport_code"), - ] - - operations = [ - migrations.CreateModel( - name="ReportResults", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ( - "state", - models.TextField( - choices=[("created", "Created"), ("ready", "Ready")], null=True - ), - ), - ("completed_at", models.DateTimeField(null=True)), - ("result", models.JSONField(default=dict)), - ( - "report", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to="reports.commitreport", - ), - ), - ], - options={ - "abstract": False, - }, - ), - ] diff --git a/reports/migrations/0006_auto_20221212_1111.py b/reports/migrations/0006_auto_20221212_1111.py deleted file mode 100644 index 60ee202bb2..0000000000 --- a/reports/migrations/0006_auto_20221212_1111.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.12 on 2022-12-12 11:11 - -from django.db import migrations - - -class Migration(migrations.Migration): - atomic = False - - dependencies = [ - ("reports", "0005_auto_20221114_1428"), - ] - - operations = [ - migrations.RunSQL( - 'CREATE UNIQUE INDEX CONCURRENTLY unique_commit_id_code_idx ON reports_commitreport ("commit_id", "code");' - ), - ] diff --git a/reports/migrations/0007_auto_20230220_1245.py b/reports/migrations/0007_auto_20230220_1245.py deleted file mode 100644 index 63db8c5c06..0000000000 --- a/reports/migrations/0007_auto_20230220_1245.py +++ /dev/null @@ -1,16 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-20 12:45 - -from django.db import migrations -from shared.django_apps.migration_utils import RiskyRunSQL - - -class Migration(migrations.Migration): - dependencies = [ - ("reports", "0006_auto_20221212_1111"), - ] - - operations = [ - RiskyRunSQL( - 'ALTER TABLE "reports_commitreport" ADD CONSTRAINT "unique_commit_id_code" UNIQUE USING INDEX unique_commit_id_code_idx;' - ), - ] diff --git a/reports/migrations/0008_auto_20230228_1059.py b/reports/migrations/0008_auto_20230228_1059.py deleted file mode 100644 index fa7af32a3b..0000000000 --- a/reports/migrations/0008_auto_20230228_1059.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-28 10:59 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("reports", "0007_auto_20230220_1245"), - ] - - operations = [ - migrations.AlterField( - model_name="reportresults", - name="state", - field=models.TextField( - choices=[ - ("pending", "Pending"), - ("completed", "Completed"), - ("error", "Error"), - ], - null=True, - ), - ), - ] diff --git a/reports/migrations/0009_auto_20230223_1624.py b/reports/migrations/0009_auto_20230223_1624.py deleted file mode 100644 index 347fca49c9..0000000000 --- a/reports/migrations/0009_auto_20230223_1624.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 3.2.12 on 2023-02-23 16:24 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("reports", "0008_auto_20230228_1059"), - ] - - operations = [ - migrations.AddField( - model_name="repositoryflag", - name="deleted", - field=models.BooleanField(null=True), - ), - migrations.AlterField( - model_name="reportsession", - name="state_id", - field=models.IntegerField( - choices=[ - (1, "UPLOADED"), - (2, "PROCESSED"), - (3, "ERROR"), - (4, "FULLY_OVERWRITTEN"), - (5, "PARTIALLY_OVERWRITTEN"), - ], - null=True, - ), - ), - migrations.AlterField( - model_name="reportsession", - name="upload_type_id", - field=models.IntegerField( - choices=[(1, "UPLOADED"), (2, "CARRIEDFORWARD")], null=True - ), - ), - ] diff --git a/reports/migrations/0010_alter_reportdetails_files_array_and_more.py b/reports/migrations/0010_alter_reportdetails_files_array_and_more.py deleted file mode 100644 index 187b3de92e..0000000000 --- a/reports/migrations/0010_alter_reportdetails_files_array_and_more.py +++ /dev/null @@ -1,60 +0,0 @@ -# Generated by Django 4.1.7 on 2023-05-29 14:15 - -import django.contrib.postgres.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - # Generated SQL - # BEGIN; - # -- - # -- Alter field files_array on reportdetails - # -- - # -- (no-op) - # -- - # -- Rename field files_array on reportdetails to _files_array - # -- - # -- (no-op) - # -- - # -- Add field _files_array_storage_path to reportdetails - # -- - # ALTER TABLE "reports_reportdetails" ADD COLUMN "files_array_storage_path" varchar(200) NULL; - # -- - # -- Alter field _files_array on reportdetails - # -- - # ALTER TABLE "reports_reportdetails" ALTER COLUMN "files_array" DROP NOT NULL; - # COMMIT; - - dependencies = [ - ("reports", "0009_auto_20230223_1624"), - ] - - operations = [ - migrations.AlterField( - model_name="reportdetails", - name="files_array", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.JSONField(), db_column="files_array", size=None - ), - ), - migrations.RenameField( - model_name="reportdetails", - old_name="files_array", - new_name="_files_array", - ), - migrations.AddField( - model_name="reportdetails", - name="_files_array_storage_path", - field=models.URLField(db_column="files_array_storage_path", null=True), - ), - migrations.AlterField( - model_name="reportdetails", - name="_files_array", - field=django.contrib.postgres.fields.ArrayField( - base_field=models.JSONField(), - db_column="files_array", - null=True, - size=None, - ), - ), - ] diff --git a/reports/migrations/0011_commitreport_report_type.py b/reports/migrations/0011_commitreport_report_type.py deleted file mode 100644 index f35133697b..0000000000 --- a/reports/migrations/0011_commitreport_report_type.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 4.2.7 on 2023-12-06 13:28 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Add field report_type to commitreport - -- - ALTER TABLE "reports_commitreport" ADD COLUMN "report_type" varchar(100) NULL; - COMMIT; - """ - - dependencies = [ - ("reports", "0010_alter_reportdetails_files_array_and_more"), - ] - - operations = [ - migrations.AddField( - model_name="commitreport", - name="report_type", - field=models.CharField( - choices=[ - ("coverage", "Coverage"), - ("test_results", "Test Results"), - ("bundle_analysis", "Bundle Analysis"), - ], - max_length=100, - null=True, - ), - ), - ] diff --git a/reports/migrations/0012_alter_repositoryflag_flag_name.py b/reports/migrations/0012_alter_repositoryflag_flag_name.py deleted file mode 100644 index b5a00d44b1..0000000000 --- a/reports/migrations/0012_alter_repositoryflag_flag_name.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.2.7 on 2023-12-12 00:26 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("reports", "0011_commitreport_report_type"), - ] - - operations = [ - migrations.AlterField( - model_name="repositoryflag", - name="flag_name", - field=models.CharField(max_length=1024), - ), - ] diff --git a/reports/migrations/0013_test_testinstance.py b/reports/migrations/0013_test_testinstance.py deleted file mode 100644 index a04733b0a0..0000000000 --- a/reports/migrations/0013_test_testinstance.py +++ /dev/null @@ -1,94 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-17 20:41 - -import uuid - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Create model Test - -- - CREATE TABLE "reports_test" ("id" text NOT NULL PRIMARY KEY, "external_id" uuid NOT NULL, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "name" text NOT NULL, "testsuite" text NOT NULL, "env" text NOT NULL, "repoid" integer NOT NULL); - -- - -- Create model TestInstance - -- - CREATE TABLE "reports_testinstance" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "external_id" uuid NOT NULL, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "duration_seconds" double precision NOT NULL, "outcome" integer NOT NULL, "failure_message" text NULL, "test_id" text NOT NULL, "upload_id" bigint NOT NULL); - ALTER TABLE "reports_test" ADD CONSTRAINT "reports_test_repoid_445c33d7_fk_repos_repoid" FOREIGN KEY ("repoid") REFERENCES "repos" ("repoid") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_test_id_5c60c58c_like" ON "reports_test" ("id" text_pattern_ops); - CREATE INDEX "reports_test_repoid_445c33d7" ON "reports_test" ("repoid"); - ALTER TABLE "reports_testinstance" ADD CONSTRAINT "reports_testinstance_test_id_9c8dd6c1_fk_reports_test_id" FOREIGN KEY ("test_id") REFERENCES "reports_test" ("id") DEFERRABLE INITIALLY DEFERRED; - ALTER TABLE "reports_testinstance" ADD CONSTRAINT "reports_testinstance_upload_id_7350520f_fk_reports_upload_id" FOREIGN KEY ("upload_id") REFERENCES "reports_upload" ("id") DEFERRABLE INITIALLY DEFERRED; - CREATE INDEX "reports_testinstance_test_id_9c8dd6c1" ON "reports_testinstance" ("test_id"); - CREATE INDEX "reports_testinstance_test_id_9c8dd6c1_like" ON "reports_testinstance" ("test_id" text_pattern_ops); - CREATE INDEX "reports_testinstance_upload_id_7350520f" ON "reports_testinstance" ("upload_id"); - COMMIT; - """ - - dependencies = [ - ("core", "0045_repository_languages_last_updated"), - ("reports", "0012_alter_repositoryflag_flag_name"), - ] - - operations = [ - migrations.CreateModel( - name="Test", - fields=[ - ("id", models.TextField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("name", models.TextField()), - ("testsuite", models.TextField()), - ("env", models.TextField()), - ( - "repository", - models.ForeignKey( - db_column="repoid", - on_delete=django.db.models.deletion.CASCADE, - related_name="tests", - to="core.repository", - ), - ), - ], - options={ - "db_table": "reports_test", - }, - ), - migrations.CreateModel( - name="TestInstance", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("duration_seconds", models.FloatField()), - ("outcome", models.IntegerField()), - ("failure_message", models.TextField(null=True)), - ( - "test", - models.ForeignKey( - db_column="test_id", - on_delete=django.db.models.deletion.CASCADE, - related_name="testinstances", - to="reports.test", - ), - ), - ( - "upload", - models.ForeignKey( - db_column="upload_id", - on_delete=django.db.models.deletion.CASCADE, - related_name="testinstances", - to="reports.reportsession", - ), - ), - ], - options={ - "db_table": "reports_testinstance", - }, - ), - ] diff --git a/reports/migrations/0014_rename_env_test_flags_hash_and_more.py b/reports/migrations/0014_rename_env_test_flags_hash_and_more.py deleted file mode 100644 index d42a2ccdbd..0000000000 --- a/reports/migrations/0014_rename_env_test_flags_hash_and_more.py +++ /dev/null @@ -1,54 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-24 22:47 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - """ - BEGIN; - -- - -- Rename field env on test to flags_hash - -- - ALTER TABLE "reports_test" RENAME COLUMN "env" TO "flags_hash"; - -- - -- Alter field outcome on testinstance - -- - ALTER TABLE "reports_testinstance" ALTER COLUMN "outcome" TYPE varchar(100) USING "outcome"::varchar(100); - -- - -- Create constraint reports_test_repoid_name_testsuite_flags_hash on model test - -- - ALTER TABLE "reports_test" ADD CONSTRAINT "reports_test_repoid_name_testsuite_flags_hash" UNIQUE ("repoid", "name", "testsuite", "flags_hash"); - COMMIT; - """ - - dependencies = [ - ("reports", "0013_test_testinstance"), - ] - - operations = [ - migrations.RenameField( - model_name="test", - old_name="env", - new_name="flags_hash", - ), - migrations.AlterField( - model_name="testinstance", - name="outcome", - field=models.CharField( - choices=[ - ("failure", "Failure"), - ("skip", "Skip"), - ("error", "Error"), - ("pass", "Pass"), - ], - max_length=100, - ), - ), - migrations.AddConstraint( - model_name="test", - constraint=models.UniqueConstraint( - fields=("repository", "name", "testsuite", "flags_hash"), - name="reports_test_repoid_name_testsuite_flags_hash", - ), - ), - ] diff --git a/reports/migrations/0015_testresultreporttotals.py b/reports/migrations/0015_testresultreporttotals.py deleted file mode 100644 index f383d2e68b..0000000000 --- a/reports/migrations/0015_testresultreporttotals.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 4.2.7 on 2024-02-08 21:30 - -import uuid - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("reports", "0014_rename_env_test_flags_hash_and_more"), - ] - - operations = [ - migrations.CreateModel( - name="TestResultReportTotals", - fields=[ - ("id", models.BigAutoField(primary_key=True, serialize=False)), - ("external_id", models.UUIDField(default=uuid.uuid4, editable=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("updated_at", models.DateTimeField(auto_now=True)), - ("passed", models.IntegerField()), - ("skipped", models.IntegerField()), - ("failed", models.IntegerField()), - ( - "report", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to="reports.commitreport", - ), - ), - ], - options={ - "db_table": "reports_testresultreporttotals", - }, - ), - ] diff --git a/reports/migrations/__init__.py b/reports/migrations/__init__.py deleted file mode 100644 index e69de29bb2..0000000000