71 lines
3.6 KiB
SQL
71 lines
3.6 KiB
SQL
CREATE TABLE `deletion_targets` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`operationId` text NOT NULL,
|
|
`accessId` text NOT NULL,
|
|
FOREIGN KEY (`operationId`) REFERENCES `deletion_operations`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `deletion_operations` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`guestId` text NOT NULL,
|
|
`undoUntil` integer NOT NULL,
|
|
`createdAt` integer NOT NULL,
|
|
`restoredAt` integer,
|
|
FOREIGN KEY (`guestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `files` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`requestId` text NOT NULL,
|
|
`ownerGuestId` text NOT NULL,
|
|
`position` integer NOT NULL,
|
|
`storageKey` text NOT NULL,
|
|
`name` text NOT NULL,
|
|
`type` text NOT NULL,
|
|
`size` integer NOT NULL,
|
|
`checksum` text,
|
|
`status` text NOT NULL,
|
|
`uploadId` text,
|
|
`updatedAt` integer NOT NULL,
|
|
FOREIGN KEY (`requestId`) REFERENCES `transfer_requests`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`ownerGuestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action,
|
|
CONSTRAINT "file_nonnegative_size" CHECK("files"."size" >= 0)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `files_storageKey_unique` ON `files` (`storageKey`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `request_file_position` ON `files` (`requestId`,`position`);--> statement-breakpoint
|
|
CREATE INDEX `files_owner_state` ON `files` (`ownerGuestId`,`status`);--> statement-breakpoint
|
|
CREATE TABLE `quota_reservations` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`fileId` text NOT NULL,
|
|
`guestId` text NOT NULL,
|
|
`bytes` integer NOT NULL,
|
|
`expiresAt` integer NOT NULL,
|
|
FOREIGN KEY (`fileId`) REFERENCES `files`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`guestId`) REFERENCES `guest_sessions`(`id`) ON UPDATE no action ON DELETE no action,
|
|
CONSTRAINT "reservation_nonnegative" CHECK("quota_reservations"."bytes" >= 0)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `quota_reservations_fileId_unique` ON `quota_reservations` (`fileId`);--> statement-breakpoint
|
|
CREATE INDEX `quota_guest_expiry` ON `quota_reservations` (`guestId`,`expiresAt`);--> statement-breakpoint
|
|
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
CREATE TABLE `__new_items` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`batchId` text NOT NULL,
|
|
`kind` text NOT NULL,
|
|
`text` text,
|
|
`url` text,
|
|
`fileId` text,
|
|
`createdAt` integer NOT NULL,
|
|
`expiresAt` integer NOT NULL,
|
|
FOREIGN KEY (`batchId`) REFERENCES `transfer_batches`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`fileId`) REFERENCES `files`(`id`) ON UPDATE no action ON DELETE no action,
|
|
CONSTRAINT "item_payload" CHECK(("__new_items"."kind" = 'text' AND "__new_items"."text" IS NOT NULL AND "__new_items"."url" IS NULL AND "__new_items"."fileId" IS NULL) OR ("__new_items"."kind" = 'url' AND "__new_items"."url" IS NOT NULL AND "__new_items"."text" IS NULL AND "__new_items"."fileId" IS NULL) OR ("__new_items"."kind" = 'file' AND "__new_items"."fileId" IS NOT NULL AND "__new_items"."text" IS NULL AND "__new_items"."url" IS NULL))
|
|
);
|
|
--> statement-breakpoint
|
|
INSERT INTO `__new_items`("id", "batchId", "kind", "text", "url", "fileId", "createdAt", "expiresAt") SELECT "id", "batchId", "kind", "text", "url", NULL, "createdAt", "expiresAt" FROM `items`;--> statement-breakpoint
|
|
DROP TABLE `items`;--> statement-breakpoint
|
|
ALTER TABLE `__new_items` RENAME TO `items`;--> statement-breakpoint
|
|
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
|
CREATE INDEX `items_expiry` ON `items` (`expiresAt`);--> statement-breakpoint
|
|
ALTER TABLE `transfer_requests` ADD `manifest` text; |