-
Notifications
You must be signed in to change notification settings - Fork 429
/
Copy path0036_remove_existing_constraints.py
57 lines (51 loc) · 2.25 KB
/
0036_remove_existing_constraints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Generated by Django 3.2.12 on 2022-02-17 17:14
from django.db import migrations
from core.migration_helpers import PostgresOnlyRunSQL
class Migration(migrations.Migration):
"""
Remove existing unique constraints. Note that only postgres supports these
constraints, so we don't need to worry about oracle / mysql as they will not exist
there in the first place.
"""
atomic = False
dependencies = [
("features", "0035_auto_20211109_0603"),
]
operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.RemoveConstraint(
model_name="featurestate",
name="unique_for_feature_segment",
),
migrations.RemoveConstraint(
model_name="featurestate",
name="unique_for_identity",
),
migrations.RemoveConstraint(
model_name="featurestate",
name="unique_for_environment",
),
],
database_operations=[
PostgresOnlyRunSQL(
'DROP INDEX CONCURRENTLY "unique_for_environment";',
reverse_sql="""CREATE UNIQUE INDEX CONCURRENTLY "unique_for_environment"
ON "features_featurestate" ("environment_id", "feature_id")
WHERE ("feature_segment_id" IS NULL AND "identity_id" IS NULL);""",
),
PostgresOnlyRunSQL(
'DROP INDEX CONCURRENTLY "unique_for_feature_segment";',
reverse_sql="""CREATE UNIQUE INDEX CONCURRENTLY "unique_for_feature_segment"
ON "features_featurestate" ("environment_id", "feature_id", "feature_segment_id")
WHERE "identity_id" IS NULL;""",
),
PostgresOnlyRunSQL(
'DROP INDEX CONCURRENTLY "unique_for_identity";',
reverse_sql="""CREATE UNIQUE INDEX CONCURRENTLY "unique_for_identity"
ON "features_featurestate" ("environment_id", "feature_id", "identity_id")
WHERE "feature_segment_id" IS NULL;""",
),
],
),
]