Files

64 lines
2.4 KiB
SQL
Raw Permalink Normal View History

CREATE TABLE `devices` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`display_name` text,
`ble_name` text NOT NULL,
`device_class` text,
`capabilities` text,
`created_at` integer NOT NULL,
`last_connected_at` integer
);
--> statement-breakpoint
CREATE TABLE `play_sessions` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`name` text,
`kind` text NOT NULL,
`replayed_recording_id` integer,
`status` text DEFAULT 'active' NOT NULL,
`started_at` integer NOT NULL,
`ended_at` integer,
`duration_ms` integer,
`notes` text,
FOREIGN KEY (`replayed_recording_id`) REFERENCES `recordings`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE TABLE `recordings` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`source_play_session_id` integer NOT NULL,
`name` text NOT NULL,
`description` text,
`created_at` integer NOT NULL,
`duration_ms` integer NOT NULL,
`device_slots` text NOT NULL,
`play_count` integer DEFAULT 0 NOT NULL,
`last_played_at` integer,
FOREIGN KEY (`source_play_session_id`) REFERENCES `play_sessions`(`id`) ON UPDATE no action ON DELETE restrict
);
--> statement-breakpoint
CREATE TABLE `session_devices` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`play_session_id` integer NOT NULL,
`device_id` integer NOT NULL,
`slot_label` text NOT NULL,
`connected_at` integer NOT NULL,
`disconnected_at` integer,
FOREIGN KEY (`play_session_id`) REFERENCES `play_sessions`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`device_id`) REFERENCES `devices`(`id`) ON UPDATE no action ON DELETE restrict
);
--> statement-breakpoint
CREATE INDEX `session_devices_play_session_id_idx` ON `session_devices` (`play_session_id`);--> statement-breakpoint
CREATE TABLE `session_events` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`play_session_id` integer NOT NULL,
`session_device_id` integer NOT NULL,
`ts_ms` integer NOT NULL,
`command_type` text NOT NULL,
`feature_index` integer NOT NULL,
`value` real NOT NULL,
`duration_ms` integer,
`raw_payload` text,
FOREIGN KEY (`play_session_id`) REFERENCES `play_sessions`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`session_device_id`) REFERENCES `session_devices`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `session_events_session_ts_idx` ON `session_events` (`play_session_id`,`ts_ms`);--> statement-breakpoint
CREATE INDEX `session_events_session_device_idx` ON `session_events` (`session_device_id`);