diff --git a/privaterelay/migrations/0011_alter_abusemetrics_table_alter_profile_table.py b/privaterelay/migrations/0011_alter_abusemetrics_table_alter_profile_table.py deleted file mode 100644 index 714d373f1..000000000 --- a/privaterelay/migrations/0011_alter_abusemetrics_table_alter_profile_table.py +++ /dev/null @@ -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, - ), - ] diff --git a/privaterelay/models.py b/privaterelay/models.py index a7201ec96..51d9a2312 100644 --- a/privaterelay/models.py +++ b/privaterelay/models.py @@ -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"]