|
| 1 | +CREATE TABLE `attachments` ( |
| 2 | + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, |
| 3 | + `lessonId` integer NOT NULL, |
| 4 | + `title` text, |
| 5 | + `media_type` text DEFAULT 'other' NOT NULL, |
| 6 | + `blobId` integer, |
| 7 | + `external_url` text, |
| 8 | + `metadata` text DEFAULT '{}' NOT NULL, |
| 9 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 10 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 11 | + FOREIGN KEY (`lessonId`) REFERENCES `lessons`(`id`) ON UPDATE no action ON DELETE cascade, |
| 12 | + FOREIGN KEY (`blobId`) REFERENCES `blobs`(`id`) ON UPDATE no action ON DELETE set null, |
| 13 | + CONSTRAINT "attachments_source_presence_check" CHECK(( ("attachments"."blobId" IS NOT NULL AND "attachments"."external_url" IS NULL) |
| 14 | + OR ("attachments"."blobId" IS NULL AND "attachments"."external_url" IS NOT NULL) )), |
| 15 | + CONSTRAINT "attachments_url_shape_check" CHECK(("attachments"."external_url" IS NULL OR "attachments"."external_url" GLOB 'http*://*')) |
| 16 | +); |
| 17 | +--> statement-breakpoint |
| 18 | +CREATE TABLE `blobs` ( |
| 19 | + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, |
| 20 | + `bucket` text NOT NULL, |
| 21 | + `object_key` text NOT NULL, |
| 22 | + `version_id` text, |
| 23 | + `etag` text, |
| 24 | + `size_bytes` integer, |
| 25 | + `content_type` text, |
| 26 | + `checksum_sha256` text, |
| 27 | + `storage_class` text, |
| 28 | + `createdBy` integer, |
| 29 | + `is_deleted` integer DEFAULT false NOT NULL, |
| 30 | + `deleted_at` integer, |
| 31 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 32 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 33 | + FOREIGN KEY (`createdBy`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null |
| 34 | +); |
| 35 | +--> statement-breakpoint |
| 36 | +CREATE UNIQUE INDEX `blobs_unique` ON `blobs` (`bucket`,`object_key`,`version_id`);--> statement-breakpoint |
| 37 | +CREATE TABLE `courses` ( |
| 38 | + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, |
| 39 | + `title` text NOT NULL, |
| 40 | + `description` text, |
| 41 | + `difficulty` text DEFAULT 'beginner' NOT NULL, |
| 42 | + `createdBy` integer, |
| 43 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 44 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 45 | + FOREIGN KEY (`createdBy`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null |
| 46 | +); |
| 47 | +--> statement-breakpoint |
| 48 | +CREATE TABLE `courses_tags` ( |
| 49 | + `courseId` integer NOT NULL, |
| 50 | + `tagId` integer NOT NULL, |
| 51 | + `added_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 52 | + PRIMARY KEY(`courseId`, `tagId`), |
| 53 | + FOREIGN KEY (`courseId`) REFERENCES `courses`(`id`) ON UPDATE no action ON DELETE cascade, |
| 54 | + FOREIGN KEY (`tagId`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE cascade |
| 55 | +); |
| 56 | +--> statement-breakpoint |
| 57 | +CREATE TABLE `lessons` ( |
| 58 | + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, |
| 59 | + `unitId` integer NOT NULL, |
| 60 | + `media_type` text DEFAULT 'markdown' NOT NULL, |
| 61 | + `content_url` text, |
| 62 | + `contentBlobId` integer, |
| 63 | + `metadata` text DEFAULT '{}' NOT NULL, |
| 64 | + `position` integer DEFAULT 1 NOT NULL, |
| 65 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 66 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 67 | + FOREIGN KEY (`unitId`) REFERENCES `units`(`id`) ON UPDATE no action ON DELETE cascade, |
| 68 | + FOREIGN KEY (`contentBlobId`) REFERENCES `blobs`(`id`) ON UPDATE no action ON DELETE set null, |
| 69 | + CONSTRAINT "lessons_position_check" CHECK("lessons"."position" >= 1), |
| 70 | + CONSTRAINT "lessons_content_presence_check" CHECK(("lessons"."content_url" IS NOT NULL AND "lessons"."contentBlobId" IS NULL) OR ("lessons"."content_url" IS NULL AND "lessons"."contentBlobId" IS NOT NULL)), |
| 71 | + CONSTRAINT "lessons_url_shape_check" CHECK(("lessons"."content_url" IS NULL OR "lessons"."content_url" GLOB 'http*://*')) |
| 72 | +); |
| 73 | +--> statement-breakpoint |
| 74 | +CREATE TABLE `tags` ( |
| 75 | + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, |
| 76 | + `tag_name` text NOT NULL, |
| 77 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 78 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 79 | + CONSTRAINT "tags_tag_name_check" CHECK("tags"."tag_name" IS NOT NULL) |
| 80 | +); |
| 81 | +--> statement-breakpoint |
| 82 | +CREATE UNIQUE INDEX `tags_tag_name_unique` ON `tags` (`tag_name`);--> statement-breakpoint |
| 83 | +CREATE TABLE `units` ( |
| 84 | + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, |
| 85 | + `course_id` text NOT NULL, |
| 86 | + `title` text, |
| 87 | + `position` integer DEFAULT 1 NOT NULL, |
| 88 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 89 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 90 | + FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON UPDATE no action ON DELETE cascade, |
| 91 | + CONSTRAINT "units_position_check" CHECK("units"."position" >= 1) |
| 92 | +); |
| 93 | +--> statement-breakpoint |
| 94 | +CREATE INDEX `units_position_index` ON `units` ("position");--> statement-breakpoint |
| 95 | +CREATE TABLE `accounts` ( |
| 96 | + `id` text PRIMARY KEY NOT NULL, |
| 97 | + `account_id` text NOT NULL, |
| 98 | + `provider_id` text NOT NULL, |
| 99 | + `user_id` text NOT NULL, |
| 100 | + `access_token` text, |
| 101 | + `refresh_token` text, |
| 102 | + `id_token` text, |
| 103 | + `access_token_expires_at` integer, |
| 104 | + `refresh_token_expires_at` integer, |
| 105 | + `scope` text, |
| 106 | + `password` text, |
| 107 | + `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 108 | + `updated_at` integer NOT NULL, |
| 109 | + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade |
| 110 | +); |
| 111 | +--> statement-breakpoint |
| 112 | +CREATE TABLE `sessions` ( |
| 113 | + `id` text PRIMARY KEY NOT NULL, |
| 114 | + `expires_at` integer NOT NULL, |
| 115 | + `token` text NOT NULL, |
| 116 | + `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 117 | + `updated_at` integer NOT NULL, |
| 118 | + `ip_address` text, |
| 119 | + `user_agent` text, |
| 120 | + `user_id` text NOT NULL, |
| 121 | + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade |
| 122 | +); |
| 123 | +--> statement-breakpoint |
| 124 | +CREATE UNIQUE INDEX `sessions_token_unique` ON `sessions` (`token`);--> statement-breakpoint |
| 125 | +CREATE TABLE `users` ( |
| 126 | + `id` text PRIMARY KEY NOT NULL, |
| 127 | + `name` text NOT NULL, |
| 128 | + `email` text NOT NULL, |
| 129 | + `role` text DEFAULT 'user' NOT NULL, |
| 130 | + `email_verified` integer DEFAULT false NOT NULL, |
| 131 | + `image` text, |
| 132 | + `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 133 | + `updated_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL |
| 134 | +); |
| 135 | +--> statement-breakpoint |
| 136 | +CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint |
| 137 | +CREATE TABLE `verifications` ( |
| 138 | + `id` text PRIMARY KEY NOT NULL, |
| 139 | + `identifier` text NOT NULL, |
| 140 | + `value` text NOT NULL, |
| 141 | + `expires_at` integer NOT NULL, |
| 142 | + `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 143 | + `updated_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL |
| 144 | +); |
0 commit comments