File
Blob: drizzle/d1/0001_perfect_black_bird.sql
| 1 | CREATE TABLE `audit_events` ( |
| 2 | `id` text PRIMARY KEY NOT NULL, |
| 3 | `subject_id` text, |
| 4 | `event_type` text NOT NULL, |
| 5 | `actor_subject_id` text, |
| 6 | `ip_hash` text, |
| 7 | `user_agent_hash` text, |
| 8 | `created_at_ms` integer NOT NULL, |
| 9 | `data_json` text NOT NULL, |
| 10 | FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON UPDATE no action ON DELETE set null |
| 11 | ); |
| 12 | --> statement-breakpoint |
| 13 | CREATE INDEX `audit_events_subject_created_idx` ON `audit_events` (`subject_id`,`created_at_ms`);--> statement-breakpoint |
| 14 | CREATE INDEX `audit_events_type_created_idx` ON `audit_events` (`event_type`,`created_at_ms`);--> statement-breakpoint |
| 15 | CREATE INDEX `audit_events_actor_created_idx` ON `audit_events` (`actor_subject_id`,`created_at_ms`);--> statement-breakpoint |
| 16 | CREATE TABLE `pat_projections` ( |
| 17 | `id` text PRIMARY KEY NOT NULL, |
| 18 | `subject_id` text NOT NULL, |
| 19 | `name` text NOT NULL, |
| 20 | `scopes_json` text NOT NULL, |
| 21 | `created_at_ms` integer NOT NULL, |
| 22 | `expires_at_ms` integer, |
| 23 | `revoked_at_ms` integer, |
| 24 | `last_used_at_ms` integer, |
| 25 | FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON UPDATE no action ON DELETE cascade |
| 26 | ); |
| 27 | --> statement-breakpoint |
| 28 | CREATE INDEX `pat_projections_subject_created_idx` ON `pat_projections` (`subject_id`,`created_at_ms`);--> statement-breakpoint |
| 29 | CREATE INDEX `pat_projections_subject_active_idx` ON `pat_projections` (`subject_id`,`revoked_at_ms`,`expires_at_ms`);--> statement-breakpoint |
| 30 | CREATE TABLE `subjects` ( |
| 31 | `id` text PRIMARY KEY NOT NULL, |
| 32 | `storage_id` text NOT NULL, |
| 33 | `host_label` text NOT NULL, |
| 34 | `email` text, |
| 35 | `display_name` text, |
| 36 | `created_at_ms` integer NOT NULL, |
| 37 | `last_login_at_ms` integer, |
| 38 | `host_rotated_at_ms` integer, |
| 39 | `disabled_at_ms` integer |
| 40 | ); |
| 41 | --> statement-breakpoint |
| 42 | CREATE UNIQUE INDEX `subjects_storage_id_unique` ON `subjects` (`storage_id`);--> statement-breakpoint |
| 43 | CREATE UNIQUE INDEX `subjects_host_label_unique` ON `subjects` (`host_label`);--> statement-breakpoint |
| 44 | CREATE INDEX `subjects_disabled_idx` ON `subjects` (`disabled_at_ms`); |