@restforgejs/platform 5.1.21 → 5.2.4
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/build-info.json +2 -2
- package/cli/consumer-deploy.js +2 -2
- package/cli/consumer.js +2 -2
- package/generators/cli/catalog/dashboard.js +1 -1
- package/generators/cli/catalog/dbschema.js +3 -3
- package/generators/cli/catalog/field-validation.js +1 -1
- package/generators/cli/catalog/query-declarative.js +1 -1
- package/generators/cli/config/clear-default.js +1 -1
- package/generators/cli/config/get-default.js +1 -1
- package/generators/cli/config/list.js +1 -1
- package/generators/cli/config/schema.js +1 -1
- package/generators/cli/config/set-default.js +2 -2
- package/generators/cli/config/template.js +1 -1
- package/generators/cli/dashboard/create.js +7 -7
- package/generators/cli/data/pull.js +12 -12
- package/generators/cli/data/push.js +9 -9
- package/generators/cli/endpoint/create.js +11 -11
- package/generators/cli/endpoint/list.js +3 -3
- package/generators/cli/fast-track.js +65 -12
- package/generators/cli/init.js +2 -2
- package/generators/cli/kafka/consumer-create.js +5 -5
- package/generators/cli/key/generate.js +3 -3
- package/generators/cli/key/list.js +2 -2
- package/generators/cli/key/revoke.js +3 -3
- package/generators/cli/payload/diff.js +3 -3
- package/generators/cli/payload/generate.js +5 -5
- package/generators/cli/payload/sync.js +5 -5
- package/generators/cli/payload/validate.js +3 -3
- package/generators/cli/processor/create.js +7 -7
- package/generators/cli/processor/list.js +3 -3
- package/generators/cli/project/delete.js +2 -2
- package/generators/cli/project/list.js +1 -1
- package/generators/cli/query/validate.js +3 -3
- package/generators/cli/schema/apply.js +13 -13
- package/generators/cli/schema/describe.js +6 -6
- package/generators/cli/schema/diff.js +10 -10
- package/generators/cli/schema/generate-ddl.js +11 -11
- package/generators/cli/schema/init.js +95 -95
- package/generators/cli/schema/introspect.js +8 -8
- package/generators/cli/schema/list.js +6 -6
- package/generators/cli/schema/migrate.js +91 -13
- package/generators/cli/schema/models.js +6 -6
- package/generators/cli/schema/template.js +223 -222
- package/generators/cli/schema/validate.js +6 -6
- package/generators/cli/test/generate.js +6 -6
- package/generators/lib/dbschema-kit/introspect-mapper.js +20 -0
- package/generators/lib/migrate/migrate-runner.js +12 -2
- package/generators/lib/migrate/sql-parser.js +5 -3
- package/generators/lib/payload/payload-runner.js +31 -5
- package/generators/lib/templates/dashboard-catalog.js +1 -1
- package/generators/lib/templates/db-connection-env.js +1 -1
- package/generators/lib/templates/dbschema-catalog.js +1 -1
- package/generators/lib/templates/field-validation-catalog.js +1 -1
- package/generators/lib/templates/mysql-template.js +1 -1
- package/generators/lib/templates/oracle-template.js +1 -1
- package/generators/lib/templates/postgres-template.js +1 -1
- package/generators/lib/templates/query-declarative-catalog.js +1 -1
- package/generators/lib/templates/sqlite-template.js +1 -1
- package/integrity-manifest.json +18 -18
- package/package.json +1 -1
- package/scripts/verify-integrity.js +1 -1
- package/server.js +2 -2
- package/src/components/handlers/adjust_handler.js +1 -1
- package/src/components/handlers/audit_handler.js +1 -1
- package/src/components/handlers/delete_handler.js +1 -1
- package/src/components/handlers/export_handler.js +1 -1
- package/src/components/handlers/import_handler.js +1 -1
- package/src/components/handlers/insert_handler.js +1 -1
- package/src/components/handlers/update_handler.js +1 -1
- package/src/components/handlers/upload_handler.js +1 -1
- package/src/components/handlers/workflow_handler.js +1 -1
- package/src/components/integrations/webhook.js +1 -1
- package/src/consumers/baseConsumer.js +1 -1
- package/src/consumers/declarativeMapper.js +1 -1
- package/src/consumers/handlers/apiHandler.js +1 -1
- package/src/consumers/handlers/consoleHandler.js +1 -1
- package/src/consumers/handlers/databaseHandler.js +1 -1
- package/src/consumers/handlers/index.js +1 -1
- package/src/consumers/handlers/kafkaHandler.js +1 -1
- package/src/consumers/index.js +1 -1
- package/src/consumers/messageTransformer.js +1 -1
- package/src/consumers/validator.js +1 -1
- package/src/core/db/dialect/base-dialect.js +1 -1
- package/src/core/db/dialect/index.js +1 -1
- package/src/core/db/dialect/mysql-dialect.js +1 -1
- package/src/core/db/dialect/oracle-dialect.js +1 -1
- package/src/core/db/dialect/postgres-dialect.js +1 -1
- package/src/core/db/dialect/sqlite-dialect.js +1 -1
- package/src/core/db/flatten-helper.js +1 -1
- package/src/core/db/query-builder-error.js +1 -1
- package/src/core/db/query-builder.js +1 -1
- package/src/core/db/relation-helper.js +1 -1
- package/src/core/handlers/delete_handler.js +1 -1
- package/src/core/handlers/insert_handler.js +1 -1
- package/src/core/handlers/update_handler.js +1 -1
- package/src/core/models/base-model.js +1 -1
- package/src/core/utils/cache-manager.js +1 -1
- package/src/core/utils/component-engine.js +1 -1
- package/src/core/utils/context-builder.js +1 -1
- package/src/core/utils/datetime-formatter.js +1 -1
- package/src/core/utils/datetime-parser.js +1 -1
- package/src/core/utils/db.js +1 -1
- package/src/core/utils/logger.js +1 -1
- package/src/core/utils/payload-loader.js +1 -1
- package/src/core/utils/security-checks.js +1 -1
- package/src/middleware/body-options.js +1 -1
- package/src/middleware/cors.js +1 -1
- package/src/middleware/idempotency.js +1 -1
- package/src/middleware/rate-limiter.js +1 -1
- package/src/middleware/request-logger.js +1 -1
- package/src/middleware/security-headers.js +1 -1
- package/src/models/base-model-mysql.js +1 -1
- package/src/models/base-model-oracle.js +1 -1
- package/src/models/base-model-sqlite.js +1 -1
- package/src/models/base-model.js +1 -1
- package/src/pro/caching/redis-client.js +1 -1
- package/src/pro/caching/redis-helper.js +1 -1
- package/src/pro/consumers/baseConsumer.js +1 -1
- package/src/pro/consumers/declarativeMapper.js +1 -1
- package/src/pro/consumers/handlers/apiHandler.js +1 -1
- package/src/pro/consumers/handlers/consoleHandler.js +1 -1
- package/src/pro/consumers/handlers/databaseHandler.js +1 -1
- package/src/pro/consumers/handlers/index.js +1 -1
- package/src/pro/consumers/handlers/kafkaHandler.js +1 -1
- package/src/pro/consumers/index.js +1 -1
- package/src/pro/consumers/messageTransformer.js +1 -1
- package/src/pro/consumers/validator.js +1 -1
- package/src/pro/database/base-model-mysql.js +1 -1
- package/src/pro/database/base-model-oracle.js +1 -1
- package/src/pro/database/base-model-sqlite.js +1 -1
- package/src/pro/database/db-mysql.js +1 -1
- package/src/pro/database/db-oracle.js +1 -1
- package/src/pro/database/db-sqlite.js +1 -1
- package/src/pro/excel/excel-generator.js +1 -1
- package/src/pro/excel/excel-parser.js +1 -1
- package/src/pro/excel/export-service.js +1 -1
- package/src/pro/excel/export_handler.js +1 -1
- package/src/pro/excel/import-service.js +1 -1
- package/src/pro/excel/import-validator.js +1 -1
- package/src/pro/excel/import_handler.js +1 -1
- package/src/pro/excel/upsert-builder.js +1 -1
- package/src/pro/idgen/idgen-routes.js +1 -1
- package/src/pro/integrations/lookup-resolver.js +1 -1
- package/src/pro/integrations/upload-handler-v2.js +1 -1
- package/src/pro/integrations/upload-handler.js +1 -1
- package/src/pro/integrations/webhook.js +1 -1
- package/src/pro/locking/lock-routes.js +1 -1
- package/src/pro/locking/resource-lock-manager.js +1 -1
- package/src/pro/messaging/kafkaConsumerService.js +1 -1
- package/src/pro/messaging/kafkaService.js +1 -1
- package/src/pro/messaging/messagehubService.js +1 -1
- package/src/pro/messaging/rabbitmqService.js +1 -1
- package/src/pro/scheduler/job-manager.js +1 -1
- package/src/pro/scheduler/job-routes.js +1 -1
- package/src/pro/scheduler/job-validator.js +1 -1
- package/src/pro/storage/base-storage-provider.js +1 -1
- package/src/pro/storage/file-metadata-helper.js +1 -1
- package/src/pro/storage/index.js +1 -1
- package/src/pro/storage/local-storage-provider.js +1 -1
- package/src/pro/storage/s3-storage-provider.js +1 -1
- package/src/pro/storage/upload-cleanup-job.js +1 -1
- package/src/pro/storage/upload-cleanup-scheduler.js +1 -1
- package/src/pro/storage/upload-pending-tracker.js +1 -1
- package/src/pro/websocket/broadcast-helper.js +1 -1
- package/src/pro/websocket/index.js +1 -1
- package/src/pro/websocket/livesync-server.js +1 -1
- package/src/pro/websocket/ws-broadcaster.js +1 -1
- package/src/services/export-service.js +1 -1
- package/src/services/import-service.js +1 -1
- package/src/services/kafkaConsumerService.js +1 -1
- package/src/services/kafkaService.js +1 -1
- package/src/services/messagehubService.js +1 -1
- package/src/services/rabbitmqService.js +1 -1
- package/src/utils/cache-invalidation-registry.js +1 -1
- package/src/utils/cache-manager.js +1 -1
- package/src/utils/component-engine.js +1 -1
- package/src/utils/config-extractor.js +1 -1
- package/src/utils/consumerLogger.js +1 -1
- package/src/utils/context-builder.js +1 -1
- package/src/utils/dashboard-helpers.js +1 -1
- package/src/utils/dateHelper.js +1 -1
- package/src/utils/datetime-formatter.js +1 -1
- package/src/utils/datetime-parser.js +1 -1
- package/src/utils/db-bootstrap.js +1 -1
- package/src/utils/db-mysql.js +1 -1
- package/src/utils/db-oracle.js +1 -1
- package/src/utils/db-sqlite.js +1 -1
- package/src/utils/db.js +1 -1
- package/src/utils/demo-generator.js +1 -1
- package/src/utils/excel-generator.js +1 -1
- package/src/utils/excel-parser.js +1 -1
- package/src/utils/file-watcher.js +1 -1
- package/src/utils/id-generator.js +1 -1
- package/src/utils/idempotency-manager.js +1 -1
- package/src/utils/import-validator.js +1 -1
- package/src/utils/license-client.js +1 -1
- package/src/utils/lock-manager.js +1 -1
- package/src/utils/logger.js +1 -1
- package/src/utils/lookup-resolver.js +1 -1
- package/src/utils/payload-loader.js +1 -1
- package/src/utils/processor-response.js +1 -1
- package/src/utils/rabbitmq.js +1 -1
- package/src/utils/redis-client.js +1 -1
- package/src/utils/redis-helper.js +1 -1
- package/src/utils/request-scope.js +1 -1
- package/src/utils/security-checks.js +1 -1
- package/src/utils/service-resolver.js +1 -1
- package/src/utils/shutdown-coordinator.js +1 -1
- package/src/utils/soft-delete-dashboard-guard.js +1 -1
- package/src/utils/sql-table-extractor.js +1 -1
- package/src/utils/trusted-keys.js +1 -1
- package/src/utils/upload-handler.js +1 -1
- package/src/utils/upsert-builder.js +1 -1
- package/src/utils/workflow-hook-executor.js +1 -1
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Contract: schema init
|
|
5
|
-
*
|
|
6
|
-
* Thin wrapper untuk scaffold file schema definition. Implementasi sekarang
|
|
7
|
-
* mendelegasikan ke binary native sdf-tools.exe dengan template `dummy`,
|
|
8
|
-
* menggantikan generator skeleton custom yang sebelumnya inline.
|
|
9
|
-
*
|
|
10
|
-
* Setara dengan: sdf-tools.exe --table=dummy --generate --lang=sdf --path=<USER_PATH>
|
|
11
|
-
*
|
|
12
|
-
* Kontrak CLI dipertahankan (verb, category, flag --path) agar workflow user
|
|
13
|
-
* tidak breaking. File yang dihasilkan berisi struktur template `dummy` dari
|
|
14
|
-
* koleksi RestForge Schema Reference, yang dapat di-rename dan diadaptasi
|
|
15
|
-
* sesuai kebutuhan.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const fs = require('fs');
|
|
19
|
-
const os = require('os');
|
|
20
|
-
const path = require('path');
|
|
21
|
-
const { spawnSync } = require('child_process');
|
|
22
|
-
|
|
23
|
-
function resolveBinaryPath() {
|
|
24
|
-
if (os.platform() !== 'win32') return null;
|
|
25
|
-
return path.resolve(__dirname, '..', '..', '..', 'bin', 'sdf-tools.exe');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
resource: 'schema',
|
|
30
|
-
verb: 'init',
|
|
31
|
-
description: '
|
|
32
|
-
category: 'utility',
|
|
33
|
-
flags: {
|
|
34
|
-
path: {
|
|
35
|
-
type: 'string',
|
|
36
|
-
required: true,
|
|
37
|
-
description: 'Path
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
examples: [
|
|
41
|
-
'npx restforge schema init --path=schema/users.js',
|
|
42
|
-
'npx restforge schema init --path=./schema/item_product.js'
|
|
43
|
-
],
|
|
44
|
-
async handler(args) {
|
|
45
|
-
if (!args
|
|
46
|
-
console.error('Error: Target file path is required.');
|
|
47
|
-
console.error("Run 'npx restforge schema init --help' for usage information");
|
|
48
|
-
throw new Error('Target file path is required');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const binaryPath = resolveBinaryPath();
|
|
52
|
-
if (!binaryPath) {
|
|
53
|
-
const err = new Error(
|
|
54
|
-
`schema init hanya tersedia di Windows (sdf-tools.exe). Platform saat ini: ${os.platform()}`
|
|
55
|
-
);
|
|
56
|
-
err.exitCode = 3;
|
|
57
|
-
throw err;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (!fs.existsSync(binaryPath)) {
|
|
61
|
-
const err = new Error(
|
|
62
|
-
`sdf-tools.exe tidak ditemukan di ${binaryPath}. ` +
|
|
63
|
-
'Pastikan binary sudah di-build dan tersedia di folder bin/ package.'
|
|
64
|
-
);
|
|
65
|
-
err.exitCode = 3;
|
|
66
|
-
throw err;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const binaryArgs = [
|
|
70
|
-
'--table=dummy',
|
|
71
|
-
'--generate',
|
|
72
|
-
'--lang=sdf',
|
|
73
|
-
`--path=${args
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
const result = spawnSync(binaryPath, binaryArgs, {
|
|
77
|
-
stdio: 'inherit',
|
|
78
|
-
windowsHide: true
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (result.error) {
|
|
82
|
-
const err = new Error(`Gagal menjalankan sdf-tools.exe: ${result.error.message}`);
|
|
83
|
-
err.exitCode = 1;
|
|
84
|
-
throw err;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const status = typeof result.status === 'number' ? result.status : 1;
|
|
88
|
-
if (status !== 0) {
|
|
89
|
-
const err = new Error(`sdf-tools.exe exit code ${status}`);
|
|
90
|
-
err.exitCode = status;
|
|
91
|
-
err.silent = true;
|
|
92
|
-
throw err;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Contract: schema init
|
|
5
|
+
*
|
|
6
|
+
* Thin wrapper untuk scaffold file schema definition. Implementasi sekarang
|
|
7
|
+
* mendelegasikan ke binary native sdf-tools.exe dengan template `dummy`,
|
|
8
|
+
* menggantikan generator skeleton custom yang sebelumnya inline.
|
|
9
|
+
*
|
|
10
|
+
* Setara dengan: sdf-tools.exe --table=dummy --generate --lang=sdf --path=<USER_PATH>
|
|
11
|
+
*
|
|
12
|
+
* Kontrak CLI dipertahankan (verb, category, flag --path) agar workflow user
|
|
13
|
+
* tidak breaking. File yang dihasilkan berisi struktur template `dummy` dari
|
|
14
|
+
* koleksi RestForge Schema Reference, yang dapat di-rename dan diadaptasi
|
|
15
|
+
* sesuai kebutuhan.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const os = require('os');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const { spawnSync } = require('child_process');
|
|
22
|
+
|
|
23
|
+
function resolveBinaryPath() {
|
|
24
|
+
if (os.platform() !== 'win32') return null;
|
|
25
|
+
return path.resolve(__dirname, '..', '..', '..', 'bin', 'sdf-tools.exe');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
resource: 'schema',
|
|
30
|
+
verb: 'init',
|
|
31
|
+
description: 'Create a skeleton schema definition file (delegates to sdf-tools with a dummy template)',
|
|
32
|
+
category: 'utility',
|
|
33
|
+
flags: {
|
|
34
|
+
'schema-path': {
|
|
35
|
+
type: 'string',
|
|
36
|
+
required: true,
|
|
37
|
+
description: 'Path to the schema file to create (e.g., schema/users.js)'
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
examples: [
|
|
41
|
+
'npx restforge schema init --schema-path=schema/users.js',
|
|
42
|
+
'npx restforge schema init --schema-path=./schema/item_product.js'
|
|
43
|
+
],
|
|
44
|
+
async handler(args) {
|
|
45
|
+
if (!args['schema-path']) {
|
|
46
|
+
console.error('Error: Target file path is required.');
|
|
47
|
+
console.error("Run 'npx restforge schema init --help' for usage information");
|
|
48
|
+
throw new Error('Target file path is required');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const binaryPath = resolveBinaryPath();
|
|
52
|
+
if (!binaryPath) {
|
|
53
|
+
const err = new Error(
|
|
54
|
+
`schema init hanya tersedia di Windows (sdf-tools.exe). Platform saat ini: ${os.platform()}`
|
|
55
|
+
);
|
|
56
|
+
err.exitCode = 3;
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!fs.existsSync(binaryPath)) {
|
|
61
|
+
const err = new Error(
|
|
62
|
+
`sdf-tools.exe tidak ditemukan di ${binaryPath}. ` +
|
|
63
|
+
'Pastikan binary sudah di-build dan tersedia di folder bin/ package.'
|
|
64
|
+
);
|
|
65
|
+
err.exitCode = 3;
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const binaryArgs = [
|
|
70
|
+
'--table=dummy',
|
|
71
|
+
'--generate',
|
|
72
|
+
'--lang=sdf',
|
|
73
|
+
`--path=${args['schema-path']}`
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const result = spawnSync(binaryPath, binaryArgs, {
|
|
77
|
+
stdio: 'inherit',
|
|
78
|
+
windowsHide: true
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (result.error) {
|
|
82
|
+
const err = new Error(`Gagal menjalankan sdf-tools.exe: ${result.error.message}`);
|
|
83
|
+
err.exitCode = 1;
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const status = typeof result.status === 'number' ? result.status : 1;
|
|
88
|
+
if (status !== 0) {
|
|
89
|
+
const err = new Error(`sdf-tools.exe exit code ${status}`);
|
|
90
|
+
err.exitCode = status;
|
|
91
|
+
err.silent = true;
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
@@ -238,49 +238,49 @@ function resolveTargetPath(mode, item) {
|
|
|
238
238
|
module.exports = {
|
|
239
239
|
resource: 'schema',
|
|
240
240
|
verb: 'introspect',
|
|
241
|
-
description: 'Reverse-engineer
|
|
241
|
+
description: 'Reverse-engineer an existing database into schema definitions (dbschema-kit factory function)',
|
|
242
242
|
category: 'introspection',
|
|
243
243
|
flags: {
|
|
244
244
|
config: {
|
|
245
245
|
type: 'string',
|
|
246
246
|
required: false,
|
|
247
247
|
default: null,
|
|
248
|
-
description: '
|
|
248
|
+
description: 'Database config file (.env). Fallback to `.restforge/defaults.json` if not explicitly provided (set via `config set-default`)'
|
|
249
249
|
},
|
|
250
250
|
'schema-path': {
|
|
251
251
|
type: 'string',
|
|
252
252
|
required: true,
|
|
253
|
-
description: '
|
|
253
|
+
description: 'Output folder or file for the schema'
|
|
254
254
|
},
|
|
255
255
|
table: {
|
|
256
256
|
type: 'string',
|
|
257
257
|
required: false,
|
|
258
258
|
default: null,
|
|
259
|
-
description: '
|
|
259
|
+
description: 'Introspect only one table (unqualified or qualified schema.table)'
|
|
260
260
|
},
|
|
261
261
|
schema: {
|
|
262
262
|
type: 'string',
|
|
263
263
|
required: false,
|
|
264
264
|
default: null,
|
|
265
|
-
description: 'Filter schema (single
|
|
265
|
+
description: 'Filter by schema name (single or comma-separated)'
|
|
266
266
|
},
|
|
267
267
|
'all-schemas': {
|
|
268
268
|
type: 'boolean',
|
|
269
269
|
required: false,
|
|
270
270
|
default: false,
|
|
271
|
-
description: 'Auto-detect
|
|
271
|
+
description: 'Auto-detect all user schemas (skips system schemas)'
|
|
272
272
|
},
|
|
273
273
|
force: {
|
|
274
274
|
type: 'boolean',
|
|
275
275
|
required: false,
|
|
276
276
|
default: false,
|
|
277
|
-
description: '
|
|
277
|
+
description: 'Overwrite existing files'
|
|
278
278
|
},
|
|
279
279
|
'dry-run': {
|
|
280
280
|
type: 'boolean',
|
|
281
281
|
required: false,
|
|
282
282
|
default: false,
|
|
283
|
-
description: 'Print factory function
|
|
283
|
+
description: 'Print factory function to stdout without writing files'
|
|
284
284
|
}
|
|
285
285
|
},
|
|
286
286
|
examples: [
|
|
@@ -67,38 +67,38 @@ function renderHumanTable(tables, schemas, dbType) {
|
|
|
67
67
|
module.exports = {
|
|
68
68
|
resource: 'schema',
|
|
69
69
|
verb: 'list',
|
|
70
|
-
description: '
|
|
70
|
+
description: 'List tables in the database via live introspection',
|
|
71
71
|
category: 'introspection',
|
|
72
72
|
flags: {
|
|
73
73
|
config: {
|
|
74
74
|
type: 'string',
|
|
75
75
|
required: false,
|
|
76
76
|
default: null,
|
|
77
|
-
description: '
|
|
77
|
+
description: 'Database config file (.env). Fallback to `.restforge/defaults.json` if not explicitly provided (set via `config set-default`)'
|
|
78
78
|
},
|
|
79
79
|
schema: {
|
|
80
80
|
type: 'string',
|
|
81
81
|
required: false,
|
|
82
82
|
default: null,
|
|
83
|
-
description: 'Filter
|
|
83
|
+
description: 'Filter by schema name (default: all non-system schemas)'
|
|
84
84
|
},
|
|
85
85
|
'include-system': {
|
|
86
86
|
type: 'boolean',
|
|
87
87
|
required: false,
|
|
88
88
|
default: false,
|
|
89
|
-
description: '
|
|
89
|
+
description: 'Include system schemas'
|
|
90
90
|
},
|
|
91
91
|
format: {
|
|
92
92
|
type: 'string',
|
|
93
93
|
required: false,
|
|
94
94
|
default: 'table',
|
|
95
|
-
description: '
|
|
95
|
+
description: 'Output format: `table` (human-readable, grouped by schema) or `json` (for AI agent / mcp-server)'
|
|
96
96
|
},
|
|
97
97
|
pretty: {
|
|
98
98
|
type: 'boolean',
|
|
99
99
|
required: false,
|
|
100
100
|
default: true,
|
|
101
|
-
description: 'Pretty-print output
|
|
101
|
+
description: 'Pretty-print JSON output (only applies when --format=json)'
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
examples: [
|
|
@@ -77,49 +77,55 @@ function formatStatementForDisplay(stmt, dialect) {
|
|
|
77
77
|
module.exports = {
|
|
78
78
|
resource: 'schema',
|
|
79
79
|
verb: 'migrate',
|
|
80
|
-
description: 'Apply schema definition
|
|
80
|
+
description: 'Apply schema definition to database (load → validate → generate DDL → execute). Destructive.',
|
|
81
81
|
category: 'management',
|
|
82
82
|
flags: {
|
|
83
|
-
path: {
|
|
83
|
+
'schema-path': {
|
|
84
84
|
type: 'string',
|
|
85
85
|
required: true,
|
|
86
|
-
description: 'Path file
|
|
86
|
+
description: 'Path to schema file or directory (e.g., ./schema or ./schema/users.js)'
|
|
87
87
|
},
|
|
88
88
|
config: {
|
|
89
89
|
type: 'string',
|
|
90
90
|
required: false,
|
|
91
91
|
default: null,
|
|
92
|
-
description: '
|
|
92
|
+
description: 'Database config file (.env). Fallback to `.restforge/defaults.json` if not explicitly provided (set via `config set-default`)'
|
|
93
93
|
},
|
|
94
94
|
drop: {
|
|
95
95
|
type: 'boolean',
|
|
96
96
|
required: false,
|
|
97
97
|
default: false,
|
|
98
|
-
description: 'Drop
|
|
98
|
+
description: 'Drop tables before re-create (destructive, data will be lost)'
|
|
99
99
|
},
|
|
100
100
|
'dry-run': {
|
|
101
101
|
type: 'boolean',
|
|
102
102
|
required: false,
|
|
103
103
|
default: false,
|
|
104
|
-
description: 'Preview DDL
|
|
104
|
+
description: 'Preview DDL without applying to database'
|
|
105
105
|
},
|
|
106
106
|
'max-name-length': {
|
|
107
107
|
type: 'number',
|
|
108
108
|
required: false,
|
|
109
109
|
default: null,
|
|
110
|
-
description: '
|
|
110
|
+
description: 'Maximum identifier length (overrides default per dialect: postgres=63, mysql=64, oracle=128, sqlite=63)'
|
|
111
111
|
},
|
|
112
112
|
'auto-create-db': {
|
|
113
113
|
type: 'boolean',
|
|
114
114
|
required: false,
|
|
115
115
|
default: false,
|
|
116
|
-
description: '
|
|
116
|
+
description: 'Postgres/MySQL only. Automatically create database if it does not exist (skips interactive confirmation). Useful for non-interactive mode (CI/CD).'
|
|
117
|
+
},
|
|
118
|
+
'auto-create-schema': {
|
|
119
|
+
type: 'boolean',
|
|
120
|
+
required: false,
|
|
121
|
+
default: false,
|
|
122
|
+
description: 'Postgres only. Automatically create schema (namespace) if it does not exist (skips interactive confirmation). Useful for non-interactive mode (CI/CD).'
|
|
117
123
|
}
|
|
118
124
|
},
|
|
119
125
|
examples: [
|
|
120
|
-
'npx restforge schema migrate --path=./schema --config=db.env --dry-run',
|
|
121
|
-
'npx restforge schema migrate --path=./schema --config=db.env',
|
|
122
|
-
'npx restforge schema migrate --path=./schema --config=db.env --auto-create-db'
|
|
126
|
+
'npx restforge schema migrate --schema-path=./schema --config=db.env --dry-run',
|
|
127
|
+
'npx restforge schema migrate --schema-path=./schema --config=db.env',
|
|
128
|
+
'npx restforge schema migrate --schema-path=./schema --config=db.env --auto-create-db'
|
|
123
129
|
],
|
|
124
130
|
async handler(args) {
|
|
125
131
|
const resolved = resolveConfig(args.config, process.cwd());
|
|
@@ -143,7 +149,7 @@ module.exports = {
|
|
|
143
149
|
throw err;
|
|
144
150
|
}
|
|
145
151
|
|
|
146
|
-
const schemaPathArg = args
|
|
152
|
+
const schemaPathArg = args['schema-path'];
|
|
147
153
|
const absPath = path.resolve(process.cwd(), schemaPathArg);
|
|
148
154
|
|
|
149
155
|
if (!fs.existsSync(absPath)) {
|
|
@@ -274,7 +280,7 @@ module.exports = {
|
|
|
274
280
|
}
|
|
275
281
|
|
|
276
282
|
if (testErr && isDbNotExistsError(targetDbType, testErr)) {
|
|
277
|
-
const hintParts = ['npx restforge schema migrate', `--path=${args
|
|
283
|
+
const hintParts = ['npx restforge schema migrate', `--schema-path=${args['schema-path']}`, `--config=${args.config}`];
|
|
278
284
|
if (args.drop === true) hintParts.push('--drop=true');
|
|
279
285
|
if (args['auto-create-db']) hintParts.push('--auto-create-db');
|
|
280
286
|
const commandHint = hintParts.join(' ');
|
|
@@ -305,6 +311,78 @@ module.exports = {
|
|
|
305
311
|
// dengan behavior sebelumnya.
|
|
306
312
|
}
|
|
307
313
|
|
|
314
|
+
// ------------------------------------------------------------------
|
|
315
|
+
// Pre-check schema (namespace) existence untuk postgres.
|
|
316
|
+
// Bila ada schema yang belum ada, tawarkan pembuatan via dialog
|
|
317
|
+
// konfirmasi (TTY) atau flag --auto-create-schema (non-TTY).
|
|
318
|
+
//
|
|
319
|
+
// Berbeda dari missing database: setelah schema berhasil dibuat,
|
|
320
|
+
// command langsung lanjut apply DDL tanpa perlu re-run.
|
|
321
|
+
//
|
|
322
|
+
// Pre-check di-skip bila test stub aktif agar unit test tidak
|
|
323
|
+
// melakukan real network call ke database.
|
|
324
|
+
// ------------------------------------------------------------------
|
|
325
|
+
if (config.dialect === 'postgres' && !process.env.DBSCHEMA_KIT_TEST_APPLY_STUB) {
|
|
326
|
+
const {
|
|
327
|
+
checkMissingSchemas,
|
|
328
|
+
handleMissingSchemas
|
|
329
|
+
} = require('../../../src/utils/db-bootstrap');
|
|
330
|
+
|
|
331
|
+
// Ekstrak namespace dari qualified table name (mis. "mydemo.guest_book" → "mydemo")
|
|
332
|
+
const namespacesNeeded = new Set();
|
|
333
|
+
for (const qualified of models.keys()) {
|
|
334
|
+
const dotIndex = qualified.indexOf('.');
|
|
335
|
+
if (dotIndex > 0) {
|
|
336
|
+
namespacesNeeded.add(qualified.slice(0, dotIndex));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
namespacesNeeded.delete('public'); // public selalu ada di PostgreSQL
|
|
340
|
+
|
|
341
|
+
if (namespacesNeeded.size > 0) {
|
|
342
|
+
const connectionConfig = {
|
|
343
|
+
host: config.host,
|
|
344
|
+
port: config.port,
|
|
345
|
+
user: config.user,
|
|
346
|
+
password: config.password,
|
|
347
|
+
database: config.database
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
let missingSchemas = [];
|
|
351
|
+
try {
|
|
352
|
+
missingSchemas = await checkMissingSchemas(connectionConfig, [...namespacesNeeded]);
|
|
353
|
+
} catch (_) {
|
|
354
|
+
// Jika check gagal, biarkan apply executor yang menangani error
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (missingSchemas.length > 0) {
|
|
358
|
+
const schemaResult = await handleMissingSchemas({
|
|
359
|
+
connectionConfig,
|
|
360
|
+
missingSchemas,
|
|
361
|
+
autoCreate: args['auto-create-schema']
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
if (schemaResult.handled && !schemaResult.created) {
|
|
365
|
+
if (schemaResult.reason === 'user declined') {
|
|
366
|
+
console.log('Aborted by user. No changes applied.');
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (schemaResult.reason === 'non-interactive' && schemaResult.hint) {
|
|
370
|
+
console.log('');
|
|
371
|
+
console.log(`Tip: ${schemaResult.hint}`);
|
|
372
|
+
}
|
|
373
|
+
if (schemaResult.reason === 'create failed') {
|
|
374
|
+
console.error('Error: Failed to create one or more schemas. No changes applied.');
|
|
375
|
+
throw new Error('Schema creation failed');
|
|
376
|
+
}
|
|
377
|
+
// non-interactive tanpa flag dan tanpa --auto-create-schema:
|
|
378
|
+
// lanjut apply; executor akan melempar error "schema does not exist"
|
|
379
|
+
// seperti sebelumnya (backward-compatible)
|
|
380
|
+
}
|
|
381
|
+
// schemaResult.created === true → lanjut apply DDL
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
308
386
|
console.log('Connection target:');
|
|
309
387
|
console.log(buildConnectionSummary(config));
|
|
310
388
|
console.log('');
|
|
@@ -67,21 +67,21 @@ function sortModels(models) {
|
|
|
67
67
|
module.exports = {
|
|
68
68
|
resource: 'schema',
|
|
69
69
|
verb: 'models',
|
|
70
|
-
description: '
|
|
70
|
+
description: 'List schema models with a structure summary (fields, primary key, indexes, uniques, relations)',
|
|
71
71
|
category: 'introspection',
|
|
72
72
|
flags: {
|
|
73
|
-
path: {
|
|
73
|
+
'schema-path': {
|
|
74
74
|
type: 'string',
|
|
75
75
|
required: true,
|
|
76
|
-
description: 'Path file
|
|
76
|
+
description: 'Path to schema file or directory (e.g., ./schema or ./schema/users.js)'
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
examples: [
|
|
80
|
-
'npx restforge schema models --path=./schema',
|
|
81
|
-
'npx restforge schema models --path=./custom-schema'
|
|
80
|
+
'npx restforge schema models --schema-path=./schema',
|
|
81
|
+
'npx restforge schema models --schema-path=./custom-schema'
|
|
82
82
|
],
|
|
83
83
|
async handler(args) {
|
|
84
|
-
const schemaPath = args
|
|
84
|
+
const schemaPath = args['schema-path'];
|
|
85
85
|
const absPath = path.resolve(process.cwd(), schemaPath);
|
|
86
86
|
|
|
87
87
|
let models;
|