CREATE TABLE `executions` (
	`id` text PRIMARY KEY NOT NULL,
	`machine_id` text NOT NULL,
	`action` text NOT NULL,
	`mode` text DEFAULT 'manual' NOT NULL,
	`started_at` text NOT NULL,
	`finished_at` text,
	`status` text NOT NULL,
	`result_json` text,
	`report_path` text,
	`raw_log_path` text,
	FOREIGN KEY (`machine_id`) REFERENCES `machines`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `machines` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text NOT NULL,
	`hostname` text NOT NULL,
	`port` integer DEFAULT 22 NOT NULL,
	`os_family` text DEFAULT 'unknown' NOT NULL,
	`username` text NOT NULL,
	`enc_password` text NOT NULL,
	`enc_sudo_password` text,
	`apt_proxy_mode` text DEFAULT 'direct' NOT NULL,
	`apt_proxy_url` text,
	`status` text DEFAULT 'unknown' NOT NULL,
	`last_checked_at` text,
	`created_at` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `snapshots` (
	`id` text PRIMARY KEY NOT NULL,
	`machine_id` text NOT NULL,
	`checked_at` text NOT NULL,
	`status` text NOT NULL,
	`payload_json` text NOT NULL,
	FOREIGN KEY (`machine_id`) REFERENCES `machines`(`id`) ON UPDATE no action ON DELETE cascade
);
