@alchemy.run/planetscale 0.0.0 → 2.0.0-beta.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +83 -4
- package/lib/AuthProvider.d.ts +64 -0
- package/lib/AuthProvider.d.ts.map +1 -0
- package/lib/AuthProvider.js +395 -0
- package/lib/AuthProvider.js.map +1 -0
- package/lib/Branch.d.ts +128 -0
- package/lib/Branch.d.ts.map +1 -0
- package/lib/Branch.js +420 -0
- package/lib/Branch.js.map +1 -0
- package/lib/Contributions.d.ts +7 -0
- package/lib/Contributions.d.ts.map +1 -0
- package/lib/Contributions.js +6 -0
- package/lib/Contributions.js.map +1 -0
- package/lib/Credentials.d.ts +33 -0
- package/lib/Credentials.d.ts.map +1 -0
- package/lib/Credentials.js +59 -0
- package/lib/Credentials.js.map +1 -0
- package/lib/Database.d.ts +138 -0
- package/lib/Database.d.ts.map +1 -0
- package/lib/Database.js +1 -0
- package/lib/Database.js.map +1 -0
- package/lib/MySQL/MySQLBranch.d.ts +87 -0
- package/lib/MySQL/MySQLBranch.d.ts.map +1 -0
- package/lib/MySQL/MySQLBranch.js +15 -0
- package/lib/MySQL/MySQLBranch.js.map +1 -0
- package/lib/MySQL/MySQLClusterSize.d.ts +32 -0
- package/lib/MySQL/MySQLClusterSize.d.ts.map +1 -0
- package/lib/MySQL/MySQLClusterSize.js +111 -0
- package/lib/MySQL/MySQLClusterSize.js.map +1 -0
- package/lib/MySQL/MySQLDatabase.d.ts +141 -0
- package/lib/MySQL/MySQLDatabase.d.ts.map +1 -0
- package/lib/MySQL/MySQLDatabase.js +294 -0
- package/lib/MySQL/MySQLDatabase.js.map +1 -0
- package/lib/MySQL/MySQLMigrations.d.ts +20 -0
- package/lib/MySQL/MySQLMigrations.d.ts.map +1 -0
- package/lib/MySQL/MySQLMigrations.js +72 -0
- package/lib/MySQL/MySQLMigrations.js.map +1 -0
- package/lib/MySQL/MySQLOrigin.d.ts +15 -0
- package/lib/MySQL/MySQLOrigin.d.ts.map +1 -0
- package/lib/MySQL/MySQLOrigin.js +2 -0
- package/lib/MySQL/MySQLOrigin.js.map +1 -0
- package/lib/MySQL/MySQLPassword.d.ts +116 -0
- package/lib/MySQL/MySQLPassword.d.ts.map +1 -0
- package/lib/MySQL/MySQLPassword.js +212 -0
- package/lib/MySQL/MySQLPassword.js.map +1 -0
- package/lib/MySQL/index.d.ts +6 -0
- package/lib/MySQL/index.d.ts.map +1 -0
- package/lib/MySQL/index.js +6 -0
- package/lib/MySQL/index.js.map +1 -0
- package/lib/OAuthClient.d.ts +32 -0
- package/lib/OAuthClient.d.ts.map +1 -0
- package/lib/OAuthClient.js +52 -0
- package/lib/OAuthClient.js.map +1 -0
- package/lib/Postgres/PostgresBranch.d.ts +75 -0
- package/lib/Postgres/PostgresBranch.d.ts.map +1 -0
- package/lib/Postgres/PostgresBranch.js +15 -0
- package/lib/Postgres/PostgresBranch.js.map +1 -0
- package/lib/Postgres/PostgresClusterSize.d.ts +77 -0
- package/lib/Postgres/PostgresClusterSize.d.ts.map +1 -0
- package/lib/Postgres/PostgresClusterSize.js +89 -0
- package/lib/Postgres/PostgresClusterSize.js.map +1 -0
- package/lib/Postgres/PostgresDatabase.d.ts +95 -0
- package/lib/Postgres/PostgresDatabase.d.ts.map +1 -0
- package/lib/Postgres/PostgresDatabase.js +294 -0
- package/lib/Postgres/PostgresDatabase.js.map +1 -0
- package/lib/Postgres/PostgresDefaultRole.d.ts +94 -0
- package/lib/Postgres/PostgresDefaultRole.d.ts.map +1 -0
- package/lib/Postgres/PostgresDefaultRole.js +187 -0
- package/lib/Postgres/PostgresDefaultRole.js.map +1 -0
- package/lib/Postgres/PostgresMigrations.d.ts +16 -0
- package/lib/Postgres/PostgresMigrations.d.ts.map +1 -0
- package/lib/Postgres/PostgresMigrations.js +65 -0
- package/lib/Postgres/PostgresMigrations.js.map +1 -0
- package/lib/Postgres/PostgresOrigin.d.ts +15 -0
- package/lib/Postgres/PostgresOrigin.d.ts.map +1 -0
- package/lib/Postgres/PostgresOrigin.js +2 -0
- package/lib/Postgres/PostgresOrigin.js.map +1 -0
- package/lib/Postgres/PostgresRole.d.ts +142 -0
- package/lib/Postgres/PostgresRole.d.ts.map +1 -0
- package/lib/Postgres/PostgresRole.js +268 -0
- package/lib/Postgres/PostgresRole.js.map +1 -0
- package/lib/Postgres/index.d.ts +7 -0
- package/lib/Postgres/index.d.ts.map +1 -0
- package/lib/Postgres/index.js +7 -0
- package/lib/Postgres/index.js.map +1 -0
- package/lib/Providers.d.ts +24 -0
- package/lib/Providers.d.ts.map +1 -0
- package/lib/Providers.js +40 -0
- package/lib/Providers.js.map +1 -0
- package/lib/Util.d.ts +93 -0
- package/lib/Util.d.ts.map +1 -0
- package/lib/Util.js +135 -0
- package/lib/Util.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +9 -0
- package/lib/index.js.map +1 -0
- package/package.json +79 -3
- package/src/AuthProvider.ts +584 -0
- package/src/Branch.ts +657 -0
- package/src/Contributions.ts +9 -0
- package/src/Credentials.ts +92 -0
- package/src/Database.ts +152 -0
- package/src/MySQL/MySQLBranch.ts +109 -0
- package/src/MySQL/MySQLClusterSize.ts +185 -0
- package/src/MySQL/MySQLDatabase.ts +521 -0
- package/src/MySQL/MySQLMigrations.ts +133 -0
- package/src/MySQL/MySQLOrigin.ts +15 -0
- package/src/MySQL/MySQLPassword.ts +428 -0
- package/src/MySQL/index.ts +5 -0
- package/src/OAuthClient.ts +59 -0
- package/src/Postgres/PostgresBranch.ts +97 -0
- package/src/Postgres/PostgresClusterSize.ts +262 -0
- package/src/Postgres/PostgresDatabase.ts +469 -0
- package/src/Postgres/PostgresDefaultRole.ts +340 -0
- package/src/Postgres/PostgresMigrations.ts +122 -0
- package/src/Postgres/PostgresOrigin.ts +15 -0
- package/src/Postgres/PostgresRole.ts +547 -0
- package/src/Postgres/index.ts +6 -0
- package/src/Providers.ts +67 -0
- package/src/Util.ts +205 -0
- package/src/index.ts +14 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { MigrationsInput } from "@alchemy.run/sql/Migrations";
|
|
2
|
+
/**
|
|
3
|
+
* Region selector for a PlanetScale Database.
|
|
4
|
+
*/
|
|
5
|
+
export interface DatabaseRegion {
|
|
6
|
+
/**
|
|
7
|
+
* Region slug (e.g. `"us-east"`, `"eu-west"`, `"gcp-us-central1"`).
|
|
8
|
+
* @see https://planetscale.com/docs/concepts/regions#available-regions
|
|
9
|
+
*/
|
|
10
|
+
slug: "us-east" | "eu-west" | "gcp-us-central1" | (string & {});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Properties shared between {@link MySQLDatabase} and
|
|
14
|
+
* {@link PostgresDatabase}. Engine-specific props live on the per-engine
|
|
15
|
+
* resource types.
|
|
16
|
+
*/
|
|
17
|
+
export interface BaseDatabaseProps {
|
|
18
|
+
/**
|
|
19
|
+
* Database name. Must be lowercase. If omitted, a unique name will be
|
|
20
|
+
* generated from the stack/stage/logical-id. A change that replaces the
|
|
21
|
+
* database needs a new name, so it fails while an explicit name stays
|
|
22
|
+
* the same.
|
|
23
|
+
*/
|
|
24
|
+
name?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Region where the database will be created. Cannot be changed after
|
|
27
|
+
* creation. If omitted, the organization's default region is used.
|
|
28
|
+
*/
|
|
29
|
+
region?: DatabaseRegion;
|
|
30
|
+
/**
|
|
31
|
+
* Number of replicas for the database. `0` for non-HA, `2+` for HA.
|
|
32
|
+
* Create-only for PostgreSQL databases; MySQL databases reconcile
|
|
33
|
+
* changes in place ({@link MySQLDatabaseProps.replicas}).
|
|
34
|
+
*/
|
|
35
|
+
replicas?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Whether deploy requests must be approved by a database administrator
|
|
38
|
+
* other than the request creator.
|
|
39
|
+
*/
|
|
40
|
+
requireApprovalForDeploy?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to limit branch creation to the same region as the one
|
|
43
|
+
* selected during database creation.
|
|
44
|
+
*/
|
|
45
|
+
restrictBranchRegion?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the web console can be used on the production branch.
|
|
48
|
+
*/
|
|
49
|
+
productionBranchWebConsole?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether PlanetScale refuses to delete the database. While enabled,
|
|
52
|
+
* destroying or replacing the database fails with a
|
|
53
|
+
* `PlanetscaleDeletionProtected` error; set it to `false` and deploy
|
|
54
|
+
* before deleting. If omitted, Alchemy leaves the database's current
|
|
55
|
+
* setting unchanged.
|
|
56
|
+
*
|
|
57
|
+
* A replacement (e.g. a region change) creates the new database first,
|
|
58
|
+
* so deleting the protected old one fails afterwards. The resource then
|
|
59
|
+
* manages the new database, so turn protection off on the old one in
|
|
60
|
+
* PlanetScale directly and deploy again.
|
|
61
|
+
*/
|
|
62
|
+
deletionProtection?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The default branch of the database.
|
|
65
|
+
* @default "main"
|
|
66
|
+
*/
|
|
67
|
+
defaultBranch?: string;
|
|
68
|
+
/**
|
|
69
|
+
* SQL migrations to apply against the default branch. Accepts a directory
|
|
70
|
+
* path, a `Drizzle.Schema` resource, or `{ dir, table? }`.
|
|
71
|
+
*
|
|
72
|
+
* Bookkeeping always lives in Alchemy's `__alchemy_migrations` table. A
|
|
73
|
+
* database previously migrated by drizzle-kit or Prisma is adopted by a
|
|
74
|
+
* one-way conversion on first deploy: the old tool's applied history is
|
|
75
|
+
* copied into Alchemy's table and the old table is left frozen. No
|
|
76
|
+
* baselining required.
|
|
77
|
+
*/
|
|
78
|
+
migrations?: MigrationsInput;
|
|
79
|
+
/**
|
|
80
|
+
* Paths to additional `.sql` files to apply after migrations. Each file is
|
|
81
|
+
* hashed; only files whose contents change are re-applied on later deploys.
|
|
82
|
+
*/
|
|
83
|
+
importFiles?: string[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Output attributes shared by both database engines.
|
|
87
|
+
*/
|
|
88
|
+
export interface BaseDatabaseAttributes {
|
|
89
|
+
/** The unique identifier of the database. */
|
|
90
|
+
id: string;
|
|
91
|
+
/** The name of the database. */
|
|
92
|
+
name: string;
|
|
93
|
+
/** The PlanetScale organization slug that owns the database. */
|
|
94
|
+
organization: string;
|
|
95
|
+
/** The current state of the database. */
|
|
96
|
+
state: string;
|
|
97
|
+
/** The default branch name. */
|
|
98
|
+
defaultBranch: string;
|
|
99
|
+
/** The plan tier (e.g. `"hobby"`, `"scaler"`). */
|
|
100
|
+
plan: string;
|
|
101
|
+
/** Time at which the database was created (ISO 8601). */
|
|
102
|
+
createdAt: string;
|
|
103
|
+
/** Time at which the database was last updated (ISO 8601). */
|
|
104
|
+
updatedAt: string;
|
|
105
|
+
/** HTML URL for accessing the database in the dashboard. */
|
|
106
|
+
htmlUrl: string;
|
|
107
|
+
/** The region of the database as reported by PlanetScale. */
|
|
108
|
+
region: DatabaseRegion;
|
|
109
|
+
/** The cluster size that was actually applied. */
|
|
110
|
+
clusterSize: string;
|
|
111
|
+
/** Directory containing migration files, if configured. */
|
|
112
|
+
migrationsDir: string | undefined;
|
|
113
|
+
/** Table used to track applied migrations, if configured. */
|
|
114
|
+
migrationsTable: string | undefined;
|
|
115
|
+
/** Content hashes for the last applied migration files. */
|
|
116
|
+
migrationsHashes: Record<string, string>;
|
|
117
|
+
/** Content hashes for the last applied import files. */
|
|
118
|
+
importHashes: Record<string, string>;
|
|
119
|
+
/**
|
|
120
|
+
* Whether deploy requests must be approved by a database administrator
|
|
121
|
+
* other than the request creator.
|
|
122
|
+
*/
|
|
123
|
+
requireApprovalForDeploy: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Whether to limit branch creation to the same region as the one
|
|
126
|
+
* selected during database creation.
|
|
127
|
+
*/
|
|
128
|
+
restrictBranchRegion: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Whether the web console can be used on the production branch.
|
|
131
|
+
*/
|
|
132
|
+
productionBranchWebConsole: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Whether deletion protection is enabled for the database.
|
|
135
|
+
*/
|
|
136
|
+
deletionProtection: boolean;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=Database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../src/Database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,iBAAiB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;CACjE;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IAExB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,0BAA0B,CAAC,EAAE,OAAO,CAAC;IAErC;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;IAE7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,MAAM,EAAE,cAAc,CAAC;IACvB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,6DAA6D;IAC7D,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,2DAA2D;IAC3D,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC;;;OAGG;IACH,wBAAwB,EAAE,OAAO,CAAC;IAElC;;;OAGG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAE9B;;OAEG;IACH,0BAA0B,EAAE,OAAO,CAAC;IAEpC;;OAEG;IACH,kBAAkB,EAAE,OAAO,CAAC;CAC7B"}
|
package/lib/Database.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=Database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.js","sourceRoot":"","sources":["../src/Database.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Resource } from "alchemy/Resource";
|
|
2
|
+
import { type BaseBranchAttributes, type BaseBranchProps } from "../Branch.ts";
|
|
3
|
+
import type { Providers } from "../Providers.ts";
|
|
4
|
+
import type { MySQLClusterSize } from "./MySQLClusterSize.ts";
|
|
5
|
+
import type { MySQLDatabase } from "./MySQLDatabase.ts";
|
|
6
|
+
/**
|
|
7
|
+
* Properties for creating or updating a {@link MySQLBranch}.
|
|
8
|
+
*/
|
|
9
|
+
export interface MySQLBranchProps extends BaseBranchProps {
|
|
10
|
+
/**
|
|
11
|
+
* Whether the branch should be a production branch.
|
|
12
|
+
*/
|
|
13
|
+
isProduction: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The MySQL database. Either a string database name or a
|
|
16
|
+
* {@link MySQLDatabase} resource.
|
|
17
|
+
*/
|
|
18
|
+
database: string | MySQLDatabase;
|
|
19
|
+
/**
|
|
20
|
+
* MySQL cluster size for the branch. Required if `backupId` is provided.
|
|
21
|
+
* For non-production branches must be `"PS_DEV"`.
|
|
22
|
+
*/
|
|
23
|
+
clusterSize?: MySQLClusterSize;
|
|
24
|
+
/**
|
|
25
|
+
* Parent branch — either a string name or another {@link MySQLBranch}.
|
|
26
|
+
* @default "main"
|
|
27
|
+
*/
|
|
28
|
+
parentBranch?: string | MySQLBranch;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Output attributes of a deployed {@link MySQLBranch}.
|
|
32
|
+
*/
|
|
33
|
+
export interface MySQLBranchAttributes extends BaseBranchAttributes {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A PlanetScale branch of a {@link MySQLDatabase}. For PostgreSQL branches
|
|
37
|
+
* use {@link PostgresBranch} instead.
|
|
38
|
+
*
|
|
39
|
+
* ### Creating a Branch
|
|
40
|
+
* **Example:** Branch from main
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const branch = yield* Planetscale.MySQLBranch("Feature123", {
|
|
43
|
+
* database: "my-db",
|
|
44
|
+
* parentBranch: "main",
|
|
45
|
+
* isProduction: false,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* **Example:** Branch from a MySQLDatabase resource
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const db = yield* Planetscale.MySQLDatabase("MyDb", { clusterSize: "PS_10" });
|
|
52
|
+
* const branch = yield* Planetscale.MySQLBranch("Feature456", {
|
|
53
|
+
* database: db,
|
|
54
|
+
* parentBranch: "main",
|
|
55
|
+
* isProduction: false,
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* ### Restoring from Backup
|
|
60
|
+
* **Example:** Branch restored from a backup
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const branch = yield* Planetscale.MySQLBranch("Restored", {
|
|
63
|
+
* database: "my-db",
|
|
64
|
+
* parentBranch: "main",
|
|
65
|
+
* isProduction: true,
|
|
66
|
+
* backupId: "backup-123",
|
|
67
|
+
* clusterSize: "PS_10",
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* ### Migrations and seed data
|
|
72
|
+
* **Example:** Apply migrations on a branch
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const branch = yield* Planetscale.MySQLBranch("Feature123", {
|
|
75
|
+
* database: db,
|
|
76
|
+
* parentBranch: "main",
|
|
77
|
+
* isProduction: false,
|
|
78
|
+
* migrationsDir: "./migrations",
|
|
79
|
+
* importFiles: ["./seed.sql"],
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export type MySQLBranch = Resource<"Planetscale.MySQLBranch", MySQLBranchProps, MySQLBranchAttributes, never, Providers>;
|
|
84
|
+
/** @resource */
|
|
85
|
+
export declare const MySQLBranch: import("alchemy/Resource").ResourceClass<MySQLBranch>;
|
|
86
|
+
export declare const MySQLBranchProvider: () => import("effect/Layer").Layer<import("alchemy/Provider").Provider<MySQLBranch>, never, never>;
|
|
87
|
+
//# sourceMappingURL=MySQLBranch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MySQLBranch.d.ts","sourceRoot":"","sources":["../../src/MySQL/MySQLBranch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,eAAe,EAAsB,MAAM,cAAc,CAAC;AACnG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC;IAEjC;;;OAGG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB;CAAG;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAChC,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,EACL,SAAS,CACV,CAAC;AAEF,gBAAgB;AAChB,eAAO,MAAM,WAAW,uDAAmD,CAAC;AAE5E,eAAO,MAAM,mBAAmB,oGAS5B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Resource } from "alchemy/Resource";
|
|
2
|
+
import { makeBranchProvider } from "../Branch.js";
|
|
3
|
+
import { runMySQLImports, runMySQLMigrations } from "./MySQLMigrations.js";
|
|
4
|
+
/** @resource */
|
|
5
|
+
export const MySQLBranch = Resource("Planetscale.MySQLBranch");
|
|
6
|
+
export const MySQLBranchProvider = () => makeBranchProvider({
|
|
7
|
+
resource: MySQLBranch,
|
|
8
|
+
expectedKind: "mysql",
|
|
9
|
+
engineLabel: "MySQLBranch",
|
|
10
|
+
runners: {
|
|
11
|
+
runMigrations: runMySQLMigrations,
|
|
12
|
+
runImports: runMySQLImports,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=MySQLBranch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MySQLBranch.js","sourceRoot":"","sources":["../../src/MySQL/MySQLBranch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAmD,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAInG,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA2F3E,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAc,yBAAyB,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CACtC,kBAAkB,CAAC;IACjB,QAAQ,EAAE,WAAW;IACrB,YAAY,EAAE,OAAO;IACrB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE;QACP,aAAa,EAAE,kBAAkB;QACjC,UAAU,EAAE,eAAe;KAC5B;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as ps from "@distilled.cloud/planetscale";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { PlanetscaleConflict } from "../Util.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Available PlanetScale MySQL (Vitess) cluster sizes.
|
|
6
|
+
*
|
|
7
|
+
* `PS_*` sizes are backed by network-attached storage (NAS) and can be
|
|
8
|
+
* specified either as the short size (`"PS_10"`) or the API SKU
|
|
9
|
+
* (`"PS_10_AWS_X86"`)
|
|
10
|
+
*
|
|
11
|
+
* @see https://planetscale.com/docs/concepts/planetscale-skus
|
|
12
|
+
*/
|
|
13
|
+
export type MySQLClusterSize = "PS_DEV" | "PS_5" | "PS_10" | "PS_20" | "PS_40" | "PS_80" | "PS_160" | "PS_320" | "PS_400" | "PS_640" | "PS_700" | "PS_900" | "PS_1280" | "PS_1400" | "PS_1800" | "PS_2100" | "PS_2560" | "PS_2700" | "PS_2800" | (string & {});
|
|
14
|
+
/**
|
|
15
|
+
* Polls keyspaces in a branch until the named keyspace reports
|
|
16
|
+
* `resizing === false` (i.e. any in-flight resize has completed).
|
|
17
|
+
*/
|
|
18
|
+
export declare const waitForKeyspaceReady: (organization: string, database: string, branch: string, keyspace: string) => Effect.Effect<void, ps.ListKeyspacesError, ps.PlanetScaleOpContext>;
|
|
19
|
+
/**
|
|
20
|
+
* Observes the total replica count of a branch's default keyspace, or
|
|
21
|
+
* `undefined` when the branch or keyspace does not exist (yet).
|
|
22
|
+
*/
|
|
23
|
+
export declare const observeDefaultKeyspaceReplicas: (organization: string, database: string, branch: string) => Effect.Effect<number | undefined, ps.BadGateway | ps.BadRequest | ps.ConfigError | ps.Conflict | ps.Forbidden | ps.Services.planetscale.Forbidden | ps.GatewayTimeout | import("effect/http/HttpClientError").HttpClientError | ps.InternalServerError | import("@distilled.cloud/core/protocol-http").InvalidInput | ps.Locked | ps.PlanetScaleParseError | ps.ServiceUnavailable | ps.TooManyRequests | ps.Unauthorized | ps.UnknownPlanetScaleError | ps.UnprocessableEntity | ps.Services.planetscale.UnprocessableEntity, ps.PlanetScaleOpContext>;
|
|
24
|
+
/**
|
|
25
|
+
* Ensures the default keyspace of a MySQL production branch has the
|
|
26
|
+
* expected cluster size and (optionally) total replica count, driving
|
|
27
|
+
* PlanetScale's in-place keyspace resize lifecycle when it doesn't.
|
|
28
|
+
* Cluster sizes can only be configured on production branches. Returns
|
|
29
|
+
* the final observed keyspace.
|
|
30
|
+
*/
|
|
31
|
+
export declare const ensureMySQLProductionBranchClusterSize: (organization: string, database: string, branch: string, expectedClusterSize: MySQLClusterSize, expectedReplicas?: number | undefined) => Effect.Effect<ps.PaginatedDatabaseBranchKeyspaceDataItem, PlanetscaleConflict | ps.ListKeyspacesError, ps.PlanetScaleOpContext>;
|
|
32
|
+
//# sourceMappingURL=MySQLClusterSize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MySQLClusterSize.d.ts","sourceRoot":"","sources":["../../src/MySQL/MySQLClusterSize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,mBAAmB,EAAa,MAAM,YAAY,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB;;;GAGG;AACH,eAAO,MAAM,oBAAoB,mJAe/B,CAAC;AAuBH;;;GAGG;AACH,eAAO,MAAM,8BAA8B,qlBASzC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sCAAsC,2QAoFjD,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as ps from "@distilled.cloud/planetscale";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Schedule from "effect/Schedule";
|
|
4
|
+
import { PlanetscaleConflict, pollUntil } from "../Util.js";
|
|
5
|
+
/**
|
|
6
|
+
* Polls keyspaces in a branch until the named keyspace reports
|
|
7
|
+
* `resizing === false` (i.e. any in-flight resize has completed).
|
|
8
|
+
*/
|
|
9
|
+
export const waitForKeyspaceReady = Effect.fn(function* (organization, database, branch, keyspace) {
|
|
10
|
+
yield* pollUntil(`keyspace "${keyspace}" not resizing`, ps.listKeyspaces({ organization, database, branch }), (page) => {
|
|
11
|
+
const ks = page.data.find((x) => x.name === keyspace);
|
|
12
|
+
// If keyspace is missing, treat as ready (caller will re-check)
|
|
13
|
+
return ks ? !ks.resizing : true;
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Observes the default keyspace of a branch. The default keyspace usually
|
|
18
|
+
* shares the database's name, but a renamed database keeps its original
|
|
19
|
+
* keyspace name, so prefer the `default` flag and fall back to name
|
|
20
|
+
* matching.
|
|
21
|
+
*/
|
|
22
|
+
const observeDefaultKeyspace = Effect.fn(function* (organization, database, branch) {
|
|
23
|
+
const keyspaces = yield* ps.listKeyspaces({
|
|
24
|
+
organization,
|
|
25
|
+
database,
|
|
26
|
+
branch,
|
|
27
|
+
page: 1,
|
|
28
|
+
per_page: 100,
|
|
29
|
+
});
|
|
30
|
+
return keyspaces.data.find((x) => x.default) ?? keyspaces.data.find((x) => x.name === database);
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Observes the total replica count of a branch's default keyspace, or
|
|
34
|
+
* `undefined` when the branch or keyspace does not exist (yet).
|
|
35
|
+
*/
|
|
36
|
+
export const observeDefaultKeyspaceReplicas = Effect.fn(function* (organization, database, branch) {
|
|
37
|
+
return yield* observeDefaultKeyspace(organization, database, branch).pipe(Effect.map((keyspace) => keyspace?.replicas), Effect.catchTag("NotFound", () => Effect.undefined));
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Ensures the default keyspace of a MySQL production branch has the
|
|
41
|
+
* expected cluster size and (optionally) total replica count, driving
|
|
42
|
+
* PlanetScale's in-place keyspace resize lifecycle when it doesn't.
|
|
43
|
+
* Cluster sizes can only be configured on production branches. Returns
|
|
44
|
+
* the final observed keyspace.
|
|
45
|
+
*/
|
|
46
|
+
export const ensureMySQLProductionBranchClusterSize = Effect.fn(function* (organization, database, branch, expectedClusterSize, expectedReplicas) {
|
|
47
|
+
let keyspace = yield* observeDefaultKeyspace(organization, database, branch);
|
|
48
|
+
if (!keyspace) {
|
|
49
|
+
return yield* Effect.die(`No default keyspace found for branch ${branch}`);
|
|
50
|
+
}
|
|
51
|
+
yield* waitForKeyspaceReady(organization, database, branch, keyspace.name);
|
|
52
|
+
if (keyspace.cluster_name !== expectedClusterSize) {
|
|
53
|
+
yield* ps.updateBranchClusterConfig({
|
|
54
|
+
organization,
|
|
55
|
+
database,
|
|
56
|
+
branch,
|
|
57
|
+
cluster_size: expectedClusterSize,
|
|
58
|
+
});
|
|
59
|
+
yield* waitForKeyspaceReady(organization, database, branch, keyspace.name);
|
|
60
|
+
// Re-observe so the replica sync below diffs against the post-resize
|
|
61
|
+
// keyspace state.
|
|
62
|
+
keyspace = (yield* observeDefaultKeyspace(organization, database, branch)) ?? keyspace;
|
|
63
|
+
}
|
|
64
|
+
// Sync replicas — MySQL databases cannot configure replicas at
|
|
65
|
+
// creation time (the API rejects the `replicas` param for mysql), so
|
|
66
|
+
// the desired total replica count is converged in place via a keyspace
|
|
67
|
+
// resize request.
|
|
68
|
+
if (expectedReplicas !== undefined && keyspace.replicas !== expectedReplicas) {
|
|
69
|
+
// Each cluster size includes a fixed number of replicas (2 for
|
|
70
|
+
// production PS_* sizes); the resize API only accepts the count of
|
|
71
|
+
// additional replicas beyond that.
|
|
72
|
+
const includedReplicas = keyspace.replicas - keyspace.extra_replicas;
|
|
73
|
+
const extraReplicas = expectedReplicas - includedReplicas;
|
|
74
|
+
if (extraReplicas < 0) {
|
|
75
|
+
return yield* new PlanetscaleConflict({
|
|
76
|
+
message: `Cannot set replicas to ${expectedReplicas} on keyspace "${keyspace.name}": ` +
|
|
77
|
+
`cluster size ${keyspace.cluster_name} always includes ${includedReplicas} replicas. ` +
|
|
78
|
+
`Set replicas to ${includedReplicas} or more (or omit it).`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const resize = yield* ps
|
|
82
|
+
.updateKeyspaceResizeRequest({
|
|
83
|
+
organization,
|
|
84
|
+
database,
|
|
85
|
+
branch,
|
|
86
|
+
keyspace: keyspace.name,
|
|
87
|
+
extra_replicas: extraReplicas,
|
|
88
|
+
})
|
|
89
|
+
.pipe(
|
|
90
|
+
// A prior resize (e.g. the cluster-size change above) can still
|
|
91
|
+
// be finalizing after the keyspace reports `resizing: false`;
|
|
92
|
+
// PlanetScale rejects new resize requests during that window.
|
|
93
|
+
Effect.retry({
|
|
94
|
+
while: (e) => e._tag === "UnprocessableEntity" && e.message.includes("resize in progress"),
|
|
95
|
+
schedule: Schedule.max([Schedule.spaced("5 seconds"), Schedule.recurs(120)]),
|
|
96
|
+
}));
|
|
97
|
+
yield* pollUntil(`keyspace "${keyspace.name}" resize completed`, ps.listKeyspaceResizeRequests({
|
|
98
|
+
organization,
|
|
99
|
+
database,
|
|
100
|
+
branch,
|
|
101
|
+
keyspace: keyspace.name,
|
|
102
|
+
}), (page) => {
|
|
103
|
+
const request = page.data.find((r) => r.id === resize.id);
|
|
104
|
+
// If the request is missing, treat as settled (caller re-observes).
|
|
105
|
+
return request ? request.state === "completed" : true;
|
|
106
|
+
});
|
|
107
|
+
keyspace = (yield* observeDefaultKeyspace(organization, database, branch)) ?? keyspace;
|
|
108
|
+
}
|
|
109
|
+
return keyspace;
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=MySQLClusterSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MySQLClusterSize.js","sourceRoot":"","sources":["../../src/MySQL/MySQLClusterSize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiC5D;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EACrD,YAAoB,EACpB,QAAgB,EAChB,MAAc,EACd,QAAgB;IAEhB,KAAK,CAAC,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C,IAAI;SACxB,CAAC,EACF,CAAC,IAAI,EAAE,EAAE;YACP,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;YAC1D,oEAAoE;YACpE,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,CAAC,CACF,CAAC;QAEF,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,sBAAsB,CAAC,YAAY,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,QAAQ,CAAC;IACzF,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as planetscale from "@distilled.cloud/planetscale";
|
|
2
|
+
import * as Provider from "alchemy/Provider";
|
|
3
|
+
import { Resource } from "alchemy/Resource";
|
|
4
|
+
import type { BaseDatabaseAttributes, BaseDatabaseProps } from "../Database.ts";
|
|
5
|
+
import type { Providers } from "../Providers.ts";
|
|
6
|
+
import { type MySQLClusterSize } from "./MySQLClusterSize.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Properties for creating or updating a MySQL PlanetScale database.
|
|
9
|
+
*/
|
|
10
|
+
export interface MySQLDatabaseProps extends BaseDatabaseProps {
|
|
11
|
+
/**
|
|
12
|
+
* The MySQL database cluster size. Required.
|
|
13
|
+
* @see https://planetscale.com/docs/concepts/cluster-size
|
|
14
|
+
*/
|
|
15
|
+
clusterSize: MySQLClusterSize;
|
|
16
|
+
/**
|
|
17
|
+
* Desired total number of replicas for the database's default keyspace.
|
|
18
|
+
* Each cluster size includes a fixed number of replicas (2 for
|
|
19
|
+
* production `PS_*` sizes); higher values add extra replicas. Changes
|
|
20
|
+
* are reconciled in place via PlanetScale's keyspace resize lifecycle —
|
|
21
|
+
* never by replacing the database.
|
|
22
|
+
* @see https://planetscale.com/docs/vitess/sharding/keyspaces
|
|
23
|
+
*/
|
|
24
|
+
replicas?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to copy migration data to new branches and in deploy requests.
|
|
27
|
+
*/
|
|
28
|
+
automaticMigrations?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Migration framework to use on the database.
|
|
31
|
+
*/
|
|
32
|
+
migrationFramework?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Name of the migration table.
|
|
35
|
+
*/
|
|
36
|
+
migrationTableName?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether data branching is allowed on the database.
|
|
39
|
+
*/
|
|
40
|
+
allowDataBranching?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Whether foreign key constraints are allowed on the database.
|
|
43
|
+
*/
|
|
44
|
+
allowForeignKeyConstraints?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Whether full queries should be collected from the database.
|
|
47
|
+
*/
|
|
48
|
+
insightsRawQueries?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Output attributes of a deployed MySQL PlanetScale database.
|
|
52
|
+
*/
|
|
53
|
+
export interface MySQLDatabaseAttributes extends BaseDatabaseAttributes {
|
|
54
|
+
/**
|
|
55
|
+
* Observed total replica count of the default keyspace on the default
|
|
56
|
+
* branch, or `undefined` while the keyspace is still provisioning.
|
|
57
|
+
*/
|
|
58
|
+
replicas: number | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Whether to copy migration data to new branches and in deploy requests.
|
|
61
|
+
*/
|
|
62
|
+
automaticMigrations: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Migration framework to use on the database.
|
|
65
|
+
*/
|
|
66
|
+
migrationFramework?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Name of the migration table.
|
|
69
|
+
*/
|
|
70
|
+
migrationTableName?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether data branching is allowed on the database.
|
|
73
|
+
*/
|
|
74
|
+
allowDataBranching: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether foreign key constraints are allowed on the database.
|
|
77
|
+
*/
|
|
78
|
+
allowForeignKeyConstraints: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether full queries should be collected from the database.
|
|
81
|
+
*/
|
|
82
|
+
insightsRawQueries: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A MySQL PlanetScale database (powered by Vitess). For PostgreSQL use
|
|
86
|
+
* {@link PostgresDatabase} instead.
|
|
87
|
+
*
|
|
88
|
+
* ### Creating a MySQL Database
|
|
89
|
+
* **Example:** Basic MySQL database
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const db = yield* Planetscale.MySQLDatabase("MyDb", {
|
|
92
|
+
* clusterSize: "PS_10",
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* **Example:** MySQL with Vitess migration tooling
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const db = yield* Planetscale.MySQLDatabase("MyDb", {
|
|
99
|
+
* clusterSize: "PS_10",
|
|
100
|
+
* automaticMigrations: true,
|
|
101
|
+
* migrationFramework: "rails",
|
|
102
|
+
* migrationTableName: "schema_migrations",
|
|
103
|
+
* allowDataBranching: true,
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* ### Migrations and seed data
|
|
108
|
+
* **Example:** Apply migrations and seed files
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const db = yield* Planetscale.MySQLDatabase("MyDb", {
|
|
111
|
+
* clusterSize: "PS_10",
|
|
112
|
+
* migrationsDir: "./migrations/mysql",
|
|
113
|
+
* importFiles: ["./seed/mysql.sql"],
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* ### Deletion protection
|
|
118
|
+
* **Example:** Refuse deletes of a production database
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const db = yield* Planetscale.MySQLDatabase("MyDb", {
|
|
121
|
+
* clusterSize: "PS_10",
|
|
122
|
+
* deletionProtection: true,
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* ### Adoption
|
|
127
|
+
* **Example:** Adopting an existing database
|
|
128
|
+
* ```typescript
|
|
129
|
+
* import { adopt } from "alchemy/AdoptPolicy";
|
|
130
|
+
*
|
|
131
|
+
* const db = yield* Planetscale.MySQLDatabase("Existing", {
|
|
132
|
+
* name: "existing-db",
|
|
133
|
+
* clusterSize: "PS_10",
|
|
134
|
+
* }).pipe(adopt());
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export type MySQLDatabase = Resource<"Planetscale.MySQLDatabase", MySQLDatabaseProps, MySQLDatabaseAttributes, never, Providers>;
|
|
138
|
+
/** @resource */
|
|
139
|
+
export declare const MySQLDatabase: import("alchemy/Resource").ResourceClass<MySQLDatabase>;
|
|
140
|
+
export declare const MySQLDatabaseProvider: () => import("effect/Layer").Layer<Provider.Provider<MySQLDatabase>, never, import("effect/FileSystem").FileSystem | import("effect/Path").Path | import("alchemy/Stack").Stack | import("alchemy/Stage").Stage | planetscale.PlanetScaleOpContext>;
|
|
141
|
+
//# sourceMappingURL=MySQLDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MySQLDatabase.d.ts","sourceRoot":"","sources":["../../src/MySQL/MySQLDatabase.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,WAAW,MAAM,8BAA8B,CAAC;AAI5D,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQjD,OAAO,EAGL,KAAK,gBAAgB,EACtB,MA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