@friggframework/devtools 2.0.0-next.7 → 2.0.0-next.70
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/frigg-cli/README.md +1289 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +279 -0
- package/frigg-cli/__tests__/unit/commands/db-setup.test.js +649 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +320 -0
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +309 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +400 -0
- package/frigg-cli/__tests__/unit/commands/ui.test.js +346 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +74 -0
- package/frigg-cli/__tests__/unit/utils/database-validator.test.js +397 -0
- package/frigg-cli/__tests__/unit/utils/error-messages.test.js +345 -0
- package/frigg-cli/__tests__/unit/version-detection.test.js +171 -0
- package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
- package/frigg-cli/__tests__/utils/prisma-mock.js +194 -0
- package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
- package/frigg-cli/__tests__/utils/test-setup.js +287 -0
- package/frigg-cli/auth-command/CLAUDE.md +293 -0
- package/frigg-cli/auth-command/README.md +450 -0
- package/frigg-cli/auth-command/api-key-flow.js +153 -0
- package/frigg-cli/auth-command/auth-tester.js +344 -0
- package/frigg-cli/auth-command/credential-storage.js +182 -0
- package/frigg-cli/auth-command/index.js +256 -0
- package/frigg-cli/auth-command/json-schema-form.js +67 -0
- package/frigg-cli/auth-command/module-loader.js +172 -0
- package/frigg-cli/auth-command/oauth-callback-server.js +431 -0
- package/frigg-cli/auth-command/oauth-flow.js +195 -0
- package/frigg-cli/auth-command/utils/browser.js +30 -0
- package/frigg-cli/build-command/index.js +45 -12
- package/frigg-cli/db-setup-command/index.js +246 -0
- package/frigg-cli/deploy-command/SPEC-DEPLOY-DRY-RUN.md +981 -0
- package/frigg-cli/deploy-command/index.js +295 -23
- package/frigg-cli/doctor-command/index.js +335 -0
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +301 -0
- package/frigg-cli/generate-command/azure-generator.js +43 -0
- package/frigg-cli/generate-command/gcp-generator.js +47 -0
- package/frigg-cli/generate-command/index.js +332 -0
- package/frigg-cli/generate-command/terraform-generator.js +555 -0
- package/frigg-cli/generate-iam-command.js +118 -0
- package/frigg-cli/index.js +174 -1
- package/frigg-cli/index.test.js +1 -4
- package/frigg-cli/init-command/backend-first-handler.js +756 -0
- package/frigg-cli/init-command/index.js +93 -0
- package/frigg-cli/init-command/template-handler.js +143 -0
- package/frigg-cli/install-command/index.js +1 -4
- package/frigg-cli/jest.config.js +124 -0
- package/frigg-cli/package.json +63 -0
- package/frigg-cli/repair-command/index.js +564 -0
- package/frigg-cli/start-command/index.js +118 -5
- package/frigg-cli/start-command/start-command.test.js +297 -0
- package/frigg-cli/test/init-command.test.js +180 -0
- package/frigg-cli/test/npm-registry.test.js +319 -0
- package/frigg-cli/ui-command/index.js +154 -0
- package/frigg-cli/utils/app-resolver.js +319 -0
- package/frigg-cli/utils/backend-path.js +16 -17
- package/frigg-cli/utils/database-validator.js +167 -0
- package/frigg-cli/utils/error-messages.js +329 -0
- package/frigg-cli/utils/npm-registry.js +167 -0
- package/frigg-cli/utils/process-manager.js +199 -0
- package/frigg-cli/utils/repo-detection.js +405 -0
- package/infrastructure/ARCHITECTURE.md +487 -0
- package/infrastructure/CLAUDE.md +481 -0
- package/infrastructure/HEALTH.md +468 -0
- package/infrastructure/README.md +522 -0
- package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
- package/infrastructure/__tests__/helpers/test-utils.js +277 -0
- package/infrastructure/__tests__/postgres-config.test.js +914 -0
- package/infrastructure/__tests__/template-generation.test.js +687 -0
- package/infrastructure/create-frigg-infrastructure.js +129 -20
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +630 -0
- package/infrastructure/docs/PRE-DEPLOYMENT-HEALTH-CHECK-SPEC.md +1317 -0
- package/infrastructure/docs/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/docs/deployment-instructions.md +268 -0
- package/infrastructure/docs/generate-iam-command.md +278 -0
- package/infrastructure/docs/iam-policy-templates.md +193 -0
- package/infrastructure/domains/database/aurora-builder.js +809 -0
- package/infrastructure/domains/database/aurora-builder.test.js +950 -0
- package/infrastructure/domains/database/aurora-discovery.js +87 -0
- package/infrastructure/domains/database/aurora-discovery.test.js +188 -0
- package/infrastructure/domains/database/aurora-resolver.js +210 -0
- package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
- package/infrastructure/domains/database/migration-builder.js +701 -0
- package/infrastructure/domains/database/migration-builder.test.js +321 -0
- package/infrastructure/domains/database/migration-resolver.js +163 -0
- package/infrastructure/domains/database/migration-resolver.test.js +337 -0
- package/infrastructure/domains/health/application/ports/IPropertyReconciler.js +164 -0
- package/infrastructure/domains/health/application/ports/IResourceDetector.js +129 -0
- package/infrastructure/domains/health/application/ports/IResourceImporter.js +142 -0
- package/infrastructure/domains/health/application/ports/IStackRepository.js +131 -0
- package/infrastructure/domains/health/application/ports/index.js +26 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/execute-resource-import-use-case.test.js +679 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +167 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +1130 -0
- package/infrastructure/domains/health/application/use-cases/execute-resource-import-use-case.js +221 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.js +152 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.test.js +343 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.js +535 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.test.js +376 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.js +213 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +441 -0
- package/infrastructure/domains/health/docs/ACME-DEV-DRIFT-ANALYSIS.md +267 -0
- package/infrastructure/domains/health/docs/BUILD-VS-DEPLOYED-TEMPLATE-ANALYSIS.md +324 -0
- package/infrastructure/domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md +386 -0
- package/infrastructure/domains/health/docs/SPEC-CLEANUP-COMMAND.md +1419 -0
- package/infrastructure/domains/health/docs/TDD-IMPLEMENTATION-SUMMARY.md +391 -0
- package/infrastructure/domains/health/docs/TEMPLATE-COMPARISON-IMPLEMENTATION.md +551 -0
- package/infrastructure/domains/health/domain/entities/issue.js +299 -0
- package/infrastructure/domains/health/domain/entities/issue.test.js +528 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.js +108 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.test.js +275 -0
- package/infrastructure/domains/health/domain/entities/resource.js +159 -0
- package/infrastructure/domains/health/domain/entities/resource.test.js +432 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.js +306 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.test.js +601 -0
- package/infrastructure/domains/health/domain/services/__tests__/health-score-percentage-based.test.js +380 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +971 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-template-generator.test.js +1150 -0
- package/infrastructure/domains/health/domain/services/__tests__/logical-id-mapper.test.js +672 -0
- package/infrastructure/domains/health/domain/services/__tests__/template-parser.test.js +496 -0
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +419 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.js +248 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.test.js +504 -0
- package/infrastructure/domains/health/domain/services/import-progress-monitor.js +195 -0
- package/infrastructure/domains/health/domain/services/import-template-generator.js +435 -0
- package/infrastructure/domains/health/domain/services/logical-id-mapper.js +345 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.js +234 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.test.js +431 -0
- package/infrastructure/domains/health/domain/services/property-mutability-config.js +382 -0
- package/infrastructure/domains/health/domain/services/template-parser.js +245 -0
- package/infrastructure/domains/health/domain/services/update-progress-monitor.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.js +138 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.test.js +267 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.js +161 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.test.js +198 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.js +167 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.test.js +196 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.test.js +262 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-cfn-tagged.test.js +312 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-multi-stack.test.js +367 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +432 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.js +784 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +1133 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.js +565 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +554 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.js +318 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.test.js +398 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.js +777 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.test.js +580 -0
- package/infrastructure/domains/integration/integration-builder.js +404 -0
- package/infrastructure/domains/integration/integration-builder.test.js +690 -0
- package/infrastructure/domains/integration/integration-resolver.js +170 -0
- package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
- package/infrastructure/domains/integration/websocket-builder.js +69 -0
- package/infrastructure/domains/integration/websocket-builder.test.js +195 -0
- package/infrastructure/domains/networking/vpc-builder.js +2051 -0
- package/infrastructure/domains/networking/vpc-builder.test.js +1960 -0
- package/infrastructure/domains/networking/vpc-discovery.js +177 -0
- package/infrastructure/domains/networking/vpc-discovery.test.js +350 -0
- package/infrastructure/domains/networking/vpc-resolver.js +505 -0
- package/infrastructure/domains/networking/vpc-resolver.test.js +801 -0
- package/infrastructure/domains/parameters/ssm-builder.js +79 -0
- package/infrastructure/domains/parameters/ssm-builder.test.js +189 -0
- package/infrastructure/domains/parameters/ssm-discovery.js +84 -0
- package/infrastructure/domains/parameters/ssm-discovery.test.js +210 -0
- package/infrastructure/domains/scheduler/scheduler-builder.js +211 -0
- package/infrastructure/domains/security/iam-generator.js +816 -0
- package/infrastructure/domains/security/iam-generator.test.js +204 -0
- package/infrastructure/domains/security/kms-builder.js +415 -0
- package/infrastructure/domains/security/kms-builder.test.js +392 -0
- package/infrastructure/domains/security/kms-discovery.js +80 -0
- package/infrastructure/domains/security/kms-discovery.test.js +177 -0
- package/infrastructure/domains/security/kms-resolver.js +96 -0
- package/infrastructure/domains/security/kms-resolver.test.js +216 -0
- package/infrastructure/domains/security/templates/frigg-deployment-iam-stack.yaml +401 -0
- package/infrastructure/domains/security/templates/iam-policy-basic.json +218 -0
- package/infrastructure/domains/security/templates/iam-policy-full.json +288 -0
- package/infrastructure/domains/shared/base-builder.js +112 -0
- package/infrastructure/domains/shared/base-resolver.js +186 -0
- package/infrastructure/domains/shared/base-resolver.test.js +305 -0
- package/infrastructure/domains/shared/builder-orchestrator.js +212 -0
- package/infrastructure/domains/shared/builder-orchestrator.test.js +213 -0
- package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
- package/infrastructure/domains/shared/cloudformation-discovery.js +672 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +985 -0
- package/infrastructure/domains/shared/environment-builder.js +119 -0
- package/infrastructure/domains/shared/environment-builder.test.js +247 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.js +579 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.test.js +416 -0
- package/infrastructure/domains/shared/providers/azure-provider-adapter.stub.js +93 -0
- package/infrastructure/domains/shared/providers/cloud-provider-adapter.js +136 -0
- package/infrastructure/domains/shared/providers/gcp-provider-adapter.stub.js +82 -0
- package/infrastructure/domains/shared/providers/provider-factory.js +108 -0
- package/infrastructure/domains/shared/providers/provider-factory.test.js +170 -0
- package/infrastructure/domains/shared/resource-discovery.enhanced.test.js +306 -0
- package/infrastructure/domains/shared/resource-discovery.js +233 -0
- package/infrastructure/domains/shared/resource-discovery.test.js +588 -0
- package/infrastructure/domains/shared/types/app-definition.js +205 -0
- package/infrastructure/domains/shared/types/discovery-result.js +106 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
- package/infrastructure/domains/shared/types/index.js +46 -0
- package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
- package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +408 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js.bak +338 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +291 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.js +134 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.test.js +268 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +159 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +444 -0
- package/infrastructure/domains/shared/validation/env-validator.js +78 -0
- package/infrastructure/domains/shared/validation/env-validator.test.js +173 -0
- package/infrastructure/domains/shared/validation/plugin-validator.js +187 -0
- package/infrastructure/domains/shared/validation/plugin-validator.test.js +323 -0
- package/infrastructure/esbuild.config.js +53 -0
- package/infrastructure/infrastructure-composer.js +119 -0
- package/infrastructure/infrastructure-composer.test.js +1895 -0
- package/infrastructure/integration.test.js +383 -0
- package/infrastructure/scripts/build-prisma-layer.js +701 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +170 -0
- package/infrastructure/scripts/build-time-discovery.js +238 -0
- package/infrastructure/scripts/build-time-discovery.test.js +379 -0
- package/infrastructure/scripts/run-discovery.js +110 -0
- package/infrastructure/scripts/verify-prisma-layer.js +72 -0
- package/management-ui/README.md +203 -0
- package/package.json +44 -14
- package/test/index.js +2 -4
- package/test/mock-api.js +1 -3
- package/test/mock-integration.js +4 -14
- package/.eslintrc.json +0 -3
- package/CHANGELOG.md +0 -132
- package/infrastructure/app-handler-helpers.js +0 -57
- package/infrastructure/backend-utils.js +0 -87
- package/infrastructure/routers/auth.js +0 -26
- package/infrastructure/routers/integration-defined-routers.js +0 -42
- package/infrastructure/routers/middleware/loadUser.js +0 -15
- package/infrastructure/routers/middleware/requireLoggedInUser.js +0 -12
- package/infrastructure/routers/user.js +0 -41
- package/infrastructure/routers/websocket.js +0 -55
- package/infrastructure/serverless-template.js +0 -291
- package/infrastructure/workers/integration-defined-workers.js +0 -24
- package/test/auther-definition-tester.js +0 -125
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { spawnSync } = require('child_process');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
-
function buildCommand(options) {
|
|
4
|
+
async function buildCommand(options) {
|
|
5
5
|
console.log('Building the serverless application...');
|
|
6
|
+
|
|
7
|
+
// Suppress AWS SDK warning message about maintenance mode
|
|
8
|
+
process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';
|
|
9
|
+
|
|
10
|
+
// Skip AWS discovery for local builds (unless --production flag is set)
|
|
11
|
+
if (!options.production) {
|
|
12
|
+
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
13
|
+
console.log('🏠 Building in local mode (use --production flag for production builds with AWS discovery)');
|
|
14
|
+
} else {
|
|
15
|
+
console.log('🚀 Building in production mode with AWS discovery enabled');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// AWS discovery is now handled directly in serverless-template.js
|
|
19
|
+
console.log('📦 Packaging serverless application...');
|
|
6
20
|
const backendPath = path.resolve(process.cwd());
|
|
7
21
|
const infrastructurePath = 'infrastructure.js';
|
|
8
|
-
const command = '
|
|
22
|
+
const command = 'osls'; // OSS-Serverless (drop-in replacement for serverless v3)
|
|
9
23
|
const serverlessArgs = [
|
|
10
24
|
'package',
|
|
11
25
|
'--config',
|
|
@@ -14,20 +28,39 @@ function buildCommand(options) {
|
|
|
14
28
|
options.stage
|
|
15
29
|
];
|
|
16
30
|
|
|
17
|
-
|
|
31
|
+
// Add support for --verbose option
|
|
32
|
+
if (options.verbose) {
|
|
33
|
+
serverlessArgs.push('--verbose');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log('Running command from ', backendPath);
|
|
37
|
+
console.log('Serverless Command:', command, serverlessArgs.join(' '));
|
|
38
|
+
|
|
39
|
+
const result = spawnSync(command, serverlessArgs, {
|
|
18
40
|
cwd: backendPath,
|
|
19
41
|
stdio: 'inherit',
|
|
42
|
+
shell: true,
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
NODE_PATH: path.resolve(backendPath, 'node_modules'),
|
|
46
|
+
SLS_STAGE: options.stage, // Set stage for resource discovery
|
|
47
|
+
}
|
|
20
48
|
});
|
|
21
49
|
|
|
22
|
-
|
|
23
|
-
console.error(`
|
|
24
|
-
|
|
50
|
+
if (result.status !== 0) {
|
|
51
|
+
console.error(`Serverless build failed with code ${result.status}`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
25
54
|
|
|
26
|
-
childProcess.on('
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
55
|
+
// childProcess.on('error', (error) => {
|
|
56
|
+
// console.error(`Error executing command: ${error.message}`);
|
|
57
|
+
// });
|
|
58
|
+
|
|
59
|
+
// childProcess.on('close', (code) => {
|
|
60
|
+
// if (code !== 0) {
|
|
61
|
+
// console.log(`Child process exited with code ${code}`);
|
|
62
|
+
// }
|
|
63
|
+
// });
|
|
31
64
|
}
|
|
32
65
|
|
|
33
66
|
module.exports = { buildCommand };
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const dotenv = require('dotenv');
|
|
4
|
+
const {
|
|
5
|
+
validateDatabaseUrl,
|
|
6
|
+
getDatabaseType,
|
|
7
|
+
checkPrismaClientGenerated,
|
|
8
|
+
} = require('../utils/database-validator');
|
|
9
|
+
const {
|
|
10
|
+
runPrismaGenerate,
|
|
11
|
+
checkDatabaseState,
|
|
12
|
+
runPrismaMigrate,
|
|
13
|
+
runPrismaDbPush,
|
|
14
|
+
getMigrationCommand,
|
|
15
|
+
} = require('@friggframework/core/database/utils/prisma-runner');
|
|
16
|
+
const {
|
|
17
|
+
getDatabaseUrlMissingError,
|
|
18
|
+
getDatabaseTypeNotConfiguredError,
|
|
19
|
+
getPrismaCommandError,
|
|
20
|
+
getDatabaseSetupSuccess,
|
|
21
|
+
} = require('../utils/error-messages');
|
|
22
|
+
|
|
23
|
+
function getDatabaseDisplayName(dbType) {
|
|
24
|
+
switch (dbType) {
|
|
25
|
+
case 'postgresql':
|
|
26
|
+
return 'PostgreSQL';
|
|
27
|
+
case 'mongodb':
|
|
28
|
+
return 'MongoDB';
|
|
29
|
+
case 'documentdb':
|
|
30
|
+
return 'AWS DocumentDB (MongoDB-compatible)';
|
|
31
|
+
default:
|
|
32
|
+
return dbType;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getPrismaRunnerDbType(dbType) {
|
|
37
|
+
return dbType === 'documentdb' ? 'mongodb' : dbType;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Database Setup Command
|
|
42
|
+
* Sets up the database for a Frigg application:
|
|
43
|
+
* - Validates configuration
|
|
44
|
+
* - Generates Prisma client
|
|
45
|
+
* - Runs migrations (PostgreSQL) or db push (MongoDB)
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
async function dbSetupCommand(options = {}) {
|
|
49
|
+
const verbose = options.verbose || false;
|
|
50
|
+
const stage = options.stage || process.env.STAGE || 'development';
|
|
51
|
+
|
|
52
|
+
console.log(chalk.blue('🔧 Frigg Database Setup'));
|
|
53
|
+
console.log(chalk.gray(`Stage: ${stage}\n`));
|
|
54
|
+
|
|
55
|
+
// Load environment variables from .env file
|
|
56
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
57
|
+
dotenv.config({ path: envPath });
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Step 1: Validate DATABASE_URL
|
|
61
|
+
if (verbose) {
|
|
62
|
+
console.log(chalk.gray('Step 1: Validating DATABASE_URL...'));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const urlValidation = validateDatabaseUrl();
|
|
66
|
+
if (!urlValidation.valid) {
|
|
67
|
+
console.error(getDatabaseUrlMissingError());
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (verbose) {
|
|
72
|
+
console.log(chalk.green('✓ DATABASE_URL found\n'));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Step 2: Determine database type from app definition
|
|
76
|
+
if (verbose) {
|
|
77
|
+
console.log(chalk.gray('Step 2: Determining database type...'));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const dbTypeResult = getDatabaseType();
|
|
81
|
+
if (dbTypeResult.error) {
|
|
82
|
+
console.error(chalk.red('❌ ' + dbTypeResult.error));
|
|
83
|
+
|
|
84
|
+
// Show stack trace in verbose mode for debugging
|
|
85
|
+
if (verbose && dbTypeResult.stack) {
|
|
86
|
+
console.error(chalk.gray('\nStack trace:'));
|
|
87
|
+
console.error(chalk.gray(dbTypeResult.stack));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.error(getDatabaseTypeNotConfiguredError());
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const dbType = dbTypeResult.dbType;
|
|
95
|
+
const dbDisplayName = getDatabaseDisplayName(dbType);
|
|
96
|
+
const isPostgres = dbType === 'postgresql';
|
|
97
|
+
const isDocumentDb = dbType === 'documentdb';
|
|
98
|
+
const isMongoFamily = dbType === 'mongodb' || isDocumentDb;
|
|
99
|
+
const runnerDbType = getPrismaRunnerDbType(dbType);
|
|
100
|
+
|
|
101
|
+
console.log(chalk.cyan(`Database type: ${dbDisplayName}`));
|
|
102
|
+
|
|
103
|
+
if (verbose) {
|
|
104
|
+
console.log(chalk.green(`✓ Using ${dbDisplayName}\n`));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Step 3: Check if Prisma client exists, generate if needed
|
|
108
|
+
if (verbose) {
|
|
109
|
+
console.log(chalk.gray('Step 3: Checking Prisma client...'));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const clientCheck = checkPrismaClientGenerated(dbType);
|
|
113
|
+
const forceRegenerate = options.force || false;
|
|
114
|
+
|
|
115
|
+
if (clientCheck.generated && !forceRegenerate) {
|
|
116
|
+
// Client already exists and --force not specified
|
|
117
|
+
console.log(
|
|
118
|
+
chalk.green(
|
|
119
|
+
'✓ Prisma client already exists (skipping generation)\n'
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
if (verbose) {
|
|
123
|
+
console.log(
|
|
124
|
+
chalk.gray(` Client location: ${clientCheck.path}\n`)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
// Client doesn't exist OR --force specified - generate it
|
|
129
|
+
if (forceRegenerate && clientCheck.generated) {
|
|
130
|
+
console.log(
|
|
131
|
+
chalk.yellow('⚠️ Forcing Prisma client regeneration...')
|
|
132
|
+
);
|
|
133
|
+
} else {
|
|
134
|
+
console.log(chalk.cyan('Generating Prisma client...'));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const generateResult = await runPrismaGenerate(
|
|
138
|
+
runnerDbType,
|
|
139
|
+
verbose
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
if (!generateResult.success) {
|
|
143
|
+
console.error(
|
|
144
|
+
getPrismaCommandError('generate', generateResult.error)
|
|
145
|
+
);
|
|
146
|
+
if (generateResult.output) {
|
|
147
|
+
console.error(chalk.gray(generateResult.output));
|
|
148
|
+
}
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
console.log(chalk.green('✓ Prisma client generated\n'));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Step 4: Check database state
|
|
156
|
+
// Note: We skip connection testing in db:setup because when using frigg:local,
|
|
157
|
+
// the CLI code runs from tmp/frigg but the client is in backend/node_modules,
|
|
158
|
+
// causing module resolution mismatches. Connection testing happens in frigg start.
|
|
159
|
+
if (verbose) {
|
|
160
|
+
console.log(chalk.gray('Step 4: Checking database state...'));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const stateCheck = await checkDatabaseState(runnerDbType);
|
|
164
|
+
|
|
165
|
+
// Step 5: Run migrations or db push
|
|
166
|
+
if (isPostgres) {
|
|
167
|
+
console.log(chalk.cyan('Running database migrations...'));
|
|
168
|
+
|
|
169
|
+
const migrationCommand = getMigrationCommand(stage);
|
|
170
|
+
|
|
171
|
+
if (verbose) {
|
|
172
|
+
console.log(
|
|
173
|
+
chalk.gray(`Using migration command: ${migrationCommand}`)
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (stateCheck.upToDate && migrationCommand === 'deploy') {
|
|
178
|
+
console.log(chalk.yellow('Database is already up-to-date'));
|
|
179
|
+
} else {
|
|
180
|
+
const migrateResult = await runPrismaMigrate(
|
|
181
|
+
migrationCommand,
|
|
182
|
+
verbose
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
if (!migrateResult.success) {
|
|
186
|
+
console.error(
|
|
187
|
+
getPrismaCommandError('migrate', migrateResult.error)
|
|
188
|
+
);
|
|
189
|
+
if (migrateResult.output) {
|
|
190
|
+
console.error(chalk.gray(migrateResult.output));
|
|
191
|
+
}
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
console.log(chalk.green('✓ Migrations applied\n'));
|
|
196
|
+
}
|
|
197
|
+
} else if (isMongoFamily) {
|
|
198
|
+
const targetName = isDocumentDb
|
|
199
|
+
? 'AWS DocumentDB (MongoDB-compatible)'
|
|
200
|
+
: 'MongoDB';
|
|
201
|
+
|
|
202
|
+
console.log(chalk.cyan(`Pushing schema to ${targetName}...`));
|
|
203
|
+
|
|
204
|
+
const pushResult = await runPrismaDbPush(verbose);
|
|
205
|
+
|
|
206
|
+
if (!pushResult.success) {
|
|
207
|
+
console.error(
|
|
208
|
+
getPrismaCommandError('db push', pushResult.error)
|
|
209
|
+
);
|
|
210
|
+
if (pushResult.output) {
|
|
211
|
+
console.error(chalk.gray(pushResult.output));
|
|
212
|
+
}
|
|
213
|
+
process.exit(1);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
console.log(chalk.green('✓ Schema pushed to database\n'));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Success!
|
|
220
|
+
console.log(getDatabaseSetupSuccess(dbType, stage));
|
|
221
|
+
} catch (error) {
|
|
222
|
+
console.error(chalk.red('\n❌ Database setup failed'));
|
|
223
|
+
console.error(chalk.gray(error.message));
|
|
224
|
+
|
|
225
|
+
if (verbose && error.stack) {
|
|
226
|
+
console.error(chalk.gray('\nStack trace:'));
|
|
227
|
+
console.error(chalk.gray(error.stack));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
console.error(chalk.yellow('\nTroubleshooting:'));
|
|
231
|
+
console.error(chalk.gray(' • Verify DATABASE_URL in your .env file'));
|
|
232
|
+
console.error(
|
|
233
|
+
chalk.gray(' • Check database is running and accessible')
|
|
234
|
+
);
|
|
235
|
+
console.error(
|
|
236
|
+
chalk.gray(' • Ensure app definition has database configuration')
|
|
237
|
+
);
|
|
238
|
+
console.error(
|
|
239
|
+
chalk.gray(' • Run with --verbose flag for more details')
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
module.exports = { dbSetupCommand };
|