CREATE TABLE `ha_entities` ( `integration_id` integer NOT NULL, `entity_id` text NOT NULL, `friendly_name` text, `state` text NOT NULL, `value` real, `unit` text, `device_class` text, `last_changed` text, `unavailable_since` text, `updated_at` text NOT NULL, PRIMARY KEY(`integration_id`, `entity_id`), FOREIGN KEY (`integration_id`) REFERENCES `integrations`(`id`) ON UPDATE no action ON DELETE cascade ); --> statement-breakpoint CREATE TABLE `ha_readings` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `integration_id` integer NOT NULL, `entity_id` text NOT NULL, `at` text NOT NULL, `value` real NOT NULL, FOREIGN KEY (`integration_id`) REFERENCES `integrations`(`id`) ON UPDATE no action ON DELETE cascade ); --> statement-breakpoint CREATE INDEX `ha_readings_lookup_idx` ON `ha_readings` (`integration_id`,`entity_id`,`at`);--> statement-breakpoint CREATE TABLE `ha_watched` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `integration_id` integer NOT NULL, `entity_id` text NOT NULL, `name` text, `above` real, `below` real, `created_at` text NOT NULL, FOREIGN KEY (`integration_id`) REFERENCES `integrations`(`id`) ON UPDATE no action ON DELETE cascade ); --> statement-breakpoint CREATE UNIQUE INDEX `ha_watched_unique` ON `ha_watched` (`integration_id`,`entity_id`);