Advertisement
dykandDK

HA - SQL - Events and States table create export

Oct 7th, 2022
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.97 KB | None | 0 0
  1.  
  2. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  3. START TRANSACTION;
  4. SET time_zone = "+00:00";
  5.  
  6. --
  7. -- Database: `homeassistant`
  8. --
  9.  
  10. -- --------------------------------------------------------
  11.  
  12. --
  13. -- Struktur-dump for tabellen `events`
  14. --
  15.  
  16. -- --------------------------------------------------------
  17.  
  18.  
  19. CREATE TABLE `events` (
  20.   `event_id` int(11) NOT NULL,
  21.   `event_type` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  22.   `event_data` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  23.   `origin` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  24.   `origin_idx` smallint(6) DEFAULT NULL,
  25.   `time_fired` datetime(6) DEFAULT NULL,
  26.   `context_id` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  27.   `context_user_id` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  28.   `context_parent_id` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  29.   `data_id` int(11) DEFAULT NULL
  30. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  31.  
  32. --
  33. -- Begrænsninger for dumpede tabeller
  34. --
  35.  
  36. --
  37. -- Indeks for tabel `events`
  38. --
  39. ALTER TABLE `events`
  40.   ADD PRIMARY KEY (`event_id`),
  41.   ADD KEY `ix_events_time_fired` (`time_fired`),
  42.   ADD KEY `ix_events_data_id` (`data_id`),
  43.   ADD KEY `ix_events_event_type_time_fired` (`event_type`,`time_fired`),
  44.   ADD KEY `ix_events_context_id` (`context_id`);
  45.  
  46. --
  47. -- Brug ikke AUTO_INCREMENT for slettede tabeller
  48. --
  49.  
  50. --
  51. -- Tilføj AUTO_INCREMENT i tabel `events`
  52. --
  53. ALTER TABLE `events`
  54.   MODIFY `event_id` int(11) NOT NULL AUTO_INCREMENT;
  55.  
  56. --
  57. -- Begrænsninger for dumpede tabeller
  58. --
  59.  
  60. --
  61. -- Begrænsninger for tabel `events`
  62. --
  63. ALTER TABLE `events`
  64.   ADD CONSTRAINT `events_ibfk_1` FOREIGN KEY (`data_id`) REFERENCES `event_data` (`data_id`);
  65. COMMIT;
  66.  
  67.  
  68. -- phpMyAdmin SQL Dump
  69. -- version 5.2.0
  70. -- https://www.phpmyadmin.net/
  71. --
  72. -- Vært: core-mariadb:3306
  73. -- Genereringstid: 07. 10 2022 kl. 12:24:56
  74. -- Serverversion: 10.6.8-MariaDB
  75. -- PHP-version: 8.0.21
  76.  
  77.  
  78. -- --------------------------------------------------------
  79.  
  80. --
  81. -- Struktur-dump for tabellen `states`
  82. --
  83.  
  84. -- --------------------------------------------------------
  85.  
  86.  
  87.  
  88. CREATE TABLE `states` (
  89.   `state_id` int(11) NOT NULL,
  90.   `entity_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  91.   `state` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  92.   `attributes` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  93.   `event_id` int(11) DEFAULT NULL,
  94.   `last_changed` datetime(6) DEFAULT NULL,
  95.   `last_updated` datetime(6) DEFAULT NULL,
  96.   `old_state_id` int(11) DEFAULT NULL,
  97.   `attributes_id` int(11) DEFAULT NULL,
  98.   `context_id` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  99.   `context_user_id` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  100.   `context_parent_id` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  101.   `origin_idx` smallint(6) DEFAULT NULL
  102. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  103.  
  104. --
  105. -- Begrænsninger for dumpede tabeller
  106. --
  107.  
  108. --
  109. -- Indeks for tabel `states`
  110. --
  111. ALTER TABLE `states`
  112.   ADD PRIMARY KEY (`state_id`),
  113.   ADD KEY `ix_states_entity_id_last_updated` (`entity_id`,`last_updated`),
  114.   ADD KEY `ix_states_attributes_id` (`attributes_id`),
  115.   ADD KEY `ix_states_old_state_id` (`old_state_id`),
  116.   ADD KEY `ix_states_event_id` (`event_id`),
  117.   ADD KEY `ix_states_last_updated` (`last_updated`),
  118.   ADD KEY `ix_states_context_id` (`context_id`);
  119.  
  120. --
  121. -- Brug ikke AUTO_INCREMENT for slettede tabeller
  122. --
  123.  
  124. --
  125. -- Tilføj AUTO_INCREMENT i tabel `states`
  126. --
  127. ALTER TABLE `states`
  128.   MODIFY `state_id` int(11) NOT NULL AUTO_INCREMENT;
  129.  
  130. --
  131. -- Begrænsninger for dumpede tabeller
  132. --
  133.  
  134. --
  135. -- Begrænsninger for tabel `states`
  136. --
  137. ALTER TABLE `states`
  138.   ADD CONSTRAINT `states_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `events` (`event_id`) ON DELETE CASCADE,
  139.   ADD CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`),
  140.   ADD CONSTRAINT `states_ibfk_3` FOREIGN KEY (`attributes_id`) REFERENCES `state_attributes` (`attributes_id`);
  141. COMMIT;
  142.  
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement