|
| 1 | +CREATE TABLE `authKey` ( |
| 2 | + `id` text PRIMARY KEY NOT NULL, |
| 3 | + `user_id` text NOT NULL, |
| 4 | + `primary_key` text NOT NULL, |
| 5 | + `hashed_password` text, |
| 6 | + `expires` integer, |
| 7 | + FOREIGN KEY (`user_id`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE cascade |
| 8 | +); |
| 9 | +--> statement-breakpoint |
| 10 | +CREATE TABLE `authSession` ( |
| 11 | + `id` text PRIMARY KEY NOT NULL, |
| 12 | + `user_id` text NOT NULL, |
| 13 | + `expires_at` integer NOT NULL, |
| 14 | + FOREIGN KEY (`user_id`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE cascade |
| 15 | +); |
| 16 | +--> statement-breakpoint |
| 17 | +CREATE TABLE `authUser` ( |
| 18 | + `id` text PRIMARY KEY NOT NULL, |
| 19 | + `username` text NOT NULL, |
| 20 | + `email` text NOT NULL, |
| 21 | + `auth_type` text NOT NULL, |
| 22 | + `first_name` text, |
| 23 | + `last_name` text, |
| 24 | + `github_id` text, |
| 25 | + `hashed_password` text, |
| 26 | + `role_id` text, |
| 27 | + `email_verified` integer DEFAULT false NOT NULL, |
| 28 | + FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON UPDATE no action ON DELETE no action |
| 29 | +); |
| 30 | +--> statement-breakpoint |
| 31 | +CREATE UNIQUE INDEX `authUser_username_unique` ON `authUser` (`username`);--> statement-breakpoint |
| 32 | +CREATE UNIQUE INDEX `authUser_email_unique` ON `authUser` (`email`);--> statement-breakpoint |
| 33 | +CREATE UNIQUE INDEX `authUser_github_id_unique` ON `authUser` (`github_id`);--> statement-breakpoint |
| 34 | +CREATE TABLE `emailVerificationTokens` ( |
| 35 | + `id` text PRIMARY KEY NOT NULL, |
| 36 | + `user_id` text NOT NULL, |
| 37 | + `token_hash` text NOT NULL, |
| 38 | + `expires_at` integer NOT NULL, |
| 39 | + `created_at` integer NOT NULL, |
| 40 | + FOREIGN KEY (`user_id`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE cascade |
| 41 | +); |
| 42 | +--> statement-breakpoint |
| 43 | +CREATE TABLE `globalSettingGroups` ( |
| 44 | + `id` text PRIMARY KEY NOT NULL, |
| 45 | + `name` text NOT NULL, |
| 46 | + `description` text, |
| 47 | + `icon` text, |
| 48 | + `sort_order` integer DEFAULT 0 NOT NULL, |
| 49 | + `created_at` integer NOT NULL, |
| 50 | + `updated_at` integer NOT NULL |
| 51 | +); |
| 52 | +--> statement-breakpoint |
| 53 | +CREATE TABLE `globalSettings` ( |
| 54 | + `key` text PRIMARY KEY NOT NULL, |
| 55 | + `value` text NOT NULL, |
| 56 | + `type` text DEFAULT 'string' NOT NULL, |
| 57 | + `description` text, |
| 58 | + `is_encrypted` integer DEFAULT false NOT NULL, |
| 59 | + `group_id` text, |
| 60 | + `created_at` integer NOT NULL, |
| 61 | + `updated_at` integer NOT NULL, |
| 62 | + FOREIGN KEY (`group_id`) REFERENCES `globalSettingGroups`(`id`) ON UPDATE no action ON DELETE no action |
| 63 | +); |
| 64 | +--> statement-breakpoint |
| 65 | +CREATE TABLE `mcpCategories` ( |
| 66 | + `id` text PRIMARY KEY NOT NULL, |
| 67 | + `name` text NOT NULL, |
| 68 | + `description` text, |
| 69 | + `icon` text, |
| 70 | + `sort_order` integer DEFAULT 0 NOT NULL, |
| 71 | + `created_at` integer NOT NULL |
| 72 | +); |
| 73 | +--> statement-breakpoint |
| 74 | +CREATE UNIQUE INDEX `mcpCategories_name_unique` ON `mcpCategories` (`name`);--> statement-breakpoint |
| 75 | +CREATE TABLE `mcpServerInstallations` ( |
| 76 | + `id` text PRIMARY KEY NOT NULL, |
| 77 | + `team_id` text NOT NULL, |
| 78 | + `server_id` text NOT NULL, |
| 79 | + `user_id` text NOT NULL, |
| 80 | + `installation_name` text NOT NULL, |
| 81 | + `installation_type` text DEFAULT 'local' NOT NULL, |
| 82 | + `user_environment_variables` text, |
| 83 | + `created_at` integer NOT NULL, |
| 84 | + `updated_at` integer NOT NULL, |
| 85 | + `last_used_at` integer, |
| 86 | + FOREIGN KEY (`team_id`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade, |
| 87 | + FOREIGN KEY (`server_id`) REFERENCES `mcpServers`(`id`) ON UPDATE no action ON DELETE cascade, |
| 88 | + FOREIGN KEY (`user_id`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE no action |
| 89 | +); |
| 90 | +--> statement-breakpoint |
| 91 | +CREATE INDEX `mcp_installations_team_name_idx` ON `mcpServerInstallations` (`team_id`,`installation_name`);--> statement-breakpoint |
| 92 | +CREATE INDEX `mcp_installations_team_server_idx` ON `mcpServerInstallations` (`team_id`,`server_id`);--> statement-breakpoint |
| 93 | +CREATE INDEX `mcp_installations_user_idx` ON `mcpServerInstallations` (`user_id`);--> statement-breakpoint |
| 94 | +CREATE TABLE `mcpServerVersions` ( |
| 95 | + `id` text PRIMARY KEY NOT NULL, |
| 96 | + `server_id` text NOT NULL, |
| 97 | + `version` text NOT NULL, |
| 98 | + `git_commit` text, |
| 99 | + `changelog` text, |
| 100 | + `is_latest` integer DEFAULT false NOT NULL, |
| 101 | + `is_stable` integer DEFAULT true NOT NULL, |
| 102 | + `created_at` integer NOT NULL, |
| 103 | + FOREIGN KEY (`server_id`) REFERENCES `mcpServers`(`id`) ON UPDATE no action ON DELETE cascade |
| 104 | +); |
| 105 | +--> statement-breakpoint |
| 106 | +CREATE INDEX `mcp_server_versions_server_idx` ON `mcpServerVersions` (`server_id`);--> statement-breakpoint |
| 107 | +CREATE INDEX `mcp_server_versions_latest_idx` ON `mcpServerVersions` (`is_latest`);--> statement-breakpoint |
| 108 | +CREATE TABLE `mcpServers` ( |
| 109 | + `id` text PRIMARY KEY NOT NULL, |
| 110 | + `name` text NOT NULL, |
| 111 | + `slug` text NOT NULL, |
| 112 | + `description` text NOT NULL, |
| 113 | + `long_description` text, |
| 114 | + `github_url` text, |
| 115 | + `git_branch` text DEFAULT 'main', |
| 116 | + `homepage_url` text, |
| 117 | + `language` text NOT NULL, |
| 118 | + `runtime` text NOT NULL, |
| 119 | + `runtime_min_version` text, |
| 120 | + `installation_methods` text NOT NULL, |
| 121 | + `tools` text NOT NULL, |
| 122 | + `resources` text, |
| 123 | + `prompts` text, |
| 124 | + `visibility` text DEFAULT 'team' NOT NULL, |
| 125 | + `owner_team_id` text, |
| 126 | + `created_by` text NOT NULL, |
| 127 | + `author_name` text, |
| 128 | + `author_contact` text, |
| 129 | + `organization` text, |
| 130 | + `license` text, |
| 131 | + `default_config` text, |
| 132 | + `environment_variables` text, |
| 133 | + `dependencies` text, |
| 134 | + `category_id` text, |
| 135 | + `tags` text, |
| 136 | + `status` text DEFAULT 'active' NOT NULL, |
| 137 | + `featured` integer DEFAULT false NOT NULL, |
| 138 | + `created_at` integer NOT NULL, |
| 139 | + `updated_at` integer NOT NULL, |
| 140 | + `last_sync_at` integer, |
| 141 | + FOREIGN KEY (`owner_team_id`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade, |
| 142 | + FOREIGN KEY (`created_by`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE no action, |
| 143 | + FOREIGN KEY (`category_id`) REFERENCES `mcpCategories`(`id`) ON UPDATE no action ON DELETE no action |
| 144 | +); |
| 145 | +--> statement-breakpoint |
| 146 | +CREATE UNIQUE INDEX `mcpServers_slug_unique` ON `mcpServers` (`slug`);--> statement-breakpoint |
| 147 | +CREATE INDEX `mcp_servers_visibility_idx` ON `mcpServers` (`visibility`);--> statement-breakpoint |
| 148 | +CREATE INDEX `mcp_servers_category_idx` ON `mcpServers` (`category_id`);--> statement-breakpoint |
| 149 | +CREATE INDEX `mcp_servers_status_idx` ON `mcpServers` (`status`);--> statement-breakpoint |
| 150 | +CREATE INDEX `mcp_servers_owner_team_idx` ON `mcpServers` (`owner_team_id`);--> statement-breakpoint |
| 151 | +CREATE TABLE `passwordResetTokens` ( |
| 152 | + `id` text PRIMARY KEY NOT NULL, |
| 153 | + `user_id` text NOT NULL, |
| 154 | + `token_hash` text NOT NULL, |
| 155 | + `expires_at` integer NOT NULL, |
| 156 | + `created_at` integer NOT NULL, |
| 157 | + FOREIGN KEY (`user_id`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE cascade |
| 158 | +); |
| 159 | +--> statement-breakpoint |
| 160 | +CREATE TABLE `roles` ( |
| 161 | + `id` text PRIMARY KEY NOT NULL, |
| 162 | + `name` text NOT NULL, |
| 163 | + `description` text, |
| 164 | + `permissions` text NOT NULL, |
| 165 | + `is_system_role` integer DEFAULT false NOT NULL, |
| 166 | + `created_at` integer NOT NULL, |
| 167 | + `updated_at` integer NOT NULL |
| 168 | +); |
| 169 | +--> statement-breakpoint |
| 170 | +CREATE UNIQUE INDEX `roles_name_unique` ON `roles` (`name`);--> statement-breakpoint |
| 171 | +CREATE TABLE `teamCloudCredentials` ( |
| 172 | + `id` text PRIMARY KEY NOT NULL, |
| 173 | + `team_id` text NOT NULL, |
| 174 | + `provider_id` text NOT NULL, |
| 175 | + `name` text NOT NULL, |
| 176 | + `comment` text, |
| 177 | + `credentials` text NOT NULL, |
| 178 | + `created_by` text NOT NULL, |
| 179 | + `created_at` integer NOT NULL, |
| 180 | + `updated_at` integer NOT NULL, |
| 181 | + FOREIGN KEY (`team_id`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade, |
| 182 | + FOREIGN KEY (`created_by`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE no action |
| 183 | +); |
| 184 | +--> statement-breakpoint |
| 185 | +CREATE TABLE `teamMemberships` ( |
| 186 | + `id` text PRIMARY KEY NOT NULL, |
| 187 | + `team_id` text NOT NULL, |
| 188 | + `user_id` text NOT NULL, |
| 189 | + `role` text NOT NULL, |
| 190 | + `joined_at` integer NOT NULL, |
| 191 | + FOREIGN KEY (`team_id`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade, |
| 192 | + FOREIGN KEY (`user_id`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE cascade |
| 193 | +); |
| 194 | +--> statement-breakpoint |
| 195 | +CREATE TABLE `teams` ( |
| 196 | + `id` text PRIMARY KEY NOT NULL, |
| 197 | + `name` text NOT NULL, |
| 198 | + `slug` text NOT NULL, |
| 199 | + `description` text, |
| 200 | + `owner_id` text NOT NULL, |
| 201 | + `is_default` integer DEFAULT false NOT NULL, |
| 202 | + `created_at` integer NOT NULL, |
| 203 | + `updated_at` integer NOT NULL, |
| 204 | + FOREIGN KEY (`owner_id`) REFERENCES `authUser`(`id`) ON UPDATE no action ON DELETE cascade |
| 205 | +); |
| 206 | +--> statement-breakpoint |
| 207 | +CREATE UNIQUE INDEX `teams_slug_unique` ON `teams` (`slug`);--> statement-breakpoint |
| 208 | + |
| 209 | +-- Insert default roles (permissions will be synced by RoleSyncService on server startup) |
| 210 | +INSERT INTO `roles` (`id`, `name`, `description`, `permissions`, `is_system_role`, `created_at`, `updated_at`) VALUES |
| 211 | +('global_admin', 'Global Administrator', 'Full system access with user management capabilities', '[]', 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000), |
| 212 | +('global_user', 'Global User', 'Standard user with basic profile access', '[]', 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000), |
| 213 | +('team_admin', 'Team Administrator', 'Team management with member and credential access', '[]', 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000), |
| 214 | +('team_user', 'Team User', 'Basic team member with view access', '[]', 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000); |
0 commit comments