schema
This commit is contained in:
374
schema.sql
374
schema.sql
@@ -1,189 +1,231 @@
|
|||||||
/* =======================================================================
|
-- Schema-Dump für `d044ae9e` (erstellt am 2025-12-07 02:21:49 UTC)
|
||||||
Email Template System — Schema passend zur api.php (2025-09-06)
|
-- Hinweis: Es werden nur CREATE-Anweisungen ausgegeben, bestehende Tabellen bleiben unangetastet.
|
||||||
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).
|
|
||||||
======================================================================= */
|
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
-- Tabelle: customers
|
||||||
SET FOREIGN_KEY_CHECKS = 0;
|
CREATE TABLE IF NOT EXISTS `customers` (
|
||||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
/* Drop-Reihenfolge: erst Items, dann Master-Tabellen */
|
`name` varchar(150) NOT NULL,
|
||||||
DROP TABLE IF EXISTS `emailtemplate_section_items`;
|
`slug` varchar(150) NOT NULL,
|
||||||
DROP TABLE IF EXISTS `emailtemplate_template_items`;
|
`plan` varchar(50) NOT NULL DEFAULT 'free',
|
||||||
DROP TABLE IF EXISTS `emailtemplate_assets`;
|
`status` varchar(20) NOT NULL DEFAULT 'active',
|
||||||
DROP TABLE IF EXISTS `emailtemplate_snippets`;
|
`logo_url` varchar(255) DEFAULT NULL,
|
||||||
DROP TABLE IF EXISTS `emailtemplate_blocks`;
|
`theme_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`theme_json`)),
|
||||||
DROP TABLE IF EXISTS `emailtemplate_sections`;
|
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||||
DROP TABLE IF EXISTS `emailtemplate_templates`;
|
`updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||||
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,
|
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_tpl_customer` (`customer_id`),
|
UNIQUE KEY `slug` (`slug`)
|
||||||
KEY `idx_tpl_updated` (`updated_at`),
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
KEY `idx_tpl_name` (`name`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
/* 2) Sections (optional einem Template zugeordnet) */
|
-- Tabelle: customer_tokens
|
||||||
CREATE TABLE `emailtemplate_sections` (
|
CREATE TABLE IF NOT EXISTS `customer_tokens` (
|
||||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`customer_id` INT UNSIGNED NOT NULL,
|
`customer_id` int(10) unsigned NOT NULL,
|
||||||
`template_id` INT UNSIGNED NULL,
|
`label` varchar(120) NOT NULL,
|
||||||
`name` VARCHAR(255) NOT NULL,
|
`token_hash` char(64) NOT NULL,
|
||||||
`type` VARCHAR(50) NOT NULL DEFAULT 'html',
|
`scopes` varchar(255) DEFAULT NULL,
|
||||||
`json_content` MEDIUMTEXT NULL, -- NEU: Speichert GrapesJS JSON-Zustand (Komponenten + Stile)
|
`is_active` tinyint(1) NOT NULL DEFAULT 1,
|
||||||
`z_index` INT NOT NULL DEFAULT 0,
|
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||||
`html` MEDIUMTEXT NULL, -- BLEIBT: Speichert finalen, exportierten HTML-Code
|
`last_used_at` timestamp NULL 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`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_sec_customer` (`customer_id`),
|
UNIQUE KEY `uq_token_hash` (`token_hash`),
|
||||||
KEY `idx_sec_template` (`template_id`),
|
KEY `customer_id` (`customer_id`)
|
||||||
KEY `idx_sec_sort` (`template_id`,`z_index`,`id`),
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
CONSTRAINT `fk_sections_template`
|
|
||||||
FOREIGN KEY (`template_id`) REFERENCES `emailtemplate_templates` (`id`)
|
|
||||||
ON UPDATE CASCADE ON DELETE SET NULL
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
/* 3) Blocks (optional einer Section zugeordnet) */
|
-- Tabelle: customer_users
|
||||||
CREATE TABLE `emailtemplate_blocks` (
|
CREATE TABLE IF NOT EXISTS `customer_users` (
|
||||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`customer_id` INT UNSIGNED NOT NULL,
|
`customer_id` int(10) unsigned NOT NULL,
|
||||||
`section_id` INT UNSIGNED NULL,
|
`email` varchar(190) NOT NULL,
|
||||||
`name` VARCHAR(255) NOT NULL,
|
`password_hash` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||||
`category` VARCHAR(100) NOT NULL DEFAULT 'Default',
|
`role` varchar(30) NOT NULL DEFAULT 'editor',
|
||||||
`json_content` MEDIUMTEXT NULL, -- NEU: Speichert GrapesJS JSON-Zustand (Komponenten + Stile)
|
`is_active` tinyint(1) NOT NULL DEFAULT 1,
|
||||||
`html` MEDIUMTEXT NULL, -- BLEIBT: Speichert finalen, exportierten HTML-Code
|
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||||
`updated_at` TIMESTAMP NOT 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`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_blk_customer` (`customer_id`),
|
KEY `idx_blk_customer` (`customer_id`),
|
||||||
KEY `idx_blk_section` (`section_id`),
|
KEY `idx_blk_section` (`section_id`),
|
||||||
KEY `idx_blk_name` (`name`),
|
KEY `idx_blk_name` (`name`),
|
||||||
CONSTRAINT `fk_blocks_section`
|
CONSTRAINT `fk_blocks_section` FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`)
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
ON UPDATE CASCADE ON DELETE SET NULL
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
/* 4) Snippets (kleine Bausteine; BY VALUE) */
|
-- Tabelle: emailtemplate_customers
|
||||||
CREATE TABLE `emailtemplate_snippets` (
|
CREATE TABLE IF NOT EXISTS `emailtemplate_customers` (
|
||||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`customer_id` INT UNSIGNED NOT NULL,
|
`name` varchar(150) NOT NULL,
|
||||||
`name` VARCHAR(255) NOT NULL,
|
`slug` varchar(150) NOT NULL,
|
||||||
`category` VARCHAR(100) NOT NULL DEFAULT '',
|
`plan` varchar(50) NOT NULL DEFAULT 'free',
|
||||||
`json_content` MEDIUMTEXT NULL, -- NEU: Speichert GrapesJS JSON-Zustand
|
`status` varchar(20) NOT NULL DEFAULT 'active',
|
||||||
`content` MEDIUMTEXT NULL, -- BLEIBT: Speichert finalen, exportierten HTML-Code
|
`logo_url` varchar(255) DEFAULT NULL,
|
||||||
`block_id` INT UNSIGNED NULL,
|
`theme_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`theme_json`)),
|
||||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||||
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_snp_customer` (`customer_id`),
|
UNIQUE KEY `slug` (`slug`)
|
||||||
KEY `idx_snp_name` (`name`),
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
KEY `idx_snp_block` (`block_id`),
|
|
||||||
CONSTRAINT `fk_snippets_block`
|
-- Tabelle: emailtemplate_customer_settings
|
||||||
FOREIGN KEY (`block_id`) REFERENCES `emailtemplate_blocks` (`id`)
|
CREATE TABLE IF NOT EXISTS `emailtemplate_customer_settings` (
|
||||||
ON UPDATE CASCADE ON DELETE SET NULL
|
`customer_id` int(10) unsigned NOT NULL,
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
`bridge_url` varchar(500) DEFAULT NULL,
|
||||||
/* 5) Assets (READ-only in api.php) */
|
`bridge_token` varchar(255) DEFAULT NULL,
|
||||||
CREATE TABLE `emailtemplate_assets` (
|
`sender_token` varchar(255) DEFAULT NULL,
|
||||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
`external_api_token` varchar(255) DEFAULT NULL,
|
||||||
`customer_id` INT UNSIGNED NOT NULL,
|
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
`name` VARCHAR(255) NOT NULL,
|
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||||
`type` VARCHAR(50) NOT NULL,
|
PRIMARY KEY (`customer_id`)
|
||||||
`mime_type` VARCHAR(100) NOT NULL,
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
`size_bytes` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
||||||
`public_url` VARCHAR(1000) NULL,
|
-- Tabelle: emailtemplate_customer_tokens
|
||||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CREATE TABLE IF NOT EXISTS `emailtemplate_customer_tokens` (
|
||||||
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`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`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_ast_customer` (`customer_id`),
|
UNIQUE KEY `uq_token_hash` (`token_hash`),
|
||||||
KEY `idx_ast_updated` (`updated_at`)
|
KEY `customer_id` (`customer_id`),
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
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
|
||||||
Referenz-Item-Tabellen
|
CREATE TABLE IF NOT EXISTS `emailtemplate_customer_users` (
|
||||||
========================= */
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`customer_id` int(10) unsigned NOT NULL,
|
||||||
/* 6) Items im Template (Sections ODER Blocks als Referenz) */
|
`email` varchar(190) NOT NULL,
|
||||||
CREATE TABLE `emailtemplate_template_items` (
|
`password_hash` varchar(255) NOT NULL,
|
||||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
`role` varchar(30) NOT NULL DEFAULT 'editor',
|
||||||
`customer_id` INT UNSIGNED NOT NULL,
|
`is_active` tinyint(1) NOT NULL DEFAULT 1,
|
||||||
`template_id` INT UNSIGNED NOT NULL,
|
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||||
`sort` INT NOT NULL DEFAULT 0,
|
`updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||||
`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`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_titems_template_sort` (`template_id`,`sort`),
|
UNIQUE KEY `uq_customer_email` (`customer_id`,`email`),
|
||||||
KEY `idx_titems_customer` (`customer_id`),
|
CONSTRAINT `fk_customer_users_customer` FOREIGN KEY (`customer_id`) REFERENCES `emailtemplate_customers` (`id`) ON DELETE CASCADE
|
||||||
KEY `idx_titems_ref` (`ref_type`,`ref_id`),
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
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) */
|
-- Tabelle: emailtemplate_sections
|
||||||
CREATE TABLE `emailtemplate_section_items` (
|
CREATE TABLE IF NOT EXISTS `emailtemplate_sections` (
|
||||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`customer_id` INT UNSIGNED NOT NULL,
|
`customer_id` int(10) unsigned NOT NULL,
|
||||||
`section_id` INT UNSIGNED NOT NULL,
|
`template_id` int(10) unsigned DEFAULT NULL,
|
||||||
`sort` INT NOT NULL DEFAULT 0,
|
`name` varchar(255) NOT NULL,
|
||||||
`ref_type` ENUM('block') NOT NULL,
|
`json_content` mediumtext DEFAULT NULL,
|
||||||
`ref_id` INT UNSIGNED NOT NULL,
|
`type` varchar(50) NOT NULL DEFAULT 'html',
|
||||||
`overrides_json` JSON NULL,
|
`z_index` int(11) NOT NULL DEFAULT 0,
|
||||||
`lock_to_version` INT NULL,
|
`html` mediumtext DEFAULT NULL,
|
||||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 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 DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
-- 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`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_sitems_section_sort` (`section_id`,`sort`),
|
KEY `idx_sitems_section_sort` (`section_id`,`sort`),
|
||||||
KEY `idx_sitems_customer` (`customer_id`),
|
KEY `idx_sitems_customer` (`customer_id`),
|
||||||
KEY `idx_sitems_ref` (`ref_type`,`ref_id`),
|
KEY `idx_sitems_ref` (`ref_type`,`ref_id`),
|
||||||
CONSTRAINT `fk_sitems_section`
|
CONSTRAINT `fk_sitems_section` FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
FOREIGN KEY (`section_id`) REFERENCES `emailtemplate_sections` (`id`)
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
ON UPDATE CASCADE ON DELETE CASCADE
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
/* 8) Kundenbezogene Einstellungen (Bridge/Sender/API Tokens) */
|
-- Tabelle: emailtemplate_snippets
|
||||||
CREATE TABLE `emailtemplate_customer_settings` (
|
CREATE TABLE IF NOT EXISTS `emailtemplate_snippets` (
|
||||||
`customer_id` INT UNSIGNED NOT NULL,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`bridge_url` VARCHAR(500) DEFAULT NULL,
|
`customer_id` int(10) unsigned NOT NULL,
|
||||||
`bridge_token` VARCHAR(255) DEFAULT NULL,
|
`name` varchar(255) NOT NULL,
|
||||||
`sender_token` VARCHAR(255) DEFAULT NULL,
|
`category` varchar(100) NOT NULL DEFAULT '',
|
||||||
`external_api_token` VARCHAR(255) DEFAULT NULL,
|
`json_content` mediumtext DEFAULT NULL,
|
||||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`content` mediumtext DEFAULT NULL,
|
||||||
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`block_id` int(10) unsigned DEFAULT NULL,
|
||||||
PRIMARY KEY (`customer_id`)
|
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
`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;
|
||||||
|
|
||||||
/* =========================
|
-- Tabelle: emailtemplate_templates
|
||||||
Optionale Seed-Daten
|
CREATE TABLE IF NOT EXISTS `emailtemplate_templates` (
|
||||||
========================= */
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
-- INSERT INTO `emailtemplate_templates` (`customer_id`,`name`,`html`) VALUES (1,'Newsletter-Template','');
|
`customer_id` int(10) unsigned NOT NULL,
|
||||||
-- INSERT INTO `emailtemplate_sections` (`customer_id`,`name`,`type`,`z_index`,`html`,`template_id`) VALUES (1,'Hero','html',10,'<table role="presentation" width="100%"><tr><td>{{children}}</td></tr></table>', NULL);
|
`name` varchar(255) NOT NULL,
|
||||||
-- INSERT INTO `emailtemplate_blocks` (`customer_id`,`name`,`category`,`html`,`section_id`) VALUES (1,'CTA-Block','CTA','<table role="presentation"><tr><td>...</td></tr></table>', NULL);
|
`json_content` mediumtext DEFAULT NULL,
|
||||||
-- INSERT INTO `emailtemplate_snippets` (`customer_id`,`name`,`category`,`content`) VALUES (1,'Textabsatz','Text','<p style="margin:0 0 12px 0;">Lorem ipsum…</p>');
|
`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;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
-- Ende des Schema-Dumps
|
||||||
Reference in New Issue
Block a user