Skip to content

Commit 030dfe8

Browse files
committed
Use constraints instead of unique_together
1 parent 671d425 commit 030dfe8

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Plain 0.3.0 on 2024-08-16 16:46
2+
3+
from plain import models
4+
from plain.models import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("plainflags", "0001_initial"),
10+
]
11+
12+
operations = [
13+
migrations.AlterUniqueTogether(
14+
name="flagresult",
15+
unique_together=set(),
16+
),
17+
migrations.AddConstraint(
18+
model_name="flagresult",
19+
constraint=models.UniqueConstraint(
20+
fields=("flag", "key"), name="unique_flag_result_key"
21+
),
22+
),
23+
]

plain-flags/plain/flags/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ class FlagResult(models.Model):
2525
value = models.JSONField()
2626

2727
class Meta:
28-
unique_together = ("flag", "key")
28+
constraints = [
29+
models.UniqueConstraint(
30+
fields=["flag", "key"], name="unique_flag_result_key"
31+
)
32+
]
2933

3034
def __str__(self):
3135
return self.key

plain-flags/tests/app/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
urlpatterns = []
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Plain 0.3.0 on 2024-08-16 16:46
2+
3+
from plain import models
4+
from plain.models import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("users", "__first__"),
10+
("plainoauth", "0004_alter_oauthconnection_access_token_and_more"),
11+
]
12+
13+
operations = [
14+
migrations.AlterUniqueTogether(
15+
name="oauthconnection",
16+
unique_together=set(),
17+
),
18+
migrations.AddConstraint(
19+
model_name="oauthconnection",
20+
constraint=models.UniqueConstraint(
21+
fields=("provider_key", "provider_user_id"),
22+
name="unique_oauth_provider_user_id",
23+
),
24+
),
25+
]

plain-oauth/plain/oauth/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ class OAuthConnection(models.Model):
4141
refresh_token_expires_at = models.DateTimeField(blank=True, null=True)
4242

4343
class Meta:
44-
unique_together = ("provider_key", "provider_user_id")
44+
constraints = [
45+
models.UniqueConstraint(
46+
fields=["provider_key", "provider_user_id"],
47+
name="unique_oauth_provider_user_id",
48+
)
49+
]
4550
ordering = ("provider_key",)
4651

4752
def __str__(self):

0 commit comments

Comments
 (0)