|
| 1 | +CREATE TABLE IF NOT EXISTS `attachments` ( |
| 2 | + `attachment_id` text PRIMARY KEY NOT NULL, |
| 3 | + `lesson_id` text NOT NULL, |
| 4 | + `title` text, |
| 5 | + `media_type` text DEFAULT 'other' NOT NULL, |
| 6 | + `blob_id` text, |
| 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 (`lesson_id`) REFERENCES `lessons`(`lesson_id`) ON UPDATE no action ON DELETE cascade, |
| 12 | + FOREIGN KEY (`blob_id`) REFERENCES `blobs`(`blob_id`) ON UPDATE no action ON DELETE set null |
| 13 | +); |
| 14 | +--> statement-breakpoint |
| 15 | +CREATE TABLE IF NOT EXISTS `blobs` ( |
| 16 | + `blob_id` text PRIMARY KEY NOT NULL, |
| 17 | + `bucket` text NOT NULL, |
| 18 | + `object_key` text NOT NULL, |
| 19 | + `version_id` text, |
| 20 | + `etag` text, |
| 21 | + `size_bytes` integer, |
| 22 | + `content_type` text, |
| 23 | + `checksum_sha256` text, |
| 24 | + `storage_class` text, |
| 25 | + `created_by` text, |
| 26 | + `is_deleted` integer DEFAULT 0 NOT NULL, |
| 27 | + `deleted_at` integer, |
| 28 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 29 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 30 | + FOREIGN KEY (`created_by`) REFERENCES `users`(`user_id`) ON UPDATE no action ON DELETE set null |
| 31 | +); |
| 32 | +--> statement-breakpoint |
| 33 | +CREATE TABLE IF NOT EXISTS `courses` ( |
| 34 | + `course_id` text PRIMARY KEY NOT NULL, |
| 35 | + `title` text NOT NULL, |
| 36 | + `description` text, |
| 37 | + `difficulty` text DEFAULT 'beginner' NOT NULL, |
| 38 | + `created_by` text, |
| 39 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 40 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 41 | + FOREIGN KEY (`created_by`) REFERENCES `users`(`user_id`) ON UPDATE no action ON DELETE set null |
| 42 | +); |
| 43 | +--> statement-breakpoint |
| 44 | +CREATE TABLE IF NOT EXISTS `courses_tags` ( |
| 45 | + `course_id` text NOT NULL, |
| 46 | + `tag_id` text NOT NULL, |
| 47 | + `added_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 48 | + PRIMARY KEY(`course_id`, `tag_id`), |
| 49 | + FOREIGN KEY (`course_id`) REFERENCES `courses`(`course_id`) ON UPDATE no action ON DELETE cascade, |
| 50 | + FOREIGN KEY (`tag_id`) REFERENCES `tags`(`tag_id`) ON UPDATE no action ON DELETE cascade |
| 51 | +); |
| 52 | +--> statement-breakpoint |
| 53 | +CREATE TABLE IF NOT EXISTS `lessons` ( |
| 54 | + `lesson_id` text PRIMARY KEY NOT NULL, |
| 55 | + `unit_id` text NOT NULL, |
| 56 | + `media_type` text DEFAULT 'markdown' NOT NULL, |
| 57 | + `content_url` text, |
| 58 | + `content_blob_id` text, |
| 59 | + `metadata` text DEFAULT '{}' NOT NULL, |
| 60 | + `position` integer DEFAULT 1 NOT NULL, |
| 61 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 62 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 63 | + FOREIGN KEY (`unit_id`) REFERENCES `units`(`unit_id`) ON UPDATE no action ON DELETE cascade, |
| 64 | + FOREIGN KEY (`content_blob_id`) REFERENCES `blobs`(`blob_id`) ON UPDATE no action ON DELETE set null |
| 65 | +); |
| 66 | +--> statement-breakpoint |
| 67 | +CREATE TABLE IF NOT EXISTS `profiles` ( |
| 68 | + `profile_id` text PRIMARY KEY NOT NULL, |
| 69 | + `user_id` text NOT NULL, |
| 70 | + `role` text DEFAULT 'student' NOT NULL, |
| 71 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 72 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 73 | + FOREIGN KEY (`user_id`) REFERENCES `users`(`user_id`) ON UPDATE no action ON DELETE cascade |
| 74 | +); |
| 75 | +--> statement-breakpoint |
| 76 | +CREATE TABLE IF NOT EXISTS `tags` ( |
| 77 | + `tag_id` text PRIMARY KEY NOT NULL, |
| 78 | + `tag_name` text NOT NULL, |
| 79 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 80 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL |
| 81 | +); |
| 82 | +--> statement-breakpoint |
| 83 | +CREATE TABLE IF NOT EXISTS `units` ( |
| 84 | + `unit_id` text PRIMARY KEY 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`(`course_id`) ON UPDATE no action ON DELETE cascade |
| 91 | +); |
| 92 | +--> statement-breakpoint |
| 93 | +CREATE TABLE IF NOT EXISTS `users` ( |
| 94 | + `user_id` text PRIMARY KEY NOT NULL, |
| 95 | + `provider` text NOT NULL, |
| 96 | + `subject` text NOT NULL, |
| 97 | + `email` text, |
| 98 | + `display_name` text, |
| 99 | + `created_at` integer DEFAULT (unixepoch()) NOT NULL, |
| 100 | + `updated_at` integer DEFAULT (unixepoch()) NOT NULL |
| 101 | +); |
0 commit comments