CREATE TABLE `item_access` ( `id` text PRIMARY KEY NOT NULL, `itemId` text NOT NULL, `guestId` text NOT NULL, `role` text NOT NULL, `read` integer DEFAULT false NOT NULL, `deletedAt` integer, FOREIGN KEY (`itemId`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE no action, FOREIGN KEY (`guestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint CREATE UNIQUE INDEX `access_subject_role` ON `item_access` (`itemId`,`guestId`,`role`);--> statement-breakpoint CREATE INDEX `access_guest` ON `item_access` (`guestId`,`deletedAt`);--> statement-breakpoint CREATE TABLE `transfer_batches` ( `id` text PRIMARY KEY NOT NULL, `requestId` text NOT NULL, `status` text NOT NULL, `storedAt` integer, FOREIGN KEY (`requestId`) REFERENCES `transfer_requests`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint CREATE UNIQUE INDEX `transfer_batches_requestId_unique` ON `transfer_batches` (`requestId`);--> statement-breakpoint CREATE TABLE `guest_blocks` ( `id` text PRIMARY KEY NOT NULL, `guestId` text NOT NULL, `targetGuestId` text NOT NULL, FOREIGN KEY (`guestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action, FOREIGN KEY (`targetGuestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint CREATE UNIQUE INDEX `guest_block_pair` ON `guest_blocks` (`guestId`,`targetGuestId`);--> statement-breakpoint CREATE TABLE `browser_devices` ( `id` text PRIMARY KEY NOT NULL, `guestId` text NOT NULL, `name` text NOT NULL, `code` text NOT NULL, `discoverable` integer DEFAULT true NOT NULL, `lastSeen` integer NOT NULL, FOREIGN KEY (`guestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action, CONSTRAINT "device_name_length" CHECK(length("browser_devices"."name") between 1 and 40) ); --> statement-breakpoint CREATE UNIQUE INDEX `browser_devices_guestId_unique` ON `browser_devices` (`guestId`);--> statement-breakpoint CREATE UNIQUE INDEX `browser_devices_code_unique` ON `browser_devices` (`code`);--> statement-breakpoint CREATE TABLE `guest_sessions` ( `id` text PRIMARY KEY NOT NULL, `tokenHash` text NOT NULL, `expiresAt` integer NOT NULL, `revokedAt` integer, `createdAt` integer NOT NULL ); --> statement-breakpoint CREATE UNIQUE INDEX `guest_sessions_tokenHash_unique` ON `guest_sessions` (`tokenHash`);--> statement-breakpoint CREATE INDEX `guest_expiry` ON `guest_sessions` (`expiresAt`);--> statement-breakpoint CREATE TABLE `idempotency_records` ( `id` text PRIMARY KEY NOT NULL, `guestId` text NOT NULL, `operation` text NOT NULL, `key` text NOT NULL, `payloadHash` text NOT NULL, `response` text NOT NULL, `createdAt` integer NOT NULL, FOREIGN KEY (`guestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint CREATE UNIQUE INDEX `idempotency_scope` ON `idempotency_records` (`guestId`,`operation`,`key`);--> statement-breakpoint CREATE TABLE `items` ( `id` text PRIMARY KEY NOT NULL, `batchId` text NOT NULL, `kind` text NOT NULL, `text` text, `url` text, `createdAt` integer NOT NULL, `expiresAt` integer NOT NULL, FOREIGN KEY (`batchId`) REFERENCES `transfer_batches`(`id`) ON UPDATE no action ON DELETE no action, CONSTRAINT "item_payload" CHECK(("items"."kind" = 'text' AND "items"."text" IS NOT NULL AND "items"."url" IS NULL) OR ("items"."kind" = 'url' AND "items"."url" IS NOT NULL AND "items"."text" IS NULL)) ); --> statement-breakpoint CREATE INDEX `items_expiry` ON `items` (`expiresAt`);--> statement-breakpoint CREATE TABLE `space_members` ( `id` text PRIMARY KEY NOT NULL, `spaceId` text NOT NULL, `deviceId` text NOT NULL, `status` text NOT NULL, `joinedAt` integer NOT NULL, FOREIGN KEY (`spaceId`) REFERENCES `connection_spaces`(`id`) ON UPDATE no action ON DELETE no action, FOREIGN KEY (`deviceId`) REFERENCES `browser_devices`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint CREATE UNIQUE INDEX `space_device` ON `space_members` (`spaceId`,`deviceId`);--> statement-breakpoint CREATE TABLE `transfer_requests` ( `id` text PRIMARY KEY NOT NULL, `mode` text DEFAULT 'local' NOT NULL, `senderGuestId` text NOT NULL, `recipientGuestId` text NOT NULL, `kind` text NOT NULL, `byteSize` integer NOT NULL, `count` integer NOT NULL, `status` text NOT NULL, `createdAt` integer NOT NULL, `expiresAt` integer NOT NULL, `acceptedAt` integer, `startBy` integer, FOREIGN KEY (`senderGuestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action, FOREIGN KEY (`recipientGuestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action, CONSTRAINT "request_different_guests" CHECK("transfer_requests"."senderGuestId" <> "transfer_requests"."recipientGuestId") ); --> statement-breakpoint CREATE INDEX `requests_sender_time` ON `transfer_requests` (`senderGuestId`,`createdAt`);--> statement-breakpoint CREATE INDEX `requests_recipient_time` ON `transfer_requests` (`recipientGuestId`,`createdAt`);--> statement-breakpoint CREATE INDEX `requests_expiry` ON `transfer_requests` (`status`,`expiresAt`);--> statement-breakpoint CREATE TABLE `connection_spaces` ( `id` text PRIMARY KEY NOT NULL, `creatorGuestId` text NOT NULL, `tokenHash` text NOT NULL, `codeHash` text NOT NULL, `approvalRequired` integer NOT NULL, `expiresAt` integer NOT NULL, `closedAt` integer, `createdAt` integer NOT NULL, FOREIGN KEY (`creatorGuestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint CREATE UNIQUE INDEX `connection_spaces_tokenHash_unique` ON `connection_spaces` (`tokenHash`);--> statement-breakpoint CREATE UNIQUE INDEX `connection_spaces_codeHash_unique` ON `connection_spaces` (`codeHash`);--> statement-breakpoint CREATE INDEX `space_expiry` ON `connection_spaces` (`expiresAt`);