diff --git a/schema.sql b/schema.sql index 0f043b2..8e30495 100644 --- a/schema.sql +++ b/schema.sql @@ -1,189 +1,231 @@ -/* ======================================================================= - Email Template System — Schema passend zur api.php (2025-09-06) - Charset: utf8mb4 | Engine: InnoDB - Hinweis: - - Mandantenfähigkeit über customer_id (alle Haupttabellen + Items + Assets). - - Contentspalten: Templates/Sections/Blocks = `html`, Snippets = `content`. - - Referenzen: template_items (Section/Block) & section_items (Block). - ======================================================================= */ +-- Schema-Dump für `d044ae9e` (erstellt am 2025-12-07 02:21:49 UTC) +-- Hinweis: Es werden nur CREATE-Anweisungen ausgegeben, bestehende Tabellen bleiben unangetastet. -SET NAMES utf8mb4; -SET FOREIGN_KEY_CHECKS = 0; - -/* Drop-Reihenfolge: erst Items, dann Master-Tabellen */ -DROP TABLE IF EXISTS `emailtemplate_section_items`; -DROP TABLE IF EXISTS `emailtemplate_template_items`; -DROP TABLE IF EXISTS `emailtemplate_assets`; -DROP TABLE IF EXISTS `emailtemplate_snippets`; -DROP TABLE IF EXISTS `emailtemplate_blocks`; -DROP TABLE IF EXISTS `emailtemplate_sections`; -DROP TABLE IF EXISTS `emailtemplate_templates`; -DROP TABLE IF EXISTS `emailtemplate_customer_settings`; -/*DROP TABLE IF EXISTS `customers`; -- optional (nur falls lokal hier gepflegt) */ -/*DROP TABLE IF EXISTS `customer_users`; -- optional */ - -SET FOREIGN_KEY_CHECKS = 1; - -/* ========================= - Master-Tabellen - ========================= */ - -/* 1) Templates (oberste Ebene) */ -CREATE TABLE `emailtemplate_templates` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `customer_id` INT UNSIGNED NOT NULL, - `name` VARCHAR(255) NOT NULL, - `json_content` MEDIUMTEXT NULL, -- NEU: Speichert GrapesJS JSON-Zustand (Komponenten + Stile) - `html` MEDIUMTEXT NULL, -- BLEIBT: Speichert finalen, exportierten HTML-Code - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +-- Tabelle: customers +CREATE TABLE IF NOT EXISTS `customers` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(150) NOT NULL, + `slug` varchar(150) NOT NULL, + `plan` varchar(50) NOT NULL DEFAULT 'free', + `status` varchar(20) NOT NULL DEFAULT 'active', + `logo_url` varchar(255) DEFAULT NULL, + `theme_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`theme_json`)), + `created_at` timestamp NULL DEFAULT current_timestamp(), + `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), - KEY `idx_tpl_customer` (`customer_id`), - KEY `idx_tpl_updated` (`updated_at`), - KEY `idx_tpl_name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + UNIQUE KEY `slug` (`slug`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/* 2) Sections (optional einem Template zugeordnet) */ -CREATE TABLE `emailtemplate_sections` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `customer_id` INT UNSIGNED NOT NULL, - `template_id` INT UNSIGNED NULL, - `name` VARCHAR(255) NOT NULL, - `type` VARCHAR(50) NOT NULL DEFAULT 'html', - `json_content` MEDIUMTEXT NULL, -- NEU: Speichert GrapesJS JSON-Zustand (Komponenten + Stile) - `z_index` INT NOT NULL DEFAULT 0, - `html` MEDIUMTEXT NULL, -- BLEIBT: Speichert finalen, exportierten HTML-Code - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +-- Tabelle: customer_tokens +CREATE TABLE IF NOT EXISTS `customer_tokens` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `label` varchar(120) NOT NULL, + `token_hash` char(64) NOT NULL, + `scopes` varchar(255) DEFAULT NULL, + `is_active` tinyint(1) NOT NULL DEFAULT 1, + `created_at` timestamp NULL DEFAULT current_timestamp(), + `last_used_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uq_token_hash` (`token_hash`), + KEY `customer_id` (`customer_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: customer_users +CREATE TABLE IF NOT EXISTS `customer_users` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `email` varchar(190) NOT NULL, + `password_hash` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, + `role` varchar(30) NOT NULL DEFAULT 'editor', + `is_active` tinyint(1) NOT NULL DEFAULT 1, + `created_at` timestamp NULL DEFAULT current_timestamp(), + `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `uq_customer_email` (`customer_id`,`email`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_assets +CREATE TABLE IF NOT EXISTS `emailtemplate_assets` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `name` varchar(255) NOT NULL, + `type` varchar(50) NOT NULL, + `mime_type` varchar(100) NOT NULL, + `size_bytes` int(10) unsigned NOT NULL DEFAULT 0, + `public_url` varchar(1000) DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + KEY `idx_ast_customer` (`customer_id`), + KEY `idx_ast_updated` (`updated_at`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_blocks +CREATE TABLE IF NOT EXISTS `emailtemplate_blocks` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `section_id` int(10) unsigned DEFAULT NULL, + `name` varchar(255) NOT NULL, + `category` varchar(100) NOT NULL DEFAULT 'Default', + `json_content` mediumtext DEFAULT NULL, + `html` mediumtext DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + KEY `idx_blk_customer` (`customer_id`), + KEY `idx_blk_section` (`section_id`), + KEY `idx_blk_name` (`name`), + CONSTRAINT `fk_blocks_section` FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_customers +CREATE TABLE IF NOT EXISTS `emailtemplate_customers` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(150) NOT NULL, + `slug` varchar(150) NOT NULL, + `plan` varchar(50) NOT NULL DEFAULT 'free', + `status` varchar(20) NOT NULL DEFAULT 'active', + `logo_url` varchar(255) DEFAULT NULL, + `theme_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`theme_json`)), + `created_at` timestamp NULL DEFAULT current_timestamp(), + `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `slug` (`slug`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_customer_settings +CREATE TABLE IF NOT EXISTS `emailtemplate_customer_settings` ( + `customer_id` int(10) unsigned NOT NULL, + `bridge_url` varchar(500) DEFAULT NULL, + `bridge_token` varchar(255) DEFAULT NULL, + `sender_token` varchar(255) DEFAULT NULL, + `external_api_token` varchar(255) DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`customer_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_customer_tokens +CREATE TABLE IF NOT EXISTS `emailtemplate_customer_tokens` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `label` varchar(120) NOT NULL, + `token_hash` char(64) NOT NULL, + `scopes` varchar(255) DEFAULT NULL, + `is_active` tinyint(1) NOT NULL DEFAULT 1, + `created_at` timestamp NULL DEFAULT current_timestamp(), + `last_used_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uq_token_hash` (`token_hash`), + KEY `customer_id` (`customer_id`), + CONSTRAINT `emailtemplate_customer_tokens_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `emailtemplate_customers` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_customer_users +CREATE TABLE IF NOT EXISTS `emailtemplate_customer_users` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `email` varchar(190) NOT NULL, + `password_hash` varchar(255) NOT NULL, + `role` varchar(30) NOT NULL DEFAULT 'editor', + `is_active` tinyint(1) NOT NULL DEFAULT 1, + `created_at` timestamp NULL DEFAULT current_timestamp(), + `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `uq_customer_email` (`customer_id`,`email`), + CONSTRAINT `fk_customer_users_customer` FOREIGN KEY (`customer_id`) REFERENCES `emailtemplate_customers` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_sections +CREATE TABLE IF NOT EXISTS `emailtemplate_sections` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `template_id` int(10) unsigned DEFAULT NULL, + `name` varchar(255) NOT NULL, + `json_content` mediumtext DEFAULT NULL, + `type` varchar(50) NOT NULL DEFAULT 'html', + `z_index` int(11) NOT NULL DEFAULT 0, + `html` mediumtext DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), KEY `idx_sec_customer` (`customer_id`), KEY `idx_sec_template` (`template_id`), KEY `idx_sec_sort` (`template_id`,`z_index`,`id`), - CONSTRAINT `fk_sections_template` - FOREIGN KEY (`template_id`) REFERENCES `emailtemplate_templates` (`id`) - ON UPDATE CASCADE ON DELETE SET NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + CONSTRAINT `fk_sections_template` FOREIGN KEY (`template_id`) REFERENCES `emailtemplate_templates` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/* 3) Blocks (optional einer Section zugeordnet) */ -CREATE TABLE `emailtemplate_blocks` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `customer_id` INT UNSIGNED NOT NULL, - `section_id` INT UNSIGNED NULL, - `name` VARCHAR(255) NOT NULL, - `category` VARCHAR(100) NOT NULL DEFAULT 'Default', - `json_content` MEDIUMTEXT NULL, -- NEU: Speichert GrapesJS JSON-Zustand (Komponenten + Stile) - `html` MEDIUMTEXT NULL, -- BLEIBT: Speichert finalen, exportierten HTML-Code - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - KEY `idx_blk_customer` (`customer_id`), - KEY `idx_blk_section` (`section_id`), - KEY `idx_blk_name` (`name`), - CONSTRAINT `fk_blocks_section` - FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`) - ON UPDATE CASCADE ON DELETE SET NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -/* 4) Snippets (kleine Bausteine; BY VALUE) */ -CREATE TABLE `emailtemplate_snippets` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `customer_id` INT UNSIGNED NOT NULL, - `name` VARCHAR(255) NOT NULL, - `category` VARCHAR(100) NOT NULL DEFAULT '', - `json_content` MEDIUMTEXT NULL, -- NEU: Speichert GrapesJS JSON-Zustand - `content` MEDIUMTEXT NULL, -- BLEIBT: Speichert finalen, exportierten HTML-Code - `block_id` INT UNSIGNED NULL, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - KEY `idx_snp_customer` (`customer_id`), - KEY `idx_snp_name` (`name`), - KEY `idx_snp_block` (`block_id`), - CONSTRAINT `fk_snippets_block` - FOREIGN KEY (`block_id`) REFERENCES `emailtemplate_blocks` (`id`) - ON UPDATE CASCADE ON DELETE SET NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -/* 5) Assets (READ-only in api.php) */ -CREATE TABLE `emailtemplate_assets` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `customer_id` INT UNSIGNED NOT NULL, - `name` VARCHAR(255) NOT NULL, - `type` VARCHAR(50) NOT NULL, - `mime_type` VARCHAR(100) NOT NULL, - `size_bytes` INT UNSIGNED NOT NULL DEFAULT 0, - `public_url` VARCHAR(1000) NULL, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - KEY `idx_ast_customer` (`customer_id`), - KEY `idx_ast_updated` (`updated_at`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -/* ========================= - Referenz-Item-Tabellen - ========================= */ - -/* 6) Items im Template (Sections ODER Blocks als Referenz) */ -CREATE TABLE `emailtemplate_template_items` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `customer_id` INT UNSIGNED NOT NULL, - `template_id` INT UNSIGNED NOT NULL, - `sort` INT NOT NULL DEFAULT 0, - `ref_type` ENUM('section','block') NOT NULL, - `ref_id` INT UNSIGNED NOT NULL, - `overrides_json` JSON NULL, - `lock_to_version` INT NULL, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - KEY `idx_titems_template_sort` (`template_id`,`sort`), - KEY `idx_titems_customer` (`customer_id`), - KEY `idx_titems_ref` (`ref_type`,`ref_id`), - CONSTRAINT `fk_titems_template` - FOREIGN KEY (`template_id`) REFERENCES `emailtemplate_templates` (`id`) - ON UPDATE CASCADE ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -/* 7) Items in einer Section (NUR Blocks als Referenz) */ -CREATE TABLE `emailtemplate_section_items` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `customer_id` INT UNSIGNED NOT NULL, - `section_id` INT UNSIGNED NOT NULL, - `sort` INT NOT NULL DEFAULT 0, - `ref_type` ENUM('block') NOT NULL, - `ref_id` INT UNSIGNED NOT NULL, - `overrides_json` JSON NULL, - `lock_to_version` INT NULL, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +-- Tabelle: emailtemplate_section_items +CREATE TABLE IF NOT EXISTS `emailtemplate_section_items` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `section_id` int(10) unsigned NOT NULL, + `sort` int(11) NOT NULL DEFAULT 0, + `ref_type` enum('block') NOT NULL, + `ref_id` int(10) unsigned NOT NULL, + `overrides_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`overrides_json`)), + `lock_to_version` int(11) DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), KEY `idx_sitems_section_sort` (`section_id`,`sort`), KEY `idx_sitems_customer` (`customer_id`), KEY `idx_sitems_ref` (`ref_type`,`ref_id`), - CONSTRAINT `fk_sitems_section` - FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`) - ON UPDATE CASCADE ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + CONSTRAINT `fk_sitems_section` FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/* 8) Kundenbezogene Einstellungen (Bridge/Sender/API Tokens) */ -CREATE TABLE `emailtemplate_customer_settings` ( - `customer_id` INT UNSIGNED NOT NULL, - `bridge_url` VARCHAR(500) DEFAULT NULL, - `bridge_token` VARCHAR(255) DEFAULT NULL, - `sender_token` VARCHAR(255) DEFAULT NULL, - `external_api_token` VARCHAR(255) DEFAULT NULL, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`customer_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +-- Tabelle: emailtemplate_snippets +CREATE TABLE IF NOT EXISTS `emailtemplate_snippets` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `name` varchar(255) NOT NULL, + `category` varchar(100) NOT NULL DEFAULT '', + `json_content` mediumtext DEFAULT NULL, + `content` mediumtext DEFAULT NULL, + `block_id` int(10) unsigned DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + KEY `idx_snp_customer` (`customer_id`), + KEY `idx_snp_name` (`name`), + KEY `idx_snp_block` (`block_id`), + CONSTRAINT `fk_snippets_block` FOREIGN KEY (`block_id`) REFERENCES `emailtemplate_blocks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/* ========================= - Optionale Seed-Daten - ========================= */ --- INSERT INTO `emailtemplate_templates` (`customer_id`,`name`,`html`) VALUES (1,'Newsletter-Template',''); --- INSERT INTO `emailtemplate_sections` (`customer_id`,`name`,`type`,`z_index`,`html`,`template_id`) VALUES (1,'Hero','html',10,'
| {{children}} |
| ... |
Lorem ipsum…
'); +-- Tabelle: emailtemplate_templates +CREATE TABLE IF NOT EXISTS `emailtemplate_templates` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `name` varchar(255) NOT NULL, + `json_content` mediumtext DEFAULT NULL, + `html` mediumtext DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + KEY `idx_tpl_customer` (`customer_id`), + KEY `idx_tpl_updated` (`updated_at`), + KEY `idx_tpl_name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Tabelle: emailtemplate_template_items +CREATE TABLE IF NOT EXISTS `emailtemplate_template_items` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `customer_id` int(10) unsigned NOT NULL, + `template_id` int(10) unsigned NOT NULL, + `sort` int(11) NOT NULL DEFAULT 0, + `ref_type` enum('section','block') NOT NULL, + `ref_id` int(10) unsigned NOT NULL, + `overrides_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`overrides_json`)), + `lock_to_version` int(11) DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`id`), + KEY `idx_titems_template_sort` (`template_id`,`sort`), + KEY `idx_titems_customer` (`customer_id`), + KEY `idx_titems_ref` (`ref_type`,`ref_id`), + CONSTRAINT `fk_titems_template` FOREIGN KEY (`template_id`) REFERENCES `emailtemplate_templates` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; --- FK-Prüfung (falls temporär deaktiviert) wieder aktivieren SET FOREIGN_KEY_CHECKS = 1; +-- Ende des Schema-Dumps \ No newline at end of file