File
Blob: drizzle/file-dav-do/0001_panoramic_lifeguard.sql
| 1 | CREATE TABLE `blobs` ( |
| 2 | `blob_id` text PRIMARY KEY NOT NULL, |
| 3 | `blob_key` text NOT NULL, |
| 4 | `size` integer NOT NULL, |
| 5 | `r2_etag` text, |
| 6 | `sha256` text, |
| 7 | `refcount` integer DEFAULT 0 NOT NULL, |
| 8 | `created_at_ms` integer NOT NULL |
| 9 | ); |
| 10 | --> statement-breakpoint |
| 11 | CREATE UNIQUE INDEX `blobs_key_unique` ON `blobs` (`blob_key`);--> statement-breakpoint |
| 12 | CREATE INDEX `blobs_refcount_idx` ON `blobs` (`refcount`);--> statement-breakpoint |
| 13 | CREATE INDEX `blobs_created_idx` ON `blobs` (`created_at_ms`);--> statement-breakpoint |
| 14 | CREATE TABLE `changes` ( |
| 15 | `seq` integer PRIMARY KEY AUTOINCREMENT NOT NULL, |
| 16 | `node_id` text, |
| 17 | `href` text NOT NULL, |
| 18 | `change_type` text NOT NULL, |
| 19 | `changed_at_ms` integer NOT NULL, |
| 20 | FOREIGN KEY (`node_id`) REFERENCES `nodes`(`id`) ON UPDATE no action ON DELETE set null, |
| 21 | CONSTRAINT "changes_type_check" CHECK("changes"."change_type" in ('created', 'updated', 'deleted', 'moved')) |
| 22 | ); |
| 23 | --> statement-breakpoint |
| 24 | CREATE INDEX `changes_href_idx` ON `changes` (`href`);--> statement-breakpoint |
| 25 | CREATE INDEX `changes_changed_idx` ON `changes` (`changed_at_ms`);--> statement-breakpoint |
| 26 | CREATE TABLE `dead_props` ( |
| 27 | `node_id` text NOT NULL, |
| 28 | `ns_uri` text NOT NULL, |
| 29 | `local_name` text NOT NULL, |
| 30 | `xml_value` text NOT NULL, |
| 31 | PRIMARY KEY(`node_id`, `ns_uri`, `local_name`), |
| 32 | FOREIGN KEY (`node_id`) REFERENCES `nodes`(`id`) ON UPDATE no action ON DELETE cascade |
| 33 | ); |
| 34 | --> statement-breakpoint |
| 35 | CREATE TABLE `locks` ( |
| 36 | `token` text PRIMARY KEY NOT NULL, |
| 37 | `root_node_id` text, |
| 38 | `root_path` text NOT NULL, |
| 39 | `owner_xml` text NOT NULL, |
| 40 | `principal_subject_id` text NOT NULL, |
| 41 | `scope` text NOT NULL, |
| 42 | `depth` text NOT NULL, |
| 43 | `created_at_ms` integer NOT NULL, |
| 44 | `expires_at_ms` integer NOT NULL, |
| 45 | FOREIGN KEY (`root_node_id`) REFERENCES `nodes`(`id`) ON UPDATE no action ON DELETE cascade, |
| 46 | CONSTRAINT "locks_scope_check" CHECK("locks"."scope" in ('exclusive', 'shared')), |
| 47 | CONSTRAINT "locks_depth_check" CHECK("locks"."depth" in ('0', 'infinity')) |
| 48 | ); |
| 49 | --> statement-breakpoint |
| 50 | CREATE INDEX `locks_root_node_idx` ON `locks` (`root_node_id`);--> statement-breakpoint |
| 51 | CREATE INDEX `locks_root_path_idx` ON `locks` (`root_path`);--> statement-breakpoint |
| 52 | CREATE INDEX `locks_expires_idx` ON `locks` (`expires_at_ms`);--> statement-breakpoint |
| 53 | CREATE INDEX `locks_principal_idx` ON `locks` (`principal_subject_id`);--> statement-breakpoint |
| 54 | CREATE TABLE `nodes` ( |
| 55 | `id` text PRIMARY KEY NOT NULL, |
| 56 | `parent_id` text, |
| 57 | `name` text NOT NULL, |
| 58 | `kind` text NOT NULL, |
| 59 | `blob_id` text, |
| 60 | `size` integer DEFAULT 0 NOT NULL, |
| 61 | `content_type` text, |
| 62 | `content_language` text, |
| 63 | `etag` text, |
| 64 | `root_marker` text, |
| 65 | `created_at_ms` integer NOT NULL, |
| 66 | `modified_at_ms` integer NOT NULL, |
| 67 | `version` integer DEFAULT 1 NOT NULL, |
| 68 | FOREIGN KEY (`parent_id`) REFERENCES `nodes`(`id`) ON UPDATE no action ON DELETE cascade, |
| 69 | FOREIGN KEY (`blob_id`) REFERENCES `blobs`(`blob_id`) ON UPDATE no action ON DELETE restrict, |
| 70 | CONSTRAINT "nodes_kind_check" CHECK("nodes"."kind" in ('collection', 'file')), |
| 71 | CONSTRAINT "nodes_root_marker_check" CHECK("nodes"."root_marker" is null or "nodes"."root_marker" = 'root'), |
| 72 | CONSTRAINT "nodes_collection_blob_check" CHECK("nodes"."kind" != 'collection' or "nodes"."blob_id" is null) |
| 73 | ); |
| 74 | --> statement-breakpoint |
| 75 | CREATE UNIQUE INDEX `nodes_parent_name_unique` ON `nodes` (`parent_id`,`name`);--> statement-breakpoint |
| 76 | CREATE UNIQUE INDEX `nodes_root_marker_unique` ON `nodes` (`root_marker`);--> statement-breakpoint |
| 77 | CREATE INDEX `nodes_parent_kind_idx` ON `nodes` (`parent_id`,`kind`);--> statement-breakpoint |
| 78 | CREATE INDEX `nodes_blob_idx` ON `nodes` (`blob_id`);--> statement-breakpoint |
| 79 | CREATE INDEX `nodes_modified_idx` ON `nodes` (`modified_at_ms`);--> statement-breakpoint |
| 80 | CREATE TABLE `pending_uploads` ( |
| 81 | `upload_id` text PRIMARY KEY NOT NULL, |
| 82 | `node_id` text, |
| 83 | `path` text NOT NULL, |
| 84 | `blob_id` text NOT NULL, |
| 85 | `blob_key` text NOT NULL, |
| 86 | `created_at_ms` integer NOT NULL, |
| 87 | `expires_at_ms` integer NOT NULL, |
| 88 | `state` text NOT NULL, |
| 89 | FOREIGN KEY (`node_id`) REFERENCES `nodes`(`id`) ON UPDATE no action ON DELETE set null, |
| 90 | CONSTRAINT "pending_uploads_state_check" CHECK("pending_uploads"."state" in ('pending', 'committed', 'aborted')) |
| 91 | ); |
| 92 | --> statement-breakpoint |
| 93 | CREATE INDEX `pending_uploads_state_expires_idx` ON `pending_uploads` (`state`,`expires_at_ms`);--> statement-breakpoint |
| 94 | CREATE INDEX `pending_uploads_path_idx` ON `pending_uploads` (`path`);--> statement-breakpoint |
| 95 | CREATE INDEX `pending_uploads_blob_idx` ON `pending_uploads` (`blob_id`);--> statement-breakpoint |
| 96 | ALTER TABLE `meta` DROP COLUMN `updated_at_ms`; |