File
Blob: src/worker/db/durable/schema/project-do.ts
| 1 | import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core"; |
| 2 | |
| 3 | import { bytes } from "@/worker/db"; |
| 4 | |
| 5 | export const projectState = sqliteTable("project_state", { |
| 6 | projectId: text("project_id").primaryKey(), |
| 7 | activeRunId: text("active_run_id"), |
| 8 | projectIndexSyncStatus: text("project_index_sync_status").notNull(), |
| 9 | updatedAt: integer("updated_at").notNull(), |
| 10 | }); |
| 11 | |
| 12 | export const projectConfig = sqliteTable("project_config", { |
| 13 | projectId: text("project_id").primaryKey(), |
| 14 | name: text("name").notNull(), |
| 15 | repoUrl: text("repo_url").notNull(), |
| 16 | defaultBranch: text("default_branch").notNull(), |
| 17 | configPath: text("config_path").notNull(), |
| 18 | repoTokenCiphertext: bytes("repo_token_ciphertext"), |
| 19 | repoTokenKeyVersion: integer("repo_token_key_version"), |
| 20 | repoTokenNonce: bytes("repo_token_nonce"), |
| 21 | dispatchMode: text("dispatch_mode").notNull(), |
| 22 | executionRuntime: text("execution_runtime").notNull(), |
| 23 | createdAt: integer("created_at").notNull(), |
| 24 | updatedAt: integer("updated_at").notNull(), |
| 25 | }); |
| 26 | |
| 27 | export const projectRuns = sqliteTable( |
| 28 | "project_runs", |
| 29 | { |
| 30 | id: text("id").primaryKey(), |
| 31 | projectId: text("project_id").notNull(), |
| 32 | runId: text("run_id").notNull(), |
| 33 | triggerType: text("trigger_type").notNull(), |
| 34 | triggeredByUserId: text("triggered_by_user_id"), |
| 35 | branch: text("branch").notNull(), |
| 36 | commitSha: text("commit_sha"), |
| 37 | provider: text("provider"), |
| 38 | deliveryId: text("delivery_id"), |
| 39 | repoUrl: text("repo_url").notNull(), |
| 40 | configPath: text("config_path").notNull(), |
| 41 | position: integer("position"), |
| 42 | status: text("status").notNull(), |
| 43 | d1SyncStatus: text("d1_sync_status").notNull(), |
| 44 | dispatchMode: text("dispatch_mode").notNull(), |
| 45 | executionRuntime: text("execution_runtime").notNull(), |
| 46 | dispatchStatus: text("dispatch_status").notNull(), |
| 47 | dispatchAttempts: integer("dispatch_attempts").notNull(), |
| 48 | lastError: text("last_error"), |
| 49 | createdAt: integer("created_at").notNull(), |
| 50 | cancelRequestedAt: integer("cancel_requested_at"), |
| 51 | }, |
| 52 | (table) => [ |
| 53 | uniqueIndex("idx_project_runs_project_position").on(table.projectId, table.position), |
| 54 | index("idx_project_runs_project_status_position").on(table.projectId, table.status, table.position), |
| 55 | uniqueIndex("idx_project_runs_run_id").on(table.runId), |
| 56 | ], |
| 57 | ); |
| 58 | |
| 59 | export const projectWebhooks = sqliteTable( |
| 60 | "project_webhooks", |
| 61 | { |
| 62 | id: text("id").primaryKey(), |
| 63 | projectId: text("project_id").notNull(), |
| 64 | provider: text("provider").notNull(), |
| 65 | configJson: text("config_json"), |
| 66 | secretCiphertext: bytes("secret_ciphertext").notNull(), |
| 67 | secretKeyVersion: integer("secret_key_version").notNull(), |
| 68 | secretNonce: bytes("secret_nonce").notNull(), |
| 69 | enabled: integer("enabled").notNull(), |
| 70 | createdAt: integer("created_at").notNull(), |
| 71 | updatedAt: integer("updated_at").notNull(), |
| 72 | }, |
| 73 | (table) => [ |
| 74 | uniqueIndex("idx_project_webhooks_project_provider").on(table.projectId, table.provider), |
| 75 | index("idx_project_webhooks_provider_enabled").on(table.provider, table.enabled), |
| 76 | index("idx_project_webhooks_project_enabled").on(table.projectId, table.enabled), |
| 77 | ], |
| 78 | ); |
| 79 | |
| 80 | export const projectWebhookDeliveries = sqliteTable( |
| 81 | "project_webhook_deliveries", |
| 82 | { |
| 83 | id: text("id").primaryKey(), |
| 84 | projectId: text("project_id").notNull(), |
| 85 | provider: text("provider").notNull(), |
| 86 | deliveryId: text("delivery_id").notNull(), |
| 87 | eventKind: text("event_kind").notNull(), |
| 88 | eventName: text("event_name").notNull(), |
| 89 | outcome: text("outcome").notNull(), |
| 90 | repoUrl: text("repo_url").notNull(), |
| 91 | ref: text("ref"), |
| 92 | branch: text("branch"), |
| 93 | commitSha: text("commit_sha"), |
| 94 | beforeSha: text("before_sha"), |
| 95 | runId: text("run_id"), |
| 96 | receivedAt: integer("received_at").notNull(), |
| 97 | }, |
| 98 | (table) => [ |
| 99 | uniqueIndex("idx_project_webhook_deliveries_project_provider_delivery").on( |
| 100 | table.projectId, |
| 101 | table.provider, |
| 102 | table.deliveryId, |
| 103 | ), |
| 104 | index("idx_project_webhook_deliveries_project_received_at").on(table.projectId, table.receivedAt), |
| 105 | ], |
| 106 | ); |