Skip to content

Commit 04edc7d

Browse files
committed
Add Django migrations for Award andbadge models
1 parent 71f25ea commit 04edc7d

File tree

2 files changed

+281
-0
lines changed

2 files changed

+281
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Generated by Django 5.2.5 on 2025-08-09 15:57
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("github", "0033_alter_release_published_at"),
10+
("nest", "0002_apikey"),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name="BadgeType",
16+
fields=[
17+
(
18+
"id",
19+
models.BigAutoField(
20+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
21+
),
22+
),
23+
("nest_created_at", models.DateTimeField(auto_now_add=True)),
24+
("nest_updated_at", models.DateTimeField(auto_now=True)),
25+
(
26+
"name",
27+
models.CharField(
28+
help_text="Badge type name (e.g., 'WASPY Award Winner')",
29+
max_length=100,
30+
unique=True,
31+
verbose_name="Name",
32+
),
33+
),
34+
(
35+
"description",
36+
models.TextField(
37+
blank=True,
38+
default="",
39+
help_text="Description of what this badge represents",
40+
verbose_name="Description",
41+
),
42+
),
43+
(
44+
"icon",
45+
models.CharField(
46+
blank=True,
47+
default="🏆",
48+
help_text="Icon class or emoji for the badge",
49+
max_length=50,
50+
verbose_name="Icon",
51+
),
52+
),
53+
(
54+
"color",
55+
models.CharField(
56+
blank=True,
57+
default="#FFD700",
58+
help_text="Badge color (hex code or CSS color name)",
59+
max_length=20,
60+
verbose_name="Color",
61+
),
62+
),
63+
(
64+
"is_active",
65+
models.BooleanField(
66+
default=True,
67+
help_text="Whether this badge type is currently active",
68+
verbose_name="Is Active",
69+
),
70+
),
71+
],
72+
options={
73+
"verbose_name": "Badge Type",
74+
"verbose_name_plural": "Badge Types",
75+
"db_table": "nest_badge_types",
76+
"ordering": ["name"],
77+
},
78+
),
79+
migrations.CreateModel(
80+
name="UserBadge",
81+
fields=[
82+
(
83+
"id",
84+
models.BigAutoField(
85+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
86+
),
87+
),
88+
("nest_created_at", models.DateTimeField(auto_now_add=True)),
89+
("nest_updated_at", models.DateTimeField(auto_now=True)),
90+
(
91+
"earned_at",
92+
models.DateTimeField(
93+
auto_now_add=True,
94+
help_text="When the badge was earned",
95+
verbose_name="Earned At",
96+
),
97+
),
98+
(
99+
"reason",
100+
models.TextField(
101+
blank=True,
102+
default="",
103+
help_text="Reason or context for earning this badge",
104+
verbose_name="Reason",
105+
),
106+
),
107+
(
108+
"metadata",
109+
models.JSONField(
110+
blank=True,
111+
default=dict,
112+
help_text="Additional metadata about the badge (e.g., award details)",
113+
verbose_name="Metadata",
114+
),
115+
),
116+
(
117+
"badge_type",
118+
models.ForeignKey(
119+
help_text="The type of badge earned",
120+
on_delete=django.db.models.deletion.CASCADE,
121+
related_name="user_badges",
122+
to="nest.badgetype",
123+
verbose_name="Badge Type",
124+
),
125+
),
126+
(
127+
"user",
128+
models.ForeignKey(
129+
help_text="The user who earned this badge",
130+
on_delete=django.db.models.deletion.CASCADE,
131+
related_name="badges",
132+
to="github.user",
133+
verbose_name="User",
134+
),
135+
),
136+
],
137+
options={
138+
"verbose_name": "User Badge",
139+
"verbose_name_plural": "User Badges",
140+
"db_table": "nest_user_badges",
141+
"ordering": ["-earned_at"],
142+
"indexes": [
143+
models.Index(fields=["user"], name="nest_user_badge_user_idx"),
144+
models.Index(fields=["badge_type"], name="nest_user_badge_type_idx"),
145+
models.Index(fields=["earned_at"], name="nest_user_badge_earned_at_idx"),
146+
],
147+
"constraints": [
148+
models.UniqueConstraint(
149+
fields=("user", "badge_type"), name="unique_user_badge_type"
150+
)
151+
],
152+
},
153+
),
154+
]
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Generated by Django 5.2.5 on 2025-08-09 15:56
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("github", "0033_alter_release_published_at"),
10+
("owasp", "0044_chapter_chapter_updated_at_desc_idx_and_more"),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name="Award",
16+
fields=[
17+
(
18+
"id",
19+
models.BigAutoField(
20+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
21+
),
22+
),
23+
("nest_created_at", models.DateTimeField(auto_now_add=True)),
24+
("nest_updated_at", models.DateTimeField(auto_now=True)),
25+
(
26+
"category",
27+
models.CharField(
28+
help_text="Award category (e.g., 'WASPY', 'Lifetime Achievement')",
29+
max_length=100,
30+
verbose_name="Category",
31+
),
32+
),
33+
(
34+
"name",
35+
models.CharField(
36+
help_text="Award name/title (e.g., 'Event Person of the Year')",
37+
max_length=200,
38+
verbose_name="Name",
39+
),
40+
),
41+
(
42+
"description",
43+
models.TextField(
44+
blank=True,
45+
default="",
46+
help_text="Award description",
47+
verbose_name="Description",
48+
),
49+
),
50+
(
51+
"year",
52+
models.IntegerField(
53+
blank=True,
54+
help_text="Year the award was given (null for category definitions)",
55+
null=True,
56+
verbose_name="Year",
57+
),
58+
),
59+
(
60+
"winner_name",
61+
models.CharField(
62+
blank=True,
63+
default="",
64+
help_text="Name of the award recipient",
65+
max_length=200,
66+
verbose_name="Winner Name",
67+
),
68+
),
69+
(
70+
"winner_info",
71+
models.TextField(
72+
blank=True,
73+
default="",
74+
help_text="Detailed information about the winner",
75+
verbose_name="Winner Information",
76+
),
77+
),
78+
(
79+
"winner_image",
80+
models.CharField(
81+
blank=True,
82+
default="",
83+
help_text="Path to winner's image",
84+
max_length=500,
85+
verbose_name="Winner Image",
86+
),
87+
),
88+
(
89+
"award_type",
90+
models.CharField(
91+
choices=[("category", "Category"), ("award", "Award")],
92+
default="award",
93+
help_text="Type of entry: category definition or individual award",
94+
max_length=20,
95+
verbose_name="Award Type",
96+
),
97+
),
98+
(
99+
"user",
100+
models.ForeignKey(
101+
blank=True,
102+
help_text="Associated GitHub user (if matched)",
103+
null=True,
104+
on_delete=django.db.models.deletion.SET_NULL,
105+
related_name="awards",
106+
to="github.user",
107+
verbose_name="User",
108+
),
109+
),
110+
],
111+
options={
112+
"verbose_name": "Award",
113+
"verbose_name_plural": "Awards",
114+
"db_table": "owasp_awards",
115+
"indexes": [
116+
models.Index(fields=["category", "year"], name="owasp_award_category_year"),
117+
models.Index(fields=["-year"], name="owasp_award_year_desc"),
118+
models.Index(fields=["name"], name="owasp_award_name"),
119+
],
120+
"constraints": [
121+
models.UniqueConstraint(
122+
fields=("name", "year", "category"), name="unique_award_name_year_category"
123+
)
124+
],
125+
},
126+
),
127+
]

0 commit comments

Comments
 (0)