import type { Context } from "../context.ts"; import type { PlanetScaleProps } from "./api.ts"; import { type DatabaseExtensions } from "./database-extensions.ts"; import { type PlanetScaleClusterSize } from "./utils.ts"; interface BaseDatabaseProps extends PlanetScaleProps { /** * The name of the database * * @default ${app}-${stage}-${id} */ name?: string; /** * The organization name where the database will be created * @default process.env.PLANETSCALE_ORGANIZATION */ organization?: string; /** * Whether to adopt the database if it already exists in Planetscale */ adopt?: boolean; /** * Whether to delete the database when the resource is destroyed. * When false, the database will only be removed from the state but not deleted via API. * @default true */ delete?: boolean; /** * The region where the database will be created (create only). * * @see https://planetscale.com/docs/concepts/regions */ region?: { /** * The slug identifier of the region (e.g. "us-east", "eu-west", "gcp-us-central1") * * @see https://planetscale.com/docs/concepts/regions#available-regions */ slug: string; }; /** * The number of replicas for the database. 0 for non-HA, 2+ for HA. (create only) */ replicas?: number; /** * The database cluster size (required) */ clusterSize: PlanetScaleClusterSize; /** * The engine kind for the database (create only) * @default "mysql" */ kind?: "mysql" | "postgresql"; /** * Whether or not deploy requests must be approved by a database administrator other than the request creator */ requireApprovalForDeploy?: boolean; /** * Whether or not to limit branch creation to the same region as the one selected during database creation. */ restrictBranchRegion?: boolean; /** * Whether or not full queries should be collected from the database */ insightsRawQueries?: boolean; /** * Whether or not the web console can be used on the production branch of the database */ productionBranchWebConsole?: boolean; /** * The default branch of the database * @default "main" */ defaultBranch?: string; } /** * Properties for creating or updating a PlanetScale MySQL database */ interface MySQLDatabaseProps extends BaseDatabaseProps { kind?: "mysql"; /** * Whether or not to copy migration data to new branches and in deploy requests. (Vitess only) */ automaticMigrations?: boolean; /** * A migration framework to use on the database. (Vitess only) */ migrationFramework?: string; /** * Name of table to use as migration table for the database. (Vitess only) */ migrationTableName?: string; /** * Whether or not data branching is allowed on the database. (Vitess only) */ allowDataBranching?: boolean; /** * Whether or not foreign key constraints are allowed on the database. (Vitess only) */ allowForeignKeyConstraints?: boolean; } /** * Properties for creating or updating a PlanetScale PostgreSQL database */ interface PostgreSQLDatabaseProps extends BaseDatabaseProps { kind: "postgresql"; /** * The PostgreSQL major version to use for the database. Defaults to the latest available major version. (PostgreSQL only) */ majorVersion?: string; /** * The CPU architecture for the database (PostgreSQL only) */ arch?: "x86" | "arm"; /** * PostgreSQL extensions to enable on the default branch. * Each key represents an extension — if present (even as `{}`), it is enabled with the given config or defaults. * If absent, the extension is disabled. (PostgreSQL only) * * @example * ```ts * const db = await Database("my-pg-db", { * kind: "postgresql", * organization: "my-org", * clusterSize: "PS_10", * extensions: { * vector: { hnswEfSearch: 100 }, * pgCron: {}, * pgStatStatements: { max: 10000 }, * }, * }); * ``` */ extensions?: DatabaseExtensions; } /** * Properties for creating or updating a PlanetScale Database */ export type DatabaseProps = MySQLDatabaseProps | PostgreSQLDatabaseProps; /** * Represents a PlanetScale Database */ export type Database = DatabaseProps & { /** * The unique identifier of the database */ id: string; /** * The name of the database */ name: string; /** * The current state of the database */ state: string; /** * The default branch name */ defaultBranch: string; /** * The plan type */ plan: string; /** * Time at which the database was created */ createdAt: string; /** * Time at which the database was last updated */ updatedAt: string; /** * HTML URL to access the database */ htmlUrl: string; /** * The organization of the database */ organization: string; /** * The region of the database as reported by PlanetScale. * * @see https://planetscale.com/docs/concepts/regions */ region: { /** * The slug identifier of the region (e.g. "us-east", "eu-west", "gcp-us-central1") * * @see https://planetscale.com/docs/concepts/regions#available-regions */ slug: string; }; }; /** * Create, manage and delete PlanetScale databases * * @example * // Create a basic database in a specific organization * const db = await Database("my-app-db", { * name: "my-app-db", * organization: "my-org", * clusterSize: "PS_10" * }); * * @example * // Create a database with specific region and settings * const db = await Database("my-app-db", { * name: "my-app-db", * organization: "my-org", * region: { * slug: "us-east" * }, * clusterSize: "PS_10", * requireApprovalForDeploy: true, * allowDataBranching: true, * automaticMigrations: true * }); * * @example * // Create a database with custom API key * const db = await Database("my-app-db", { * name: "my-app-db", * organization: "my-org", * apiKey: alchemy.secret(process.env.CUSTOM_PLANETSCALE_TOKEN), * clusterSize: "PS_10" * }); */ export declare const Database: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context, id: string, props: DatabaseProps) => Promise); export {}; //# sourceMappingURL=database.d.ts.map