CREATE TABLE `endpoint_daily` ( `check_id` integer NOT NULL, `day` text NOT NULL, `total` integer DEFAULT 0 NOT NULL, `ok` integer DEFAULT 0 NOT NULL, `ms_sum` integer DEFAULT 0 NOT NULL, `ms_count` integer DEFAULT 0 NOT NULL, PRIMARY KEY(`check_id`, `day`), FOREIGN KEY (`check_id`) REFERENCES `endpoint_checks`(`id`) ON UPDATE no action ON DELETE cascade ); --> statement-breakpoint CREATE TABLE `patch_plan_runs` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `plan_id` integer NOT NULL, `plan_name` text NOT NULL, `trigger` text NOT NULL, `started_by` text, `status` text NOT NULL, `message` text, `items` text DEFAULT '[]' NOT NULL, `started_at` text NOT NULL, `finished_at` text, FOREIGN KEY (`plan_id`) REFERENCES `patch_plans`(`id`) ON UPDATE no action ON DELETE cascade ); --> statement-breakpoint CREATE INDEX `patch_plan_runs_plan_idx` ON `patch_plan_runs` (`plan_id`,`started_at`);--> statement-breakpoint CREATE INDEX `patch_plan_runs_status_idx` ON `patch_plan_runs` (`status`);--> statement-breakpoint CREATE TABLE `patch_plans` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `name` text NOT NULL, `enabled` integer DEFAULT true NOT NULL, `days` text NOT NULL, `start_time` text NOT NULL, `timezone` text NOT NULL, `tags` text DEFAULT '[]' NOT NULL, `server_ids` text DEFAULT '[]' NOT NULL, `integration_id` integer NOT NULL, `project_id` integer NOT NULL, `template_id` integer NOT NULL, `template_name` text NOT NULL, `limit_from` text DEFAULT 'name' NOT NULL, `stop_on_failure` integer DEFAULT true NOT NULL, `only_with_updates` integer DEFAULT true NOT NULL, `silence_dependents` integer DEFAULT true NOT NULL, `window_minutes` integer DEFAULT 90 NOT NULL, `last_run_date` text, `created_by` text, `created_at` text DEFAULT (current_timestamp) NOT NULL ); --> statement-breakpoint CREATE TABLE `renewals` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `kind` text NOT NULL, `subject` text NOT NULL, `at` text NOT NULL, `from_date` text NOT NULL, `to_date` text NOT NULL ); --> statement-breakpoint CREATE INDEX `renewals_at_idx` ON `renewals` (`at`);--> statement-breakpoint ALTER TABLE `servers` ADD `port_baseline` text; --> statement-breakpoint -- The daily rollup starts with what the endpoint results already hold (they are kept two weeks), so the first report is not blank. INSERT INTO `endpoint_daily` (`check_id`, `day`, `total`, `ok`, `ms_sum`, `ms_count`) SELECT `check_id`, substr(`at`, 1, 10), count(*), sum(`ok`), sum(CASE WHEN `ok` = 1 AND `ms` IS NOT NULL THEN `ms` ELSE 0 END), sum(CASE WHEN `ok` = 1 AND `ms` IS NOT NULL THEN 1 ELSE 0 END) FROM `endpoint_results` GROUP BY `check_id`, substr(`at`, 1, 10);