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

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

@ -0,0 +1,56 @@
# 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):
schema_editor.execute('DROP TABLE IF EXISTS "emails_profile";')
schema_editor.execute('DROP TABLE IF EXISTS "emails_abusemetrics";')
schema_editor.execute('DROP VIEW IF EXISTS "emails_profile";')
schema_editor.execute('DROP VIEW IF EXISTS "emails_abusemetrics";')
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,9 +94,6 @@ 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"
@ -564,4 +561,3 @@ class AbuseMetrics(models.Model):
class Meta:
unique_together = ["user", "first_recorded"]
db_table = "emails_abusemetrics"