From 3735c513ae9bd407982fabb12a41cca905fcf78f Mon Sep 17 00:00:00 2001 From: usmannasir Date: Fri, 28 Nov 2025 15:08:49 +0500 Subject: [PATCH] Fix: Use upgrade.py for email filtering tables instead of Django migrations - Remove Django migration file that caused model resolution errors - Add CREATE TABLE statements to mailServerMigrations() in upgrade.py - Tables created: e_catchall, e_server_settings, e_plus_override, e_pattern_forwarding --- .../0001_email_filtering_features.py | 61 ------------------- plogical/upgrade.py | 52 ++++++++++++++++ 2 files changed, 52 insertions(+), 61 deletions(-) delete mode 100644 mailServer/migrations/0001_email_filtering_features.py diff --git a/mailServer/migrations/0001_email_filtering_features.py b/mailServer/migrations/0001_email_filtering_features.py deleted file mode 100644 index 4621970ee..000000000 --- a/mailServer/migrations/0001_email_filtering_features.py +++ /dev/null @@ -1,61 +0,0 @@ -# Generated migration for email filtering features -# Uses raw SQL since existing email models weren't created via Django migrations - -from django.db import migrations - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.RunSQL( - sql=""" - CREATE TABLE IF NOT EXISTS `e_catchall` ( - `domain_id` varchar(50) NOT NULL PRIMARY KEY, - `destination` varchar(255) NOT NULL, - `enabled` tinyint(1) NOT NULL DEFAULT 1, - CONSTRAINT `fk_catchall_domain` FOREIGN KEY (`domain_id`) REFERENCES `e_domains` (`domain`) ON DELETE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """, - reverse_sql="DROP TABLE IF EXISTS `e_catchall`;" - ), - migrations.RunSQL( - sql=""" - CREATE TABLE IF NOT EXISTS `e_server_settings` ( - `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, - `plus_addressing_enabled` tinyint(1) NOT NULL DEFAULT 0, - `plus_addressing_delimiter` varchar(1) NOT NULL DEFAULT '+' - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """, - reverse_sql="DROP TABLE IF EXISTS `e_server_settings`;" - ), - migrations.RunSQL( - sql=""" - CREATE TABLE IF NOT EXISTS `e_plus_override` ( - `domain_id` varchar(50) NOT NULL PRIMARY KEY, - `enabled` tinyint(1) NOT NULL DEFAULT 1, - CONSTRAINT `fk_plus_override_domain` FOREIGN KEY (`domain_id`) REFERENCES `e_domains` (`domain`) ON DELETE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """, - reverse_sql="DROP TABLE IF EXISTS `e_plus_override`;" - ), - migrations.RunSQL( - sql=""" - CREATE TABLE IF NOT EXISTS `e_pattern_forwarding` ( - `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, - `domain_id` varchar(50) NOT NULL, - `pattern` varchar(255) NOT NULL, - `destination` varchar(255) NOT NULL, - `pattern_type` varchar(20) NOT NULL DEFAULT 'wildcard', - `priority` int(11) NOT NULL DEFAULT 100, - `enabled` tinyint(1) NOT NULL DEFAULT 1, - CONSTRAINT `fk_pattern_domain` FOREIGN KEY (`domain_id`) REFERENCES `e_domains` (`domain`) ON DELETE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """, - reverse_sql="DROP TABLE IF EXISTS `e_pattern_forwarding`;" - ), - ] diff --git a/plogical/upgrade.py b/plogical/upgrade.py index aa7518778..6ba031d97 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -2258,6 +2258,58 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL except: pass + # Email Filtering Tables - Catch-All, Plus-Addressing, Pattern Forwarding + query = """CREATE TABLE IF NOT EXISTS `e_catchall` ( + `domain_id` varchar(50) NOT NULL, + `destination` varchar(255) NOT NULL, + `enabled` tinyint(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`domain_id`), + CONSTRAINT `fk_catchall_domain` FOREIGN KEY (`domain_id`) REFERENCES `e_domains` (`domain`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4""" + try: + cursor.execute(query) + except: + pass + + query = """CREATE TABLE IF NOT EXISTS `e_server_settings` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plus_addressing_enabled` tinyint(1) NOT NULL DEFAULT 0, + `plus_addressing_delimiter` varchar(1) NOT NULL DEFAULT '+', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4""" + try: + cursor.execute(query) + except: + pass + + query = """CREATE TABLE IF NOT EXISTS `e_plus_override` ( + `domain_id` varchar(50) NOT NULL, + `enabled` tinyint(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`domain_id`), + CONSTRAINT `fk_plus_override_domain` FOREIGN KEY (`domain_id`) REFERENCES `e_domains` (`domain`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4""" + try: + cursor.execute(query) + except: + pass + + query = """CREATE TABLE IF NOT EXISTS `e_pattern_forwarding` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `domain_id` varchar(50) NOT NULL, + `pattern` varchar(255) NOT NULL, + `destination` varchar(255) NOT NULL, + `pattern_type` varchar(20) NOT NULL DEFAULT 'wildcard', + `priority` int(11) NOT NULL DEFAULT 100, + `enabled` tinyint(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`id`), + KEY `fk_pattern_domain` (`domain_id`), + CONSTRAINT `fk_pattern_domain` FOREIGN KEY (`domain_id`) REFERENCES `e_domains` (`domain`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4""" + try: + cursor.execute(query) + except: + pass + try: connection.close() except: