Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit d5d7c20

Browse files
feat: Create plans and tiers tables (#467)
* first pass to the plans and tiers tables * remove comments * fix linting * resolve comments * update with migration * update with correct name * create factories * add app-label back * update name of tables --------- Co-authored-by: Ajay Singh <[email protected]>
1 parent 07b39b2 commit d5d7c20

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Generated by Django 4.2.16 on 2025-01-14 18:09
2+
3+
import django.contrib.postgres.fields
4+
import django.db.models.deletion
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
"""
10+
BEGIN;
11+
--
12+
-- Create model Tier
13+
--
14+
CREATE TABLE "codecov_auth_tier" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "tier_name" varchar(255) NOT NULL UNIQUE, "bundle_analysis" boolean NOT NULL, "test_analytics" boolean NOT NULL, "flaky_test_detection" boolean NOT NULL, "project_coverage" boolean NOT NULL, "private_repo_support" boolean NOT NULL);
15+
--
16+
-- Create model Plan
17+
--
18+
CREATE TABLE "codecov_auth_plan" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "base_unit_price" integer NOT NULL, "benefits" text[] NOT NULL, "billing_rate" text NULL, "is_active" boolean NOT NULL, "marketing_name" varchar(255) NOT NULL, "max_seats" integer NULL, "monthly_uploads_limit" integer NULL, "paid_plan" boolean NOT NULL, "name" varchar(255) NOT NULL UNIQUE, "tier_id" bigint NOT NULL);
19+
CREATE INDEX "codecov_auth_tier_tier_name_ec8e98b1_like" ON "codecov_auth_tier" ("tier_name" varchar_pattern_ops);
20+
ALTER TABLE "codecov_auth_plan" ADD CONSTRAINT "codecov_auth_plan_tier_id_7847a9eb_fk_codecov_auth_tier_id" FOREIGN KEY ("tier_id") REFERENCES "codecov_auth_tier" ("id") DEFERRABLE INITIALLY DEFERRED;
21+
CREATE INDEX "codecov_auth_plan_name_e2fccac6_like" ON "codecov_auth_plan" ("name" varchar_pattern_ops);
22+
CREATE INDEX "codecov_auth_plan_tier_id_7847a9eb" ON "codecov_auth_plan" ("tier_id");
23+
COMMIT;
24+
"""
25+
26+
dependencies = [
27+
("codecov_auth", "0062_alter_owner_upload_token_required_for_public_repos"),
28+
]
29+
30+
operations = [
31+
migrations.CreateModel(
32+
name="Tier",
33+
fields=[
34+
("id", models.BigAutoField(primary_key=True, serialize=False)),
35+
("created_at", models.DateTimeField(auto_now_add=True)),
36+
("updated_at", models.DateTimeField(auto_now=True)),
37+
("tier_name", models.CharField(max_length=255, unique=True)),
38+
("bundle_analysis", models.BooleanField(default=False)),
39+
("test_analytics", models.BooleanField(default=False)),
40+
("flaky_test_detection", models.BooleanField(default=False)),
41+
("project_coverage", models.BooleanField(default=False)),
42+
("private_repo_support", models.BooleanField(default=False)),
43+
],
44+
options={
45+
"abstract": False,
46+
},
47+
),
48+
migrations.CreateModel(
49+
name="Plan",
50+
fields=[
51+
("id", models.BigAutoField(primary_key=True, serialize=False)),
52+
("created_at", models.DateTimeField(auto_now_add=True)),
53+
("updated_at", models.DateTimeField(auto_now=True)),
54+
("base_unit_price", models.IntegerField(blank=True, default=0)),
55+
(
56+
"benefits",
57+
django.contrib.postgres.fields.ArrayField(
58+
base_field=models.TextField(),
59+
blank=True,
60+
default=list,
61+
size=None,
62+
),
63+
),
64+
(
65+
"billing_rate",
66+
models.TextField(
67+
blank=True,
68+
choices=[("monthly", "Monthly"), ("annually", "Annually")],
69+
null=True,
70+
),
71+
),
72+
("is_active", models.BooleanField(default=True)),
73+
("marketing_name", models.CharField(max_length=255)),
74+
("max_seats", models.IntegerField(blank=True, null=True)),
75+
("monthly_uploads_limit", models.IntegerField(blank=True, null=True)),
76+
("paid_plan", models.BooleanField(default=False)),
77+
("name", models.CharField(max_length=255, unique=True)),
78+
(
79+
"tier",
80+
models.ForeignKey(
81+
on_delete=django.db.models.deletion.CASCADE,
82+
related_name="plans",
83+
to="codecov_auth.tier",
84+
),
85+
),
86+
],
87+
options={
88+
"abstract": False,
89+
},
90+
),
91+
]

shared/django_apps/codecov_auth/models.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,3 +997,46 @@ def save(self, *args, **kwargs):
997997
id=self.id
998998
).update(is_active=False)
999999
return super().save(*args, **kwargs)
1000+
1001+
1002+
class BillingRate(models.TextChoices):
1003+
MONTHLY = "monthly"
1004+
ANNUALLY = "annually"
1005+
1006+
1007+
class Plan(BaseModel):
1008+
tier = models.ForeignKey("Tier", on_delete=models.CASCADE, related_name="plans")
1009+
base_unit_price = models.IntegerField(default=0, blank=True)
1010+
benefits = ArrayField(models.TextField(), blank=True, default=list)
1011+
billing_rate = models.TextField(
1012+
choices=BillingRate.choices,
1013+
null=True,
1014+
blank=True,
1015+
)
1016+
is_active = models.BooleanField(default=True)
1017+
marketing_name = models.CharField(max_length=255)
1018+
max_seats = models.IntegerField(null=True, blank=True)
1019+
monthly_uploads_limit = models.IntegerField(null=True, blank=True)
1020+
paid_plan = models.BooleanField(default=False)
1021+
name = models.CharField(max_length=255, unique=True)
1022+
1023+
class Meta:
1024+
app_label = CODECOV_AUTH_APP_LABEL
1025+
1026+
def __str__(self):
1027+
return self.name
1028+
1029+
1030+
class Tier(BaseModel):
1031+
tier_name = models.CharField(max_length=255, unique=True)
1032+
bundle_analysis = models.BooleanField(default=False)
1033+
test_analytics = models.BooleanField(default=False)
1034+
flaky_test_detection = models.BooleanField(default=False)
1035+
project_coverage = models.BooleanField(default=False)
1036+
private_repo_support = models.BooleanField(default=False)
1037+
1038+
class Meta:
1039+
app_label = CODECOV_AUTH_APP_LABEL
1040+
1041+
def __str__(self):
1042+
return self.tier_name

shared/django_apps/codecov_auth/tests/factories.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
OrganizationLevelToken,
1414
Owner,
1515
OwnerProfile,
16+
Plan,
1617
SentryUser,
1718
Session,
1819
StripeBilling,
20+
Tier,
1921
TokenTypeChoices,
2022
User,
2123
UserToken,
@@ -169,3 +171,26 @@ class Meta:
169171
model = InvoiceBilling
170172

171173
account = factory.SubFactory(Account)
174+
175+
176+
class TierFactory(DjangoModelFactory):
177+
class Meta:
178+
model = Tier
179+
180+
tier_name = factory.Faker("name")
181+
182+
183+
class PlanFactory(DjangoModelFactory):
184+
class Meta:
185+
model = Plan
186+
187+
base_unit_price = factory.Faker("pyint")
188+
benefits = []
189+
billing_rate = None
190+
is_active = True
191+
marketing_name = factory.Faker("name")
192+
max_seats = None
193+
monthly_uploads_limit = None
194+
paid_plan = True
195+
name = factory.Faker("name")
196+
tier = factory.SubFactory(TierFactory)

0 commit comments

Comments
 (0)