| 1 | import type { MigrationsInput } from "../SQL/Migrations/index.ts"; |
| 2 | |
| 3 | /** |
| 4 | * Region selector for a PlanetScale Database. |
| 5 | */ |
| 6 | export interface DatabaseRegion { |
| 7 | /** |
| 8 | * Region slug (e.g. `"us-east"`, `"eu-west"`, `"gcp-us-central1"`). |
| 9 | * @see https://planetscale.com/docs/concepts/regions#available-regions |
| 10 | */ |
| 11 | slug: "us-east" | "eu-west" | "gcp-us-central1" | (string & {}); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Properties shared between {@link MySQLDatabase} and |
| 16 | * {@link PostgresDatabase}. Engine-specific props live on the per-engine |
| 17 | * resource types. |
| 18 | */ |
| 19 | export interface BaseDatabaseProps { |
| 20 | /** |
| 21 | * Database name. Must be lowercase. If omitted, a unique name will be |
| 22 | * generated from the stack/stage/logical-id. |
| 23 | */ |
| 24 | name?: string; |
| 25 | |
| 26 | /** |
| 27 | * Region where the database will be created. Cannot be changed after |
| 28 | * creation. If omitted, the organization's default region is used. |
| 29 | */ |
| 30 | region?: DatabaseRegion; |
| 31 | |
| 32 | /** |
| 33 | * Number of replicas for the database. `0` for non-HA, `2+` for HA. |
| 34 | * Create-only for PostgreSQL databases; MySQL databases reconcile |
| 35 | * changes in place ({@link MySQLDatabaseProps.replicas}). |
| 36 | */ |
| 37 | replicas?: number; |
| 38 | |
| 39 | /** |
| 40 | * Whether deploy requests must be approved by a database administrator |
| 41 | * other than the request creator. |
| 42 | */ |
| 43 | requireApprovalForDeploy?: boolean; |
| 44 | |
| 45 | /** |
| 46 | * Whether to limit branch creation to the same region as the one |
| 47 | * selected during database creation. |
| 48 | */ |
| 49 | restrictBranchRegion?: boolean; |
| 50 | |
| 51 | /** |
| 52 | * Whether the web console can be used on the production branch. |
| 53 | */ |
| 54 | productionBranchWebConsole?: boolean; |
| 55 | |
| 56 | /** |
| 57 | * The default branch of the database. |
| 58 | * @default "main" |
| 59 | */ |
| 60 | defaultBranch?: string; |
| 61 | |
| 62 | /** |
| 63 | * SQL migrations to apply against the default branch. Accepts a directory |
| 64 | * path, a `Drizzle.Schema` resource, or `{ dir, table? }`. |
| 65 | * |
| 66 | * Bookkeeping always lives in Alchemy's `__alchemy_migrations` table. A |
| 67 | * database previously migrated by drizzle-kit or Prisma is adopted by a |
| 68 | * one-way conversion on first deploy: the old tool's applied history is |
| 69 | * copied into Alchemy's table and the old table is left frozen. No |
| 70 | * baselining required. |
| 71 | */ |
| 72 | migrations?: MigrationsInput; |
| 73 | |
| 74 | /** |
| 75 | * Paths to additional `.sql` files to apply after migrations. Each file is |
| 76 | * hashed; only files whose contents change are re-applied on later deploys. |
| 77 | */ |
| 78 | importFiles?: string[]; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Output attributes shared by both database engines. |
| 83 | */ |
| 84 | export interface BaseDatabaseAttributes { |
| 85 | /** The unique identifier of the database. */ |
| 86 | id: string; |
| 87 | /** The name of the database. */ |
| 88 | name: string; |
| 89 | /** The PlanetScale organization slug that owns the database. */ |
| 90 | organization: string; |
| 91 | /** The current state of the database. */ |
| 92 | state: string; |
| 93 | /** The default branch name. */ |
| 94 | defaultBranch: string; |
| 95 | /** The plan tier (e.g. `"hobby"`, `"scaler"`). */ |
| 96 | plan: string; |
| 97 | /** Time at which the database was created (ISO 8601). */ |
| 98 | createdAt: string; |
| 99 | /** Time at which the database was last updated (ISO 8601). */ |
| 100 | updatedAt: string; |
| 101 | /** HTML URL for accessing the database in the dashboard. */ |
| 102 | htmlUrl: string; |
| 103 | /** The region of the database as reported by PlanetScale. */ |
| 104 | region: DatabaseRegion; |
| 105 | /** The cluster size that was actually applied. */ |
| 106 | clusterSize: string; |
| 107 | /** Directory containing migration files, if configured. */ |
| 108 | migrationsDir: string | undefined; |
| 109 | /** Table used to track applied migrations, if configured. */ |
| 110 | migrationsTable: string | undefined; |
| 111 | /** Content hashes for the last applied migration files. */ |
| 112 | migrationsHashes: Record<string, string>; |
| 113 | /** Content hashes for the last applied import files. */ |
| 114 | importHashes: Record<string, string>; |
| 115 | /** |
| 116 | * Whether deploy requests must be approved by a database administrator |
| 117 | * other than the request creator. |
| 118 | */ |
| 119 | requireApprovalForDeploy: boolean; |
| 120 | |
| 121 | /** |
| 122 | * Whether to limit branch creation to the same region as the one |
| 123 | * selected during database creation. |
| 124 | */ |
| 125 | restrictBranchRegion: boolean; |
| 126 | |
| 127 | /** |
| 128 | * Whether the web console can be used on the production branch. |
| 129 | */ |
| 130 | productionBranchWebConsole: boolean; |
| 131 | } |