drink-it-cold/sql/migrations/009_mailing.sql
torsten 5cce6ca86f feat(mailing): Kundenrundmail mit Empfängern aus Buchungen, Abmeldelink und Versandprotokoll
Empfänger kommen aus bookings.email (dedupliziert, ohne Abmeldungen), Text mit
{jahr}, Testmail an die eigene Adresse, Versand in Häppchen über mail_send().
Abmeldungen landen in mail_optouts und gelten für alle künftigen Rundmails.
Migration 009_mailing.sql, DSGVO-Verzeichnis und ROADMAP (Feature 18) ergänzt.
2026-11-30 08:11:06 +01:00

35 lines
1.5 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Kundenrundmail: Sperrliste (Abmeldungen) und Versandprotokoll.
-- Empfänger sind nicht gespeichert – sie werden je Kampagne aus bookings.email
-- gezogen (siehe app/mailing.php).
CREATE TABLE IF NOT EXISTS mail_optouts (
email VARCHAR(190) NOT NULL,
source VARCHAR(40) NOT NULL DEFAULT '',
created_at DATETIME NOT NULL,
PRIMARY KEY (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS mailings (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
subject VARCHAR(190) NOT NULL,
body TEXT NOT NULL,
recipient_count INT UNSIGNED NOT NULL DEFAULT 0,
sent_count INT UNSIGNED NOT NULL DEFAULT 0,
failed_count INT UNSIGNED NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL,
created_by BIGINT UNSIGNED NULL DEFAULT NULL,
finished_at DATETIME NULL DEFAULT NULL,
PRIMARY KEY (id),
KEY idx_mailings_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS mailing_recipients (
mailing_id BIGINT UNSIGNED NOT NULL,
email VARCHAR(190) NOT NULL,
status ENUM('pending', 'sent', 'failed') NOT NULL DEFAULT 'pending',
error VARCHAR(190) NOT NULL DEFAULT '',
sent_at DATETIME NULL DEFAULT NULL,
PRIMARY KEY (mailing_id, email),
KEY idx_mailing_recipients_status (mailing_id, status),
CONSTRAINT fk_mailing_recipients_mailing FOREIGN KEY (mailing_id) REFERENCES mailings (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;