
DROP TABLE IF EXISTS `geo_waypoint_facts`;
CREATE TABLE `geo_waypoint_facts` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `wp_key` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `kind` enum('geo','kids') COLLATE utf8mb4_unicode_ci NOT NULL,
  `text_de` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL,
  `audio_file` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `display_order` tinyint(4) DEFAULT 1,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_wp_kind` (`wp_key`,`kind`)
) ENGINE=InnoDB AUTO_INCREMENT=79 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `glossar`;
CREATE TABLE `glossar` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `key_slug` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `title` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `short` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `text` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `unit` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `image_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `animation_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `diagram_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `video_url` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort_order` int(11) DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `short_easy` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `text_easy` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `key_slug` (`key_slug`),
  KEY `category` (`category`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `glossar_examples`;
CREATE TABLE `glossar_examples` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `glossar_id` int(10) unsigned NOT NULL,
  `text` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `source_ref` tinyint(3) unsigned DEFAULT NULL,
  `sort_order` int(11) DEFAULT 0,
  `text_easy` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `glossar_id` (`glossar_id`),
  CONSTRAINT `glossar_examples_ibfk_1` FOREIGN KEY (`glossar_id`) REFERENCES `glossar` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=236 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `glossar_links`;
CREATE TABLE `glossar_links` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `glossar_id` int(10) unsigned NOT NULL,
  `label` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `url` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL,
  `sort_order` int(11) DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `glossar_id` (`glossar_id`),
  CONSTRAINT `glossar_links_ibfk_1` FOREIGN KEY (`glossar_id`) REFERENCES `glossar` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=97 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `glossar_modules`;
CREATE TABLE `glossar_modules` (
  `glossar_id` int(10) unsigned NOT NULL,
  `module_id` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`glossar_id`,`module_id`),
  CONSTRAINT `glossar_modules_ibfk_1` FOREIGN KEY (`glossar_id`) REFERENCES `glossar` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `glossar_related`;
CREATE TABLE `glossar_related` (
  `glossar_id` int(10) unsigned NOT NULL,
  `related_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`glossar_id`,`related_id`),
  KEY `related_id` (`related_id`),
  CONSTRAINT `glossar_related_ibfk_1` FOREIGN KEY (`glossar_id`) REFERENCES `glossar` (`id`) ON DELETE CASCADE,
  CONSTRAINT `glossar_related_ibfk_2` FOREIGN KEY (`related_id`) REFERENCES `glossar` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `glossar_sources`;
CREATE TABLE `glossar_sources` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `glossar_id` int(10) unsigned NOT NULL,
  `ref_num` tinyint(3) unsigned NOT NULL,
  `label` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `url` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `access_date` date DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_gl_ref` (`glossar_id`,`ref_num`),
  KEY `idx_gl` (`glossar_id`),
  CONSTRAINT `glossar_sources_ibfk_1` FOREIGN KEY (`glossar_id`) REFERENCES `glossar` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=114 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `kompetenzen`;
CREATE TABLE `kompetenzen` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `key_slug` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `title` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `age_min` tinyint(3) unsigned DEFAULT NULL,
  `age_max` tinyint(3) unsigned DEFAULT NULL,
  `sort_order` int(11) DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `key_slug` (`key_slug`)
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `kompetenz_modules`;
CREATE TABLE `kompetenz_modules` (
  `kompetenz_id` int(10) unsigned NOT NULL,
  `module_id` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `level` tinyint(3) unsigned NOT NULL DEFAULT 0,
  `strength` enum('primaer','sekundaer') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'primaer',
  PRIMARY KEY (`kompetenz_id`,`module_id`,`level`),
  KEY `module_id` (`module_id`),
  CONSTRAINT `fk_km_kompetenz` FOREIGN KEY (`kompetenz_id`) REFERENCES `kompetenzen` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `lehrplan_anchors`;
CREATE TABLE `lehrplan_anchors` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `kompetenz_id` int(10) unsigned NOT NULL,
  `country` char(2) COLLATE utf8mb4_unicode_ci NOT NULL,
  `anchor_type` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fach',
  `region` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `school_type` varchar(48) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `grade` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `subject` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `reference` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reference_url` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `quote` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort_order` int(11) DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `kompetenz_id` (`kompetenz_id`),
  KEY `country` (`country`,`school_type`),
  KEY `idx_anchor_type` (`anchor_type`),
  CONSTRAINT `fk_la_kompetenz` FOREIGN KEY (`kompetenz_id`) REFERENCES `kompetenzen` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=309 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


