File
Blob: drizzle/d1/0000_skinny_titania.sql
| 1 | CREATE TABLE `accounts` ( |
| 2 | `id` text PRIMARY KEY NOT NULL, |
| 3 | `account_id` text NOT NULL, |
| 4 | `provider_id` text NOT NULL, |
| 5 | `user_id` text NOT NULL, |
| 6 | `access_token` text, |
| 7 | `refresh_token` text, |
| 8 | `id_token` text, |
| 9 | `access_token_expires_at` integer, |
| 10 | `refresh_token_expires_at` integer, |
| 11 | `scope` text, |
| 12 | `password` text, |
| 13 | `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 14 | `updated_at` integer NOT NULL, |
| 15 | FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade |
| 16 | ); |
| 17 | --> statement-breakpoint |
| 18 | CREATE INDEX `accounts_userId_idx` ON `accounts` (`user_id`);--> statement-breakpoint |
| 19 | CREATE TABLE `jwkss` ( |
| 20 | `id` text PRIMARY KEY NOT NULL, |
| 21 | `public_key` text NOT NULL, |
| 22 | `private_key` text NOT NULL, |
| 23 | `created_at` integer NOT NULL, |
| 24 | `expires_at` integer |
| 25 | ); |
| 26 | --> statement-breakpoint |
| 27 | CREATE TABLE `oauth_access_tokens` ( |
| 28 | `id` text PRIMARY KEY NOT NULL, |
| 29 | `token` text, |
| 30 | `client_id` text NOT NULL, |
| 31 | `session_id` text, |
| 32 | `user_id` text, |
| 33 | `reference_id` text, |
| 34 | `refresh_id` text, |
| 35 | `expires_at` integer, |
| 36 | `created_at` integer, |
| 37 | `scopes` text NOT NULL, |
| 38 | FOREIGN KEY (`client_id`) REFERENCES `oauth_clients`(`client_id`) ON UPDATE no action ON DELETE cascade, |
| 39 | FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null, |
| 40 | FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade, |
| 41 | FOREIGN KEY (`refresh_id`) REFERENCES `oauth_refresh_tokens`(`id`) ON UPDATE no action ON DELETE cascade |
| 42 | ); |
| 43 | --> statement-breakpoint |
| 44 | CREATE UNIQUE INDEX `oauth_access_tokens_token_unique` ON `oauth_access_tokens` (`token`);--> statement-breakpoint |
| 45 | CREATE TABLE `oauth_clients` ( |
| 46 | `id` text PRIMARY KEY NOT NULL, |
| 47 | `client_id` text NOT NULL, |
| 48 | `client_secret` text, |
| 49 | `disabled` integer DEFAULT false, |
| 50 | `skip_consent` integer, |
| 51 | `enable_end_session` integer, |
| 52 | `subject_type` text, |
| 53 | `scopes` text, |
| 54 | `user_id` text, |
| 55 | `created_at` integer, |
| 56 | `updated_at` integer, |
| 57 | `name` text, |
| 58 | `uri` text, |
| 59 | `icon` text, |
| 60 | `contacts` text, |
| 61 | `tos` text, |
| 62 | `policy` text, |
| 63 | `software_id` text, |
| 64 | `software_version` text, |
| 65 | `software_statement` text, |
| 66 | `redirect_uris` text NOT NULL, |
| 67 | `post_logout_redirect_uris` text, |
| 68 | `token_endpoint_auth_method` text, |
| 69 | `grant_types` text, |
| 70 | `response_types` text, |
| 71 | `public` integer, |
| 72 | `type` text, |
| 73 | `require_pkce` integer, |
| 74 | `reference_id` text, |
| 75 | `metadata` text, |
| 76 | FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade |
| 77 | ); |
| 78 | --> statement-breakpoint |
| 79 | CREATE UNIQUE INDEX `oauth_clients_client_id_unique` ON `oauth_clients` (`client_id`);--> statement-breakpoint |
| 80 | CREATE TABLE `oauth_consents` ( |
| 81 | `id` text PRIMARY KEY NOT NULL, |
| 82 | `client_id` text NOT NULL, |
| 83 | `user_id` text, |
| 84 | `reference_id` text, |
| 85 | `scopes` text NOT NULL, |
| 86 | `created_at` integer, |
| 87 | `updated_at` integer, |
| 88 | FOREIGN KEY (`client_id`) REFERENCES `oauth_clients`(`client_id`) ON UPDATE no action ON DELETE cascade, |
| 89 | FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade |
| 90 | ); |
| 91 | --> statement-breakpoint |
| 92 | CREATE TABLE `oauth_refresh_tokens` ( |
| 93 | `id` text PRIMARY KEY NOT NULL, |
| 94 | `token` text NOT NULL, |
| 95 | `client_id` text NOT NULL, |
| 96 | `session_id` text, |
| 97 | `user_id` text NOT NULL, |
| 98 | `reference_id` text, |
| 99 | `expires_at` integer, |
| 100 | `created_at` integer, |
| 101 | `revoked` integer, |
| 102 | `auth_time` integer, |
| 103 | `scopes` text NOT NULL, |
| 104 | FOREIGN KEY (`client_id`) REFERENCES `oauth_clients`(`client_id`) ON UPDATE no action ON DELETE cascade, |
| 105 | FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null, |
| 106 | FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade |
| 107 | ); |
| 108 | --> statement-breakpoint |
| 109 | CREATE TABLE `sessions` ( |
| 110 | `id` text PRIMARY KEY NOT NULL, |
| 111 | `expires_at` integer NOT NULL, |
| 112 | `token` text NOT NULL, |
| 113 | `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 114 | `updated_at` integer NOT NULL, |
| 115 | `ip_address` text, |
| 116 | `user_agent` text, |
| 117 | `user_id` text NOT NULL, |
| 118 | `impersonated_by` text, |
| 119 | FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade |
| 120 | ); |
| 121 | --> statement-breakpoint |
| 122 | CREATE UNIQUE INDEX `sessions_token_unique` ON `sessions` (`token`);--> statement-breakpoint |
| 123 | CREATE INDEX `sessions_userId_idx` ON `sessions` (`user_id`);--> statement-breakpoint |
| 124 | CREATE TABLE `users` ( |
| 125 | `id` text PRIMARY KEY NOT NULL, |
| 126 | `name` text NOT NULL, |
| 127 | `email` text NOT NULL, |
| 128 | `email_verified` integer DEFAULT false NOT NULL, |
| 129 | `image` text, |
| 130 | `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 131 | `updated_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 132 | `role` text, |
| 133 | `banned` integer DEFAULT false, |
| 134 | `ban_reason` text, |
| 135 | `ban_expires` integer, |
| 136 | `preferred_username` text |
| 137 | ); |
| 138 | --> statement-breakpoint |
| 139 | CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint |
| 140 | CREATE TABLE `verifications` ( |
| 141 | `id` text PRIMARY KEY NOT NULL, |
| 142 | `identifier` text NOT NULL, |
| 143 | `value` text NOT NULL, |
| 144 | `expires_at` integer NOT NULL, |
| 145 | `created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL, |
| 146 | `updated_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL |
| 147 | ); |
| 148 | --> statement-breakpoint |
| 149 | CREATE INDEX `verifications_identifier_idx` ON `verifications` (`identifier`);--> statement-breakpoint |
| 150 | CREATE TABLE `invites` ( |
| 151 | `id` text PRIMARY KEY NOT NULL, |
| 152 | `token_hash` text NOT NULL, |
| 153 | `email` text NOT NULL, |
| 154 | `created_by` text NOT NULL, |
| 155 | `created_at` text DEFAULT (current_timestamp) NOT NULL, |
| 156 | `expires_at` text NOT NULL, |
| 157 | `consumed_at` text |
| 158 | ); |
| 159 | --> statement-breakpoint |
| 160 | CREATE UNIQUE INDEX `idx_invites_token_hash` ON `invites` (`token_hash`);--> statement-breakpoint |
| 161 | CREATE UNIQUE INDEX `idx_invites_email` ON `invites` (`email`);--> statement-breakpoint |
| 162 | CREATE INDEX `idx_invites_created_by_created_at` ON `invites` (`created_by`,`created_at`);--> statement-breakpoint |
| 163 | CREATE INDEX `idx_invites_expires_at` ON `invites` (`expires_at`); |