@buenojs/bueno 0.8.4 → 0.8.6
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/README.md +264 -17
- package/dist/cli/{index.js → bin.js} +413 -332
- package/dist/container/index.js +273 -0
- package/dist/context/index.js +219 -0
- package/dist/database/index.js +493 -0
- package/dist/frontend/index.js +7697 -0
- package/dist/graphql/index.js +2156 -0
- package/dist/health/index.js +364 -0
- package/dist/i18n/index.js +345 -0
- package/dist/index.js +9694 -5047
- package/dist/jobs/index.js +819 -0
- package/dist/lock/index.js +367 -0
- package/dist/logger/index.js +281 -0
- package/dist/metrics/index.js +289 -0
- package/dist/middleware/index.js +77 -0
- package/dist/migrations/index.js +571 -0
- package/dist/modules/index.js +3411 -0
- package/dist/notification/index.js +484 -0
- package/dist/observability/index.js +331 -0
- package/dist/openapi/index.js +795 -0
- package/dist/orm/index.js +1356 -0
- package/dist/router/index.js +886 -0
- package/dist/rpc/index.js +691 -0
- package/dist/schema/index.js +400 -0
- package/dist/telemetry/index.js +595 -0
- package/dist/template/index.js +640 -0
- package/dist/templates/index.js +640 -0
- package/dist/testing/index.js +1111 -0
- package/dist/types/index.js +60 -0
- package/llms.txt +231 -0
- package/package.json +125 -27
- package/src/cache/index.ts +2 -1
- package/src/cli/ARCHITECTURE.md +3 -3
- package/src/cli/bin.ts +2 -2
- package/src/cli/commands/build.ts +183 -165
- package/src/cli/commands/dev.ts +96 -89
- package/src/cli/commands/generate.ts +142 -111
- package/src/cli/commands/help.ts +20 -16
- package/src/cli/commands/index.ts +3 -6
- package/src/cli/commands/migration.ts +124 -105
- package/src/cli/commands/new.ts +294 -232
- package/src/cli/commands/start.ts +81 -79
- package/src/cli/core/args.ts +68 -50
- package/src/cli/core/console.ts +89 -95
- package/src/cli/core/index.ts +4 -4
- package/src/cli/core/prompt.ts +65 -62
- package/src/cli/core/spinner.ts +23 -20
- package/src/cli/index.ts +46 -38
- package/src/cli/templates/database/index.ts +37 -18
- package/src/cli/templates/database/mysql.ts +3 -3
- package/src/cli/templates/database/none.ts +2 -2
- package/src/cli/templates/database/postgresql.ts +3 -3
- package/src/cli/templates/database/sqlite.ts +3 -3
- package/src/cli/templates/deploy.ts +29 -26
- package/src/cli/templates/docker.ts +41 -30
- package/src/cli/templates/frontend/index.ts +33 -15
- package/src/cli/templates/frontend/none.ts +2 -2
- package/src/cli/templates/frontend/react.ts +18 -18
- package/src/cli/templates/frontend/solid.ts +15 -15
- package/src/cli/templates/frontend/svelte.ts +17 -17
- package/src/cli/templates/frontend/vue.ts +15 -15
- package/src/cli/templates/generators/index.ts +29 -29
- package/src/cli/templates/generators/types.ts +21 -21
- package/src/cli/templates/index.ts +6 -6
- package/src/cli/templates/project/api.ts +37 -36
- package/src/cli/templates/project/default.ts +25 -25
- package/src/cli/templates/project/fullstack.ts +28 -26
- package/src/cli/templates/project/index.ts +55 -16
- package/src/cli/templates/project/minimal.ts +17 -12
- package/src/cli/templates/project/types.ts +10 -5
- package/src/cli/templates/project/website.ts +15 -15
- package/src/cli/utils/fs.ts +55 -41
- package/src/cli/utils/index.ts +3 -3
- package/src/cli/utils/strings.ts +47 -33
- package/src/cli/utils/version.ts +14 -8
- package/src/config/env-validation.ts +100 -0
- package/src/config/env.ts +169 -41
- package/src/config/index.ts +28 -20
- package/src/config/loader.ts +25 -16
- package/src/config/merge.ts +21 -10
- package/src/config/types.ts +566 -25
- package/src/config/validation.ts +215 -7
- package/src/container/forward-ref.ts +22 -22
- package/src/container/index.ts +34 -12
- package/src/context/index.ts +11 -1
- package/src/database/index.ts +7 -190
- package/src/database/orm/builder.ts +457 -0
- package/src/database/orm/casts/index.ts +130 -0
- package/src/database/orm/casts/types.ts +25 -0
- package/src/database/orm/compiler.ts +304 -0
- package/src/database/orm/hooks/index.ts +114 -0
- package/src/database/orm/index.ts +61 -0
- package/src/database/orm/model-registry.ts +59 -0
- package/src/database/orm/model.ts +821 -0
- package/src/database/orm/relationships/base.ts +146 -0
- package/src/database/orm/relationships/belongs-to-many.ts +179 -0
- package/src/database/orm/relationships/belongs-to.ts +56 -0
- package/src/database/orm/relationships/has-many.ts +45 -0
- package/src/database/orm/relationships/has-one.ts +41 -0
- package/src/database/orm/relationships/index.ts +11 -0
- package/src/database/orm/scopes/index.ts +55 -0
- package/src/events/__tests__/event-system.test.ts +235 -0
- package/src/events/config.ts +238 -0
- package/src/events/example-usage.ts +185 -0
- package/src/events/index.ts +278 -0
- package/src/events/manager.ts +385 -0
- package/src/events/registry.ts +182 -0
- package/src/events/types.ts +124 -0
- package/src/frontend/api-routes.ts +65 -23
- package/src/frontend/bundler.ts +76 -34
- package/src/frontend/console-client.ts +2 -2
- package/src/frontend/console-stream.ts +94 -38
- package/src/frontend/dev-server.ts +94 -46
- package/src/frontend/file-router.ts +61 -19
- package/src/frontend/frameworks/index.ts +37 -10
- package/src/frontend/frameworks/react.ts +10 -8
- package/src/frontend/frameworks/solid.ts +11 -9
- package/src/frontend/frameworks/svelte.ts +15 -9
- package/src/frontend/frameworks/vue.ts +13 -11
- package/src/frontend/hmr-client.ts +12 -10
- package/src/frontend/hmr.ts +146 -103
- package/src/frontend/index.ts +14 -5
- package/src/frontend/islands.ts +41 -22
- package/src/frontend/isr.ts +59 -37
- package/src/frontend/layout.ts +36 -21
- package/src/frontend/ssr/react.ts +74 -27
- package/src/frontend/ssr/solid.ts +54 -20
- package/src/frontend/ssr/svelte.ts +48 -14
- package/src/frontend/ssr/vue.ts +50 -18
- package/src/frontend/ssr.ts +83 -39
- package/src/frontend/types.ts +91 -56
- package/src/graphql/built-in-engine.ts +598 -0
- package/src/graphql/context-builder.ts +110 -0
- package/src/graphql/decorators.ts +358 -0
- package/src/graphql/execution-pipeline.ts +227 -0
- package/src/graphql/graphql-module.ts +563 -0
- package/src/graphql/index.ts +101 -0
- package/src/graphql/metadata.ts +237 -0
- package/src/graphql/schema-builder.ts +319 -0
- package/src/graphql/subscription-handler.ts +283 -0
- package/src/graphql/types.ts +324 -0
- package/src/health/index.ts +21 -9
- package/src/i18n/engine.ts +305 -0
- package/src/i18n/index.ts +38 -0
- package/src/i18n/loader.ts +218 -0
- package/src/i18n/middleware.ts +164 -0
- package/src/i18n/negotiator.ts +162 -0
- package/src/i18n/types.ts +158 -0
- package/src/index.ts +182 -27
- package/src/jobs/drivers/memory.ts +315 -0
- package/src/jobs/drivers/redis.ts +459 -0
- package/src/jobs/index.ts +30 -0
- package/src/jobs/queue.ts +281 -0
- package/src/jobs/types.ts +295 -0
- package/src/jobs/worker.ts +380 -0
- package/src/logger/index.ts +1 -3
- package/src/logger/transports/index.ts +62 -22
- package/src/metrics/index.ts +25 -16
- package/src/migrations/index.ts +9 -0
- package/src/modules/filters.ts +13 -17
- package/src/modules/guards.ts +49 -26
- package/src/modules/index.ts +457 -299
- package/src/modules/interceptors.ts +58 -20
- package/src/modules/lazy.ts +11 -19
- package/src/modules/lifecycle.ts +15 -7
- package/src/modules/metadata.ts +15 -5
- package/src/modules/pipes.ts +94 -72
- package/src/notification/channels/base.ts +68 -0
- package/src/notification/channels/email.ts +105 -0
- package/src/notification/channels/push.ts +104 -0
- package/src/notification/channels/sms.ts +105 -0
- package/src/notification/channels/whatsapp.ts +104 -0
- package/src/notification/index.ts +48 -0
- package/src/notification/service.ts +354 -0
- package/src/notification/types.ts +344 -0
- package/src/observability/__tests__/observability.test.ts +483 -0
- package/src/observability/breadcrumbs.ts +114 -0
- package/src/observability/index.ts +136 -0
- package/src/observability/interceptor.ts +85 -0
- package/src/observability/service.ts +303 -0
- package/src/observability/trace.ts +37 -0
- package/src/observability/types.ts +196 -0
- package/src/openapi/__tests__/decorators.test.ts +335 -0
- package/src/openapi/__tests__/document-builder.test.ts +285 -0
- package/src/openapi/__tests__/route-scanner.test.ts +334 -0
- package/src/openapi/__tests__/schema-generator.test.ts +275 -0
- package/src/openapi/decorators.ts +328 -0
- package/src/openapi/document-builder.ts +274 -0
- package/src/openapi/index.ts +112 -0
- package/src/openapi/metadata.ts +112 -0
- package/src/openapi/route-scanner.ts +289 -0
- package/src/openapi/schema-generator.ts +256 -0
- package/src/openapi/swagger-module.ts +166 -0
- package/src/openapi/types.ts +398 -0
- package/src/orm/index.ts +10 -0
- package/src/rpc/index.ts +3 -1
- package/src/schema/index.ts +9 -0
- package/src/security/index.ts +15 -6
- package/src/ssg/index.ts +9 -8
- package/src/telemetry/index.ts +76 -22
- package/src/template/index.ts +7 -0
- package/src/templates/engine.ts +224 -0
- package/src/templates/index.ts +9 -0
- package/src/templates/loader.ts +331 -0
- package/src/templates/renderers/markdown.ts +212 -0
- package/src/templates/renderers/simple.ts +269 -0
- package/src/templates/types.ts +154 -0
- package/src/testing/index.ts +100 -27
- package/src/types/optional-deps.d.ts +347 -187
- package/src/validation/index.ts +92 -2
- package/src/validation/schemas.ts +536 -0
- package/tests/integration/cli.test.ts +19 -19
- package/tests/integration/fullstack.test.ts +4 -4
- package/tests/unit/cli.test.ts +1 -1
- package/tests/unit/database.test.ts +2 -72
- package/tests/unit/env-validation.test.ts +166 -0
- package/tests/unit/events.test.ts +910 -0
- package/tests/unit/graphql.test.ts +991 -0
- package/tests/unit/i18n.test.ts +455 -0
- package/tests/unit/jobs.test.ts +493 -0
- package/tests/unit/notification.test.ts +988 -0
- package/tests/unit/observability.test.ts +453 -0
- package/tests/unit/orm/builder.test.ts +323 -0
- package/tests/unit/orm/casts.test.ts +179 -0
- package/tests/unit/orm/compiler.test.ts +220 -0
- package/tests/unit/orm/eager-loading.test.ts +285 -0
- package/tests/unit/orm/hooks.test.ts +191 -0
- package/tests/unit/orm/model.test.ts +373 -0
- package/tests/unit/orm/relationships.test.ts +303 -0
- package/tests/unit/orm/scopes.test.ts +74 -0
- package/tests/unit/templates-simple.test.ts +53 -0
- package/tests/unit/templates.test.ts +454 -0
- package/tests/unit/validation.test.ts +18 -24
- package/tsconfig.json +11 -3
|
@@ -4,25 +4,31 @@
|
|
|
4
4
|
* Manage database migrations
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { type ParsedArgs, getOption, hasFlag } from "../core/args";
|
|
8
|
+
import { cliConsole, colors, printTable } from "../core/console";
|
|
9
|
+
import { spinner } from "../core/spinner";
|
|
10
|
+
import { CLIError, CLIErrorType } from "../index";
|
|
11
11
|
import {
|
|
12
12
|
fileExists,
|
|
13
|
-
readFile,
|
|
14
|
-
writeFile,
|
|
15
|
-
listFiles,
|
|
16
13
|
getProjectRoot,
|
|
17
14
|
isBuenoProject,
|
|
18
15
|
joinPaths,
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
listFiles,
|
|
17
|
+
readFile,
|
|
18
|
+
writeFile,
|
|
19
|
+
} from "../utils/fs";
|
|
20
|
+
import { defineCommand } from "./index";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Migration actions
|
|
24
24
|
*/
|
|
25
|
-
type MigrationAction =
|
|
25
|
+
type MigrationAction =
|
|
26
|
+
| "create"
|
|
27
|
+
| "up"
|
|
28
|
+
| "down"
|
|
29
|
+
| "reset"
|
|
30
|
+
| "refresh"
|
|
31
|
+
| "status";
|
|
26
32
|
|
|
27
33
|
/**
|
|
28
34
|
* Generate migration ID
|
|
@@ -30,11 +36,11 @@ type MigrationAction = 'create' | 'up' | 'down' | 'reset' | 'refresh' | 'status'
|
|
|
30
36
|
function generateMigrationId(): string {
|
|
31
37
|
const now = new Date();
|
|
32
38
|
const year = now.getFullYear();
|
|
33
|
-
const month = String(now.getMonth() + 1).padStart(2,
|
|
34
|
-
const day = String(now.getDate()).padStart(2,
|
|
35
|
-
const hour = String(now.getHours()).padStart(2,
|
|
36
|
-
const minute = String(now.getMinutes()).padStart(2,
|
|
37
|
-
const second = String(now.getSeconds()).padStart(2,
|
|
39
|
+
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
40
|
+
const day = String(now.getDate()).padStart(2, "0");
|
|
41
|
+
const hour = String(now.getHours()).padStart(2, "0");
|
|
42
|
+
const minute = String(now.getMinutes()).padStart(2, "0");
|
|
43
|
+
const second = String(now.getSeconds()).padStart(2, "0");
|
|
38
44
|
return `${year}${month}${day}${hour}${minute}${second}`;
|
|
39
45
|
}
|
|
40
46
|
|
|
@@ -44,17 +50,14 @@ function generateMigrationId(): string {
|
|
|
44
50
|
async function getMigrationsDir(): Promise<string> {
|
|
45
51
|
const projectRoot = await getProjectRoot();
|
|
46
52
|
if (!projectRoot) {
|
|
47
|
-
throw new CLIError(
|
|
48
|
-
'Not in a project directory',
|
|
49
|
-
CLIErrorType.NOT_FOUND,
|
|
50
|
-
);
|
|
53
|
+
throw new CLIError("Not in a project directory", CLIErrorType.NOT_FOUND);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
// Check common locations
|
|
54
57
|
const possibleDirs = [
|
|
55
|
-
joinPaths(projectRoot,
|
|
56
|
-
joinPaths(projectRoot,
|
|
57
|
-
joinPaths(projectRoot,
|
|
58
|
+
joinPaths(projectRoot, "server", "database", "migrations"),
|
|
59
|
+
joinPaths(projectRoot, "database", "migrations"),
|
|
60
|
+
joinPaths(projectRoot, "migrations"),
|
|
58
61
|
];
|
|
59
62
|
|
|
60
63
|
for (const dir of possibleDirs) {
|
|
@@ -64,14 +67,14 @@ async function getMigrationsDir(): Promise<string> {
|
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
// Default to server/database/migrations
|
|
67
|
-
return possibleDirs[0] ??
|
|
70
|
+
return possibleDirs[0] ?? "";
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
74
|
* Get migration files
|
|
72
75
|
*/
|
|
73
76
|
async function getMigrationFiles(dir: string): Promise<string[]> {
|
|
74
|
-
if (!await fileExists(dir)) {
|
|
77
|
+
if (!(await fileExists(dir))) {
|
|
75
78
|
return [];
|
|
76
79
|
}
|
|
77
80
|
|
|
@@ -100,11 +103,11 @@ function parseMigrationFile(filename: string): { id: string; name: string } {
|
|
|
100
103
|
async function createMigration(name: string, dryRun: boolean): Promise<string> {
|
|
101
104
|
const migrationsDir = await getMigrationsDir();
|
|
102
105
|
const id = generateMigrationId();
|
|
103
|
-
const kebabName = name.toLowerCase().replace(/\s+/g,
|
|
106
|
+
const kebabName = name.toLowerCase().replace(/\s+/g, "-");
|
|
104
107
|
const fileName = `${id}_${kebabName}.ts`;
|
|
105
108
|
const filePath = joinPaths(migrationsDir, fileName);
|
|
106
109
|
|
|
107
|
-
const template = `import { createMigration, type MigrationRunner } from '@buenojs/bueno';
|
|
110
|
+
const template = `import { createMigration, type MigrationRunner } from '@buenojs/bueno/migrations';
|
|
108
111
|
|
|
109
112
|
export default createMigration('${id}', '${kebabName}')
|
|
110
113
|
.up(async (db: MigrationRunner) => {
|
|
@@ -126,10 +129,10 @@ export default createMigration('${id}', '${kebabName}')
|
|
|
126
129
|
`;
|
|
127
130
|
|
|
128
131
|
if (dryRun) {
|
|
129
|
-
cliConsole.log(`\n${colors.bold(
|
|
130
|
-
cliConsole.log(colors.bold(
|
|
132
|
+
cliConsole.log(`\n${colors.bold("File:")} ${filePath}`);
|
|
133
|
+
cliConsole.log(colors.bold("Content:"));
|
|
131
134
|
cliConsole.log(template);
|
|
132
|
-
cliConsole.log(
|
|
135
|
+
cliConsole.log("");
|
|
133
136
|
return filePath;
|
|
134
137
|
}
|
|
135
138
|
|
|
@@ -145,19 +148,19 @@ async function showStatus(): Promise<void> {
|
|
|
145
148
|
const files = await getMigrationFiles(migrationsDir);
|
|
146
149
|
|
|
147
150
|
if (files.length === 0) {
|
|
148
|
-
cliConsole.info(
|
|
151
|
+
cliConsole.info("No migrations found");
|
|
149
152
|
return;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
cliConsole.header(
|
|
155
|
+
cliConsole.header("Migration Status");
|
|
153
156
|
|
|
154
157
|
const rows = files.map((file) => {
|
|
155
|
-
const info = parseMigrationFile(file.split(
|
|
156
|
-
return [info.id, info.name, colors.yellow(
|
|
158
|
+
const info = parseMigrationFile(file.split("/").pop() ?? "");
|
|
159
|
+
return [info.id, info.name, colors.yellow("Pending")];
|
|
157
160
|
});
|
|
158
161
|
|
|
159
|
-
printTable([
|
|
160
|
-
cliConsole.log(
|
|
162
|
+
printTable(["ID", "Name", "Status"], rows);
|
|
163
|
+
cliConsole.log("");
|
|
161
164
|
cliConsole.log(`Total: ${files.length} migration(s)`);
|
|
162
165
|
}
|
|
163
166
|
|
|
@@ -169,45 +172,52 @@ async function handleMigration(args: ParsedArgs): Promise<void> {
|
|
|
169
172
|
const action = args.positionals[0] as MigrationAction | undefined;
|
|
170
173
|
if (!action) {
|
|
171
174
|
throw new CLIError(
|
|
172
|
-
|
|
175
|
+
"Action is required. Usage: bueno migration <action>",
|
|
173
176
|
CLIErrorType.INVALID_ARGS,
|
|
174
177
|
);
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
const validActions: MigrationAction[] = [
|
|
180
|
+
const validActions: MigrationAction[] = [
|
|
181
|
+
"create",
|
|
182
|
+
"up",
|
|
183
|
+
"down",
|
|
184
|
+
"reset",
|
|
185
|
+
"refresh",
|
|
186
|
+
"status",
|
|
187
|
+
];
|
|
178
188
|
if (!validActions.includes(action)) {
|
|
179
189
|
throw new CLIError(
|
|
180
|
-
`Unknown action: ${action}. Valid actions: ${validActions.join(
|
|
190
|
+
`Unknown action: ${action}. Valid actions: ${validActions.join(", ")}`,
|
|
181
191
|
CLIErrorType.INVALID_ARGS,
|
|
182
192
|
);
|
|
183
193
|
}
|
|
184
194
|
|
|
185
195
|
// Get options
|
|
186
|
-
const dryRun = hasFlag(args,
|
|
187
|
-
const steps = getOption(args,
|
|
188
|
-
name:
|
|
189
|
-
alias:
|
|
190
|
-
type:
|
|
196
|
+
const dryRun = hasFlag(args, "dry-run");
|
|
197
|
+
const steps = getOption(args, "steps", {
|
|
198
|
+
name: "steps",
|
|
199
|
+
alias: "n",
|
|
200
|
+
type: "number",
|
|
191
201
|
default: 1,
|
|
192
|
-
description:
|
|
202
|
+
description: "",
|
|
193
203
|
});
|
|
194
204
|
|
|
195
205
|
// Check if in a Bueno project (except for create with dry-run)
|
|
196
|
-
if (action !==
|
|
206
|
+
if (action !== "create" || !dryRun) {
|
|
197
207
|
if (!(await isBuenoProject())) {
|
|
198
208
|
throw new CLIError(
|
|
199
|
-
|
|
209
|
+
"Not in a Bueno project directory. Run this command from a Bueno project.",
|
|
200
210
|
CLIErrorType.NOT_FOUND,
|
|
201
211
|
);
|
|
202
212
|
}
|
|
203
213
|
}
|
|
204
214
|
|
|
205
215
|
switch (action) {
|
|
206
|
-
case
|
|
216
|
+
case "create": {
|
|
207
217
|
const name = args.positionals[1];
|
|
208
218
|
if (!name) {
|
|
209
219
|
throw new CLIError(
|
|
210
|
-
|
|
220
|
+
"Migration name is required. Usage: bueno migration create <name>",
|
|
211
221
|
CLIErrorType.INVALID_ARGS,
|
|
212
222
|
);
|
|
213
223
|
}
|
|
@@ -216,7 +226,7 @@ async function handleMigration(args: ParsedArgs): Promise<void> {
|
|
|
216
226
|
try {
|
|
217
227
|
const filePath = await createMigration(name, dryRun);
|
|
218
228
|
if (dryRun) {
|
|
219
|
-
s.info(
|
|
229
|
+
s.info("Dry run complete");
|
|
220
230
|
} else {
|
|
221
231
|
s.success(`Created ${colors.green(filePath)}`);
|
|
222
232
|
}
|
|
@@ -227,83 +237,91 @@ async function handleMigration(args: ParsedArgs): Promise<void> {
|
|
|
227
237
|
break;
|
|
228
238
|
}
|
|
229
239
|
|
|
230
|
-
case
|
|
231
|
-
cliConsole.info(
|
|
232
|
-
cliConsole.log(
|
|
240
|
+
case "up": {
|
|
241
|
+
cliConsole.info("Running pending migrations...");
|
|
242
|
+
cliConsole.log("");
|
|
233
243
|
cliConsole.warn(
|
|
234
|
-
|
|
244
|
+
"Migration execution requires database connection. Use the MigrationRunner in your application code.",
|
|
235
245
|
);
|
|
236
|
-
cliConsole.log(
|
|
237
|
-
cliConsole.log(
|
|
238
|
-
cliConsole.log(
|
|
239
|
-
|
|
246
|
+
cliConsole.log("");
|
|
247
|
+
cliConsole.log("Example:");
|
|
248
|
+
cliConsole.log(
|
|
249
|
+
colors.cyan(`
|
|
250
|
+
import { createMigrationRunner, loadMigrations } from '@buenojs/bueno/migrations';
|
|
240
251
|
import { db } from './database';
|
|
241
252
|
|
|
242
253
|
const runner = createMigrationRunner(db);
|
|
243
254
|
const migrations = await loadMigrations('./database/migrations');
|
|
244
255
|
await runner.migrate(migrations);
|
|
245
|
-
`)
|
|
256
|
+
`),
|
|
257
|
+
);
|
|
246
258
|
break;
|
|
247
259
|
}
|
|
248
260
|
|
|
249
|
-
case
|
|
261
|
+
case "down": {
|
|
250
262
|
cliConsole.info(`Rolling back ${steps} migration(s)...`);
|
|
251
|
-
cliConsole.log(
|
|
263
|
+
cliConsole.log("");
|
|
252
264
|
cliConsole.warn(
|
|
253
|
-
|
|
265
|
+
"Migration rollback requires database connection. Use the MigrationRunner in your application code.",
|
|
254
266
|
);
|
|
255
|
-
cliConsole.log(
|
|
256
|
-
cliConsole.log(
|
|
257
|
-
cliConsole.log(
|
|
258
|
-
|
|
267
|
+
cliConsole.log("");
|
|
268
|
+
cliConsole.log("Example:");
|
|
269
|
+
cliConsole.log(
|
|
270
|
+
colors.cyan(`
|
|
271
|
+
import { createMigrationRunner, loadMigrations } from '@buenojs/bueno/migrations';
|
|
259
272
|
import { db } from './database';
|
|
260
273
|
|
|
261
274
|
const runner = createMigrationRunner(db);
|
|
262
275
|
const migrations = await loadMigrations('./database/migrations');
|
|
263
276
|
await runner.rollback(migrations, ${steps});
|
|
264
|
-
`)
|
|
277
|
+
`),
|
|
278
|
+
);
|
|
265
279
|
break;
|
|
266
280
|
}
|
|
267
281
|
|
|
268
|
-
case
|
|
269
|
-
cliConsole.info(
|
|
270
|
-
cliConsole.log(
|
|
282
|
+
case "reset": {
|
|
283
|
+
cliConsole.info("Rolling back all migrations...");
|
|
284
|
+
cliConsole.log("");
|
|
271
285
|
cliConsole.warn(
|
|
272
|
-
|
|
286
|
+
"Migration reset requires database connection. Use the MigrationRunner in your application code.",
|
|
273
287
|
);
|
|
274
|
-
cliConsole.log(
|
|
275
|
-
cliConsole.log(
|
|
276
|
-
cliConsole.log(
|
|
277
|
-
|
|
288
|
+
cliConsole.log("");
|
|
289
|
+
cliConsole.log("Example:");
|
|
290
|
+
cliConsole.log(
|
|
291
|
+
colors.cyan(`
|
|
292
|
+
import { createMigrationRunner, loadMigrations } from '@buenojs/bueno/migrations';
|
|
278
293
|
import { db } from './database';
|
|
279
294
|
|
|
280
295
|
const runner = createMigrationRunner(db);
|
|
281
296
|
const migrations = await loadMigrations('./database/migrations');
|
|
282
297
|
await runner.reset(migrations);
|
|
283
|
-
`)
|
|
298
|
+
`),
|
|
299
|
+
);
|
|
284
300
|
break;
|
|
285
301
|
}
|
|
286
302
|
|
|
287
|
-
case
|
|
288
|
-
cliConsole.info(
|
|
289
|
-
cliConsole.log(
|
|
303
|
+
case "refresh": {
|
|
304
|
+
cliConsole.info("Refreshing all migrations...");
|
|
305
|
+
cliConsole.log("");
|
|
290
306
|
cliConsole.warn(
|
|
291
|
-
|
|
307
|
+
"Migration refresh requires database connection. Use the MigrationRunner in your application code.",
|
|
292
308
|
);
|
|
293
|
-
cliConsole.log(
|
|
294
|
-
cliConsole.log(
|
|
295
|
-
cliConsole.log(
|
|
296
|
-
|
|
309
|
+
cliConsole.log("");
|
|
310
|
+
cliConsole.log("Example:");
|
|
311
|
+
cliConsole.log(
|
|
312
|
+
colors.cyan(`
|
|
313
|
+
import { createMigrationRunner, loadMigrations } from '@buenojs/bueno/migrations';
|
|
297
314
|
import { db } from './database';
|
|
298
315
|
|
|
299
316
|
const runner = createMigrationRunner(db);
|
|
300
317
|
const migrations = await loadMigrations('./database/migrations');
|
|
301
318
|
await runner.refresh(migrations);
|
|
302
|
-
`)
|
|
319
|
+
`),
|
|
320
|
+
);
|
|
303
321
|
break;
|
|
304
322
|
}
|
|
305
323
|
|
|
306
|
-
case
|
|
324
|
+
case "status": {
|
|
307
325
|
await showStatus();
|
|
308
326
|
break;
|
|
309
327
|
}
|
|
@@ -313,43 +331,44 @@ await runner.refresh(migrations);
|
|
|
313
331
|
// Register the command
|
|
314
332
|
defineCommand(
|
|
315
333
|
{
|
|
316
|
-
name:
|
|
317
|
-
description:
|
|
334
|
+
name: "migration",
|
|
335
|
+
description: "Manage database migrations",
|
|
318
336
|
positionals: [
|
|
319
337
|
{
|
|
320
|
-
name:
|
|
338
|
+
name: "action",
|
|
321
339
|
required: true,
|
|
322
|
-
description:
|
|
340
|
+
description:
|
|
341
|
+
"Action to perform (create, up, down, reset, refresh, status)",
|
|
323
342
|
},
|
|
324
343
|
{
|
|
325
|
-
name:
|
|
344
|
+
name: "name",
|
|
326
345
|
required: false,
|
|
327
|
-
description:
|
|
346
|
+
description: "Migration name (required for create action)",
|
|
328
347
|
},
|
|
329
348
|
],
|
|
330
349
|
options: [
|
|
331
350
|
{
|
|
332
|
-
name:
|
|
333
|
-
alias:
|
|
334
|
-
type:
|
|
351
|
+
name: "steps",
|
|
352
|
+
alias: "n",
|
|
353
|
+
type: "number",
|
|
335
354
|
default: 1,
|
|
336
|
-
description:
|
|
355
|
+
description: "Number of migrations to rollback",
|
|
337
356
|
},
|
|
338
357
|
{
|
|
339
|
-
name:
|
|
340
|
-
type:
|
|
358
|
+
name: "dry-run",
|
|
359
|
+
type: "boolean",
|
|
341
360
|
default: false,
|
|
342
|
-
description:
|
|
361
|
+
description: "Show what would happen without executing",
|
|
343
362
|
},
|
|
344
363
|
],
|
|
345
364
|
examples: [
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
365
|
+
"bueno migration create add-users-table",
|
|
366
|
+
"bueno migration up",
|
|
367
|
+
"bueno migration down --steps 3",
|
|
368
|
+
"bueno migration reset",
|
|
369
|
+
"bueno migration refresh",
|
|
370
|
+
"bueno migration status",
|
|
352
371
|
],
|
|
353
372
|
},
|
|
354
373
|
handleMigration,
|
|
355
|
-
);
|
|
374
|
+
);
|