You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -24,20 +10,36 @@ class Migration(migrations.Migration):
24
10
]
25
11
26
12
operations= [
27
-
migrations.AddField(
28
-
model_name="challenge",
29
-
name="github_branch",
30
-
field=models.CharField(
31
-
blank=True, default="", max_length=200, null=True
13
+
migrations.RunSQL(
14
+
sql=(
15
+
"DO $$\n"
16
+
"BEGIN\n"
17
+
" IF NOT EXISTS (\n"
18
+
" SELECT 1 FROM information_schema.columns\n"
19
+
" WHERE table_name='challenge'\n"
20
+
" AND column_name='github_branch'\n"
21
+
" ) THEN\n"
22
+
" ALTER TABLE challenge ADD COLUMN github_branch "
23
+
"varchar(200) NULL DEFAULT '';\n"
24
+
" END IF;\n"
25
+
"END$$;"
26
+
),
27
+
reverse_sql=(
28
+
"ALTER TABLE challenge DROP COLUMN IF EXISTS github_branch;"
32
29
),
33
30
),
34
-
migrations.RunPython(
35
-
fix_duplicate_github_fields,
36
-
reverse_fix_duplicate_github_fields,
37
-
),
38
-
# Add a partial unique constraint that only applies when both fields are not empty
31
+
# Add a partial unique constraint
32
+
# Only applies when both fields are not empty
39
33
migrations.RunSQL(
40
-
"CREATE UNIQUE INDEX challenge_github_repo_branch_partial_idx ON challenge (github_repository, github_branch) WHERE github_repository != '' AND github_branch != '';",
41
-
reverse_sql="DROP INDEX IF EXISTS challenge_github_repo_branch_partial_idx;",
34
+
(
35
+
"CREATE UNIQUE INDEX challenge_github_repo_branch_partial_idx "
0 commit comments