|
| 1 | +-- Migration script: mysql_virtual_recipient_blacklist → recipient_blacklist |
| 2 | +-- |
| 3 | +-- This script migrates from the old table name to the new standardized name |
| 4 | +-- Run this after updating the PostfixAdmin code |
| 5 | + |
| 6 | +-- Step 1: Create the new table with the correct name |
| 7 | +CREATE TABLE IF NOT EXISTS `recipient_blacklist` ( |
| 8 | + `id` int(11) NOT NULL AUTO_INCREMENT, |
| 9 | + `address` varchar(255) NOT NULL COMMENT 'Email address or pattern (e.g., bad@domain.com or @spammer.com)', |
| 10 | + `action` varchar(20) NOT NULL DEFAULT 'REJECT' COMMENT 'Action to take: REJECT, DISCARD, DEFER', |
| 11 | + `domain` varchar(255) NOT NULL DEFAULT '' COMMENT 'Domain for organization/filtering', |
| 12 | + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 13 | + `modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 14 | + `active` tinyint(1) NOT NULL DEFAULT 1, |
| 15 | + PRIMARY KEY (`id`), |
| 16 | + UNIQUE KEY `address` (`address`), |
| 17 | + KEY `domain` (`domain`), |
| 18 | + KEY `active` (`active`) |
| 19 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Recipient blacklist for email rejection/filtering'; |
| 20 | + |
| 21 | +-- Step 2: Migrate data from old table if it exists |
| 22 | +INSERT IGNORE INTO recipient_blacklist (address, action, domain, created, modified, active) |
| 23 | +SELECT address, action, domain, created, modified, active |
| 24 | +FROM mysql_virtual_recipient_blacklist |
| 25 | +WHERE NOT EXISTS (SELECT 1 FROM recipient_blacklist WHERE recipient_blacklist.address = mysql_virtual_recipient_blacklist.address); |
| 26 | + |
| 27 | +-- Step 3: Verify data migration |
| 28 | +SELECT 'Old table count:' as info, COUNT(*) as count FROM mysql_virtual_recipient_blacklist |
| 29 | +UNION ALL |
| 30 | +SELECT 'New table count:' as info, COUNT(*) as count FROM recipient_blacklist; |
| 31 | + |
| 32 | +-- Step 4: After verifying data, uncomment the following line to drop the old table |
| 33 | +-- DROP TABLE mysql_virtual_recipient_blacklist; |
0 commit comments