This commit is contained in:
John Whitlock 2024-06-06 08:38:23 -05:00
Родитель cd4d4e0614
Коммит 5b390e9db9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 082C735D154FB750
2 изменённых файлов: 4 добавлений и 60 удалений

Просмотреть файл

@ -1,60 +0,0 @@
# Generated by Django 4.2.13 on 2024-06-05 19:23
from django.db import migrations
def add_view_forward_func(apps, schema_editor):
if schema_editor.connection.vendor.startswith("postgres"):
# Postgres views can be used in UPDATE, INSERT, DELETE statements
schema_editor.execute(
'CREATE VIEW "emails_profile" AS SELECT * FROM "privaterelay_profile";'
)
schema_editor.execute(
'CREATE VIEW "emails_abusemetrics" AS'
' SELECT * FROM "privaterelay_abusemetrics";'
)
elif schema_editor.connection.vendor.startswith("sqlite"):
# SQLite views can not. Just create look-alike DBs for migrations tests
schema_editor.execute(
'CREATE TABLE "emails_profile" AS SELECT * FROM "privaterelay_profile";'
)
schema_editor.execute(
'CREATE TABLE "emails_abusemetrics" AS'
' SELECT * FROM "privaterelay_abusemetrics";'
)
else:
raise Exception(f"Unknown vendor {schema_editor.connection.vendor=}")
def rm_view_reverse_func(apps, schema_editor):
if schema_editor.connection.vendor.startswith("postgres"):
schema_editor.execute('DROP VIEW IF EXISTS "emails_profile";')
schema_editor.execute('DROP VIEW IF EXISTS "emails_abusemetrics";')
elif schema_editor.connection.vendor.startswith("sqlite"):
schema_editor.execute('DROP TABLE IF EXISTS "emails_profile";')
schema_editor.execute('DROP TABLE IF EXISTS "emails_abusemetrics";')
else:
raise Exception(f"Unknown vendor {schema_editor.connection.vendor=}")
class Migration(migrations.Migration):
dependencies = [
("privaterelay", "0010_move_profile_and_abusemetrics"),
]
operations = [
migrations.AlterModelTable(
name="abusemetrics",
table=None,
),
migrations.AlterModelTable(
name="profile",
table=None,
),
migrations.RunPython(
code=add_view_forward_func,
reverse_code=rm_view_reverse_func,
elidable=True,
),
]

Просмотреть файл

@ -94,6 +94,9 @@ class Profile(models.Model):
sent_welcome_email = models.BooleanField(default=False)
last_engagement = models.DateTimeField(blank=True, null=True, db_index=True)
class Meta:
db_table = "emails_profile"
def __str__(self):
return f"{self.user} Profile"
@ -560,4 +563,5 @@ class AbuseMetrics(models.Model):
forwarded_email_size_per_day = models.PositiveBigIntegerField(default=0)
class Meta:
db_table = "emails_abusemetrics"
unique_together = ["user", "first_recorded"]