@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 109 lines 2.92 KB
Raw
1 import { Resource } from "alchemy/Resource";
2 import { type BaseBranchAttributes, type BaseBranchProps, makeBranchProvider } 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 import { runMySQLImports, runMySQLMigrations } from "./MySQLMigrations.ts";
7
8 /**
9 * Properties for creating or updating a {@link MySQLBranch}.
10 */
11 export interface MySQLBranchProps extends BaseBranchProps {
12 /**
13 * Whether the branch should be a production branch.
14 */
15 isProduction: boolean;
16
17 /**
18 * The MySQL database. Either a string database name or a
19 * {@link MySQLDatabase} resource.
20 */
21 database: string | MySQLDatabase;
22
23 /**
24 * MySQL cluster size for the branch. Required if `backupId` is provided.
25 * For non-production branches must be `"PS_DEV"`.
26 */
27 clusterSize?: MySQLClusterSize;
28
29 /**
30 * Parent branch — either a string name or another {@link MySQLBranch}.
31 * @default "main"
32 */
33 parentBranch?: string | MySQLBranch;
34 }
35
36 /**
37 * Output attributes of a deployed {@link MySQLBranch}.
38 */
39 export interface MySQLBranchAttributes extends BaseBranchAttributes {}
40
41 /**
42 * A PlanetScale branch of a {@link MySQLDatabase}. For PostgreSQL branches
43 * use {@link PostgresBranch} instead.
44 *
45 * ### Creating a Branch
46 * **Example:** Branch from main
47 * ```typescript
48 * const branch = yield* Planetscale.MySQLBranch("Feature123", {
49 * database: "my-db",
50 * parentBranch: "main",
51 * isProduction: false,
52 * });
53 * ```
54 *
55 * **Example:** Branch from a MySQLDatabase resource
56 * ```typescript
57 * const db = yield* Planetscale.MySQLDatabase("MyDb", { clusterSize: "PS_10" });
58 * const branch = yield* Planetscale.MySQLBranch("Feature456", {
59 * database: db,
60 * parentBranch: "main",
61 * isProduction: false,
62 * });
63 * ```
64 *
65 * ### Restoring from Backup
66 * **Example:** Branch restored from a backup
67 * ```typescript
68 * const branch = yield* Planetscale.MySQLBranch("Restored", {
69 * database: "my-db",
70 * parentBranch: "main",
71 * isProduction: true,
72 * backupId: "backup-123",
73 * clusterSize: "PS_10",
74 * });
75 * ```
76 *
77 * ### Migrations and seed data
78 * **Example:** Apply migrations on a branch
79 * ```typescript
80 * const branch = yield* Planetscale.MySQLBranch("Feature123", {
81 * database: db,
82 * parentBranch: "main",
83 * isProduction: false,
84 * migrationsDir: "./migrations",
85 * importFiles: ["./seed.sql"],
86 * });
87 * ```
88 */
89 export type MySQLBranch = Resource<
90 "Planetscale.MySQLBranch",
91 MySQLBranchProps,
92 MySQLBranchAttributes,
93 never,
94 Providers
95 >;
96
97 /** @resource */
98 export const MySQLBranch = Resource<MySQLBranch>("Planetscale.MySQLBranch");
99
100 export const MySQLBranchProvider = () =>
101 makeBranchProvider({
102 resource: MySQLBranch,
103 expectedKind: "mysql",
104 engineLabel: "MySQLBranch",
105 runners: {
106 runMigrations: runMySQLMigrations,
107 runImports: runMySQLImports,
108 },
109 });