@friggframework/devtools 2.0.0--canary.657.f16d20b.0 → 2.0.0--canary.737.83b4e17.0

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.
Files changed (104) hide show
  1. package/frigg-cli/README.md +115 -31
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  3. package/frigg-cli/__tests__/unit/commands/deploy.test.js +33 -24
  4. package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
  5. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  6. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  7. package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
  8. package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
  9. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
  11. package/frigg-cli/build-command/index.js +6 -0
  12. package/frigg-cli/deploy-command/index.js +6 -0
  13. package/frigg-cli/generate-command/index.js +1 -0
  14. package/frigg-cli/generate-iam-command.js +1 -0
  15. package/frigg-cli/index.js +22 -5
  16. package/frigg-cli/init-command/backend-first-handler.js +395 -551
  17. package/frigg-cli/init-command/deployment-modes.js +7 -0
  18. package/frigg-cli/init-command/index.js +82 -35
  19. package/frigg-cli/init-command/safe-path.js +58 -0
  20. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  21. package/frigg-cli/install-command/app-definition.js +174 -0
  22. package/frigg-cli/install-command/commit-changes.js +40 -8
  23. package/frigg-cli/install-command/environment-variables.js +15 -0
  24. package/frigg-cli/install-command/index.js +96 -21
  25. package/frigg-cli/install-command/install-package.js +77 -4
  26. package/frigg-cli/install-command/integration-file.js +20 -11
  27. package/frigg-cli/install-command/resolve-module.js +69 -0
  28. package/frigg-cli/install-command/template.js +102 -75
  29. package/frigg-cli/install-command/validate-package.js +36 -4
  30. package/frigg-cli/package.json +1 -1
  31. package/frigg-cli/start-command/index.js +4 -0
  32. package/frigg-cli/start-command/start-command.test.js +3 -0
  33. package/frigg-cli/templates/backend/README.md +267 -0
  34. package/frigg-cli/templates/backend/env.example +20 -0
  35. package/frigg-cli/templates/backend/gitignore +10 -0
  36. package/frigg-cli/templates/backend/index.js +114 -0
  37. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  38. package/frigg-cli/test/init-command.test.js +9 -2
  39. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  40. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  41. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
  42. package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
  43. package/frigg-cli/validate-command/checks/config.js +504 -0
  44. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  45. package/frigg-cli/validate-command/format-report.js +58 -0
  46. package/frigg-cli/validate-command/index.js +107 -0
  47. package/frigg-cli/validate-command/load-app-definition.js +105 -0
  48. package/frigg-cli/validate-command/schema-issues.js +154 -0
  49. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  50. package/infrastructure/README.md +32 -5
  51. package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
  52. package/infrastructure/__tests__/management-api-gateway-routes.test.js +284 -0
  53. package/infrastructure/__tests__/postgres-config.test.js +245 -836
  54. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +151 -0
  55. package/infrastructure/__tests__/scoped-environment.test.js +3 -0
  56. package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
  57. package/infrastructure/__tests__/template-generation.test.js +39 -8
  58. package/infrastructure/app-definition-schema-contract.test.js +634 -0
  59. package/infrastructure/create-frigg-infrastructure.js +4 -1
  60. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  61. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +80 -98
  62. package/infrastructure/domains/admin-scripts/admin-script-builder.js +8 -2
  63. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +52 -6
  64. package/infrastructure/domains/database/aurora-builder.js +13 -2
  65. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  66. package/infrastructure/domains/database/migration-builder.js +21 -2
  67. package/infrastructure/domains/database/migration-builder.test.js +61 -6
  68. package/infrastructure/domains/database/migration-engines.js +93 -0
  69. package/infrastructure/domains/database/migration-engines.test.js +142 -0
  70. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
  71. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
  72. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
  73. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
  74. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
  75. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
  76. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
  77. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
  78. package/infrastructure/domains/integration/integration-builder.js +2 -0
  79. package/infrastructure/domains/integration/integration-builder.test.js +22 -39
  80. package/infrastructure/domains/networking/vpc-builder.js +18 -8
  81. package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
  82. package/infrastructure/domains/scheduler/scheduler-builder.js +2 -19
  83. package/infrastructure/domains/scheduler/scheduler-builder.test.js +0 -99
  84. package/infrastructure/domains/security/iam-generator.js +112 -5
  85. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  86. package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
  87. package/infrastructure/domains/shared/environment-builder.js +31 -5
  88. package/infrastructure/domains/shared/environment-builder.test.js +93 -7
  89. package/infrastructure/domains/shared/lambda-architectures.js +113 -0
  90. package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
  91. package/infrastructure/domains/shared/utilities/base-definition-factory.js +39 -4
  92. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +85 -17
  93. package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
  94. package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
  95. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
  96. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
  97. package/infrastructure/infrastructure-composer.js +12 -1
  98. package/infrastructure/infrastructure-composer.test.js +339 -794
  99. package/infrastructure/scripts/build-prisma-layer.js +136 -50
  100. package/infrastructure/scripts/build-prisma-layer.test.js +128 -7
  101. package/infrastructure/scripts/build-time-discovery.test.js +18 -3
  102. package/package.json +12 -10
  103. package/frigg-cli/index.test.js +0 -158
  104. package/infrastructure/integration.test.js +0 -381
@@ -8,25 +8,49 @@ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 P
8
8
 
9
9
  ### Key Features
10
10
 
11
- - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-1.0 ACU default)
11
+ - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-4 ACU default)
12
12
  - **VPC Integration**: Deployed in same private subnets as Lambda functions
13
13
  - **Secrets Manager**: Automatic credential management and rotation
14
- - **Three Management Modes**: discover, create-new, use-existing
14
+ - **Management Modes**: discover, managed, use-existing, external (bring your own `DATABASE_URL`)
15
15
  - **Security**: Private subnet deployment with security group isolation
16
16
  - **High Availability**: Multi-AZ deployment with automatic failover
17
17
 
18
+ ### Bring your own PostgreSQL (`management: 'external'`)
19
+
20
+ To connect to a PostgreSQL that Frigg does not manage (any hosted provider, or
21
+ a database you run yourself), set `management: 'external'`. Frigg then creates
22
+ and discovers no database resources (no RDS/Aurora, no Secrets Manager secret)
23
+ and needs no VPC for the database; the app connects through `DATABASE_URL`.
24
+ This check takes precedence over a top-level `managementMode`. The migration
25
+ infrastructure is still composed, so migrations run against `DATABASE_URL`.
26
+
27
+ ```javascript
28
+ const appDefinition = {
29
+ vpc: { enable: false },
30
+ database: { postgres: { enable: true, management: 'external' } },
31
+ environment: { DATABASE_URL: true }, // read from the shell that runs `frigg deploy` (not .env)
32
+ };
33
+ ```
34
+
35
+ Use `sslmode=require` in the URL. This is the default for apps scaffolded by
36
+ `frigg init`.
37
+
18
38
  ---
19
39
 
20
40
  ## Configuration Schema
21
41
 
22
42
  ### App Definition Structure
23
43
 
44
+ These are the keys the Aurora builder reads (see `database.postgres` in
45
+ `packages/schemas/schemas/app-definition.schema.json`). `frigg validate`
46
+ rejects any other key under `database.postgres`.
47
+
24
48
  ```javascript
25
49
  // backend/index.js
26
50
  const appDefinition = {
27
51
  name: 'my-frigg-app',
28
52
 
29
- // Enable VPC deployment (required for Aurora)
53
+ // VPC Configuration (required for Aurora)
30
54
  vpc: {
31
55
  enable: true,
32
56
  },
@@ -36,34 +60,24 @@ const appDefinition = {
36
60
  postgres: {
37
61
  enable: true,
38
62
 
39
- // Management mode: 'discover' | 'create-new' | 'use-existing'
63
+ // 'discover' (also when omitted) | 'managed' | 'use-existing'
64
+ // Ignored when managementMode is 'managed' or 'existing'.
40
65
  management: 'discover',
41
66
 
42
- // Basic Configuration
43
- databaseName: 'frigg_db',
44
- masterUsername: 'frigg_admin',
45
-
46
- // Engine Configuration
47
- engine: 'aurora-postgresql',
48
- engineVersion: '15.3',
49
-
50
- // Scaling Configuration (Aurora Serverless v2)
51
- scaling: {
52
- minCapacity: 0.5, // ACUs (0.5 = ~1GB RAM, ~$43/month)
53
- maxCapacity: 1.0, // ACUs (1.0 = ~2GB RAM, ~$87/month)
54
- },
67
+ database: 'frigg', // database name (default 'frigg')
68
+ username: 'postgres', // master user (default 'postgres')
69
+ engineVersion: '15.13', // Aurora PostgreSQL version (default '15.13')
55
70
 
56
- // Backup Configuration
57
- backupRetentionDays: 7,
58
- preferredBackupWindow: '03:00-04:00',
71
+ // Aurora Serverless v2 capacity, in ACUs (0.5-128)
72
+ minCapacity: 0.5, // default 0.5
73
+ maxCapacity: 4, // default 4
59
74
 
60
- // Security & Advanced
61
- deletionProtection: true,
62
- enablePerformanceInsights: false,
75
+ publiclyAccessible: false, // default false (private subnets)
76
+ autoCreateCredentials: false, // discover only: create a secret for a discovered cluster
63
77
 
64
- // For use-existing mode
65
- clusterIdentifier: 'my-existing-cluster',
66
- secretArn: 'arn:aws:secretsmanager:...',
78
+ // use-existing only
79
+ // endpoint: 'mydb.cluster-abc123.us-east-1.rds.amazonaws.com',
80
+ // port: 5432,
67
81
  }
68
82
  }
69
83
  };
@@ -73,13 +87,17 @@ module.exports = {
73
87
  };
74
88
  ```
75
89
 
90
+ Backup retention (7 days), the backup and maintenance windows and deletion
91
+ settings are fixed by the builder and are not configurable through the app
92
+ definition.
93
+
76
94
  ---
77
95
 
78
96
  ## Management Modes
79
97
 
80
98
  ### 1. Discover Mode (Default)
81
99
 
82
- Automatically discovers existing Aurora clusters or creates new one if none found.
100
+ Discovers an existing Aurora cluster, or creates a new one in the stack if none is found.
83
101
 
84
102
  ```javascript
85
103
  database: {
@@ -100,63 +118,56 @@ database: {
100
118
 
101
119
  ---
102
120
 
103
- ### 2. Create-New Mode
121
+ ### 2. Managed Mode
104
122
 
105
- Always creates a new Aurora cluster, even if existing clusters are found.
123
+ Creates the cluster, instance, subnet group and secret in the stack.
106
124
 
107
125
  ```javascript
108
126
  database: {
109
127
  postgres: {
110
128
  enable: true,
111
- management: 'create-new',
112
-
113
- // Customization options
114
- databaseName: 'my_app_db',
115
- masterUsername: 'admin',
116
- engineVersion: '15.3',
117
- scaling: {
118
- minCapacity: 1.0,
119
- maxCapacity: 2.0,
120
- },
121
- backupRetentionDays: 14,
122
- deletionProtection: true,
129
+ management: 'managed',
130
+ minCapacity: 1,
131
+ maxCapacity: 2,
123
132
  }
124
133
  }
125
134
  ```
126
135
 
136
+ With the top-level `managementMode: 'managed'` (and `vpcIsolation: 'isolated'`),
137
+ Frigg manages the database per stage and `database.postgres.management` is ignored.
138
+
127
139
  **Best For**: Production environments where you want dedicated database resources.
128
140
 
129
141
  ---
130
142
 
131
143
  ### 3. Use-Existing Mode
132
144
 
133
- Uses a specific existing Aurora cluster by identifier.
145
+ Connects to an existing PostgreSQL endpoint without creating database resources.
134
146
 
135
147
  ```javascript
136
148
  database: {
137
149
  postgres: {
138
150
  enable: true,
139
151
  management: 'use-existing',
140
-
141
- // Required: existing cluster identifier
142
- clusterIdentifier: 'my-existing-aurora-cluster',
143
-
144
- // Optional: secret ARN (discovered if not provided)
145
- secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:my-db-secret',
146
-
147
- // Database name to connect to
148
- databaseName: 'frigg_db',
152
+ endpoint: 'my-cluster.cluster-abc123.us-east-1.rds.amazonaws.com', // required
153
+ port: 5432,
154
+ database: 'frigg_db',
155
+ username: 'frigg_admin',
149
156
  }
150
157
  }
151
158
  ```
152
159
 
160
+ To use an existing cluster by identifier instead, use the ownership form:
161
+ `ownership: { cluster: 'external', instance: 'external' }` with
162
+ `external: { clusterIdentifier, instanceIdentifier, secretArn }`.
163
+
153
164
  **Best For**: Shared database scenarios or when you manage Aurora outside of Frigg.
154
165
 
155
166
  ---
156
167
 
157
168
  ## Created AWS Resources
158
169
 
159
- When provisioning Aurora (`create-new` or `discover` mode without existing cluster), Frigg creates:
170
+ When provisioning Aurora (`managed`, or `discover` mode without an existing cluster), Frigg creates:
160
171
 
161
172
  ### 1. RDS DB Subnet Group
162
173
  - **Name**: `{service}-{stage}-db-subnet-group`
@@ -221,17 +232,15 @@ database: {
221
232
  database: {
222
233
  postgres: {
223
234
  enable: true,
224
- scaling: {
225
- minCapacity: 1.0, // Higher baseline for production
226
- maxCapacity: 4.0, // Handle traffic spikes
227
- },
228
- backupRetentionDays: 30, // Longer retention
229
- enablePerformanceInsights: true, // Monitoring
230
- deletionProtection: true, // Prevent accidental deletion
235
+ minCapacity: 1, // Higher baseline for production
236
+ maxCapacity: 4, // Handle traffic spikes
231
237
  }
232
238
  }
233
239
  ```
234
240
 
241
+ Backup retention, Performance Insights and deletion protection are not
242
+ configurable through the app definition; change them on the cluster.
243
+
235
244
  **Estimated Monthly Costs**:
236
245
  - **Baseline**: $87/month (1.0 ACU minimum)
237
246
  - **Peak Traffic**: $348/month (4.0 ACU maximum)
@@ -276,15 +285,9 @@ const users = await prismaClient.user.findMany();
276
285
 
277
286
  ### 4. Deletion Protection
278
287
 
279
- ```javascript
280
- database: {
281
- postgres: {
282
- deletionProtection: true, // Prevents accidental deletion
283
- }
284
- }
285
- ```
286
-
287
- **Important**: When enabled, you must manually disable deletion protection in AWS console before stack deletion.
288
+ Deletion protection is not configurable through the app definition. Enable it
289
+ on the cluster in the AWS console (or with the AWS CLI); you must then disable
290
+ it before deleting the stack.
288
291
 
289
292
  ---
290
293
 
@@ -384,7 +387,7 @@ DB_TYPE=postgresql
384
387
  database: {
385
388
  postgres: {
386
389
  enable: true,
387
- management: 'create-new',
390
+ management: 'managed',
388
391
  }
389
392
  }
390
393
  ```
@@ -411,7 +414,7 @@ DB_TYPE=postgresql
411
414
  database: {
412
415
  postgres: {
413
416
  enable: true,
414
- management: 'create-new',
417
+ management: 'managed',
415
418
  }
416
419
  }
417
420
  ```
@@ -456,13 +459,13 @@ DB_TYPE=postgresql
456
459
 
457
460
  **Error**:
458
461
  ```
459
- No Aurora cluster found in discovery mode. Set management to "create-new"...
462
+ No Aurora cluster found in discovery mode. Set management to "managed" or provide endpoint with "use-existing".
460
463
  ```
461
464
 
462
465
  **Solution**:
463
466
  1. Check VPC is enabled: `vpc.enable: true`
464
- 2. Set management mode: `management: 'create-new'`
465
- 3. Or provide cluster identifier: `clusterIdentifier: 'my-cluster'`
467
+ 2. Set management mode: `management: 'managed'`
468
+ 3. Or connect to a known endpoint: `management: 'use-existing'`, `endpoint: '...'`
466
469
 
467
470
  ---
468
471
 
@@ -544,41 +547,20 @@ Cannot create Aurora cluster: InsufficientDBInstanceCapacity
544
547
 
545
548
  ## Advanced Configuration
546
549
 
547
- ### Custom Backup Window
548
-
549
- ```javascript
550
- database: {
551
- postgres: {
552
- enable: true,
553
- backupRetentionDays: 30,
554
- preferredBackupWindow: '02:00-03:00', // UTC
555
- }
556
- }
557
- ```
558
-
559
- ### Enhanced Monitoring
560
-
561
- ```javascript
562
- database: {
563
- postgres: {
564
- enable: true,
565
- enablePerformanceInsights: true,
566
- // Performance Insights retention: 7 days (default) or 731 days
567
- }
568
- }
569
- ```
570
-
571
550
  ### Custom Engine Version
572
551
 
573
552
  ```javascript
574
553
  database: {
575
554
  postgres: {
576
555
  enable: true,
577
- engineVersion: '14.6', // Default: 15.3
556
+ engineVersion: '16.4', // Default: 15.13
578
557
  }
579
558
  }
580
559
  ```
581
560
 
561
+ The backup window, backup retention and Performance Insights are set by the
562
+ builder and are not configurable through the app definition.
563
+
582
564
  ### Read Replicas (Not Supported Yet)
583
565
 
584
566
  Frigg currently provisions a single Aurora instance. For read replicas:
@@ -16,6 +16,7 @@
16
16
  const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
17
17
  const { isScopedEnvironmentActive } = require('../shared/function-environments');
18
18
  const { nestedNodeModulesExcludes } = require('../shared/utilities/nested-node-modules');
19
+ const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
19
20
 
20
21
  class AdminScriptBuilder extends InfrastructureBuilder {
21
22
  constructor() {
@@ -141,10 +142,12 @@ class AdminScriptBuilder extends InfrastructureBuilder {
141
142
  }
142
143
 
143
144
  createAdminScriptQueue(result, appDefinition) {
145
+ // Registered under custom so the serverless plugin creates it in LocalStack offline
146
+ result.custom.AdminScriptQueue = '${self:service}-${self:provider.stage}-AdminScriptQueue';
144
147
  result.resources.AdminScriptQueue = {
145
148
  Type: 'AWS::SQS::Queue',
146
149
  Properties: {
147
- QueueName: '${self:service}-${self:provider.stage}-AdminScriptQueue',
150
+ QueueName: '${self:custom.AdminScriptQueue}',
148
151
  MessageRetentionPeriod: 86400, // 1 day
149
152
  VisibilityTimeout: 900, // 15 minutes (Lambda max)
150
153
  RedrivePolicy: {
@@ -264,10 +267,12 @@ class AdminScriptBuilder extends InfrastructureBuilder {
264
267
  }
265
268
 
266
269
  createReportQueue(result, appDefinition) {
270
+ // Registered under custom so the serverless plugin creates it in LocalStack offline
271
+ result.custom.ReportQueue = '${self:service}-${self:provider.stage}-ReportQueue';
267
272
  result.resources.ReportQueue = {
268
273
  Type: 'AWS::SQS::Queue',
269
274
  Properties: {
270
- QueueName: '${self:service}-${self:provider.stage}-ReportQueue',
275
+ QueueName: '${self:custom.ReportQueue}',
271
276
  MessageRetentionPeriod: 86400, // 1 day
272
277
  VisibilityTimeout: 900, // 15 minutes (Lambda max)
273
278
  RedrivePolicy: {
@@ -408,6 +413,7 @@ class AdminScriptBuilder extends InfrastructureBuilder {
408
413
  'node_modules/@friggframework/core/generated/**',
409
414
  ]
410
415
  : []),
416
+ ...bundledPrismaEngineExcludes(appDefinition, usePrismaLayer),
411
417
  ...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
412
418
  'node_modules/@friggframework/test/**',
413
419
  'node_modules/@friggframework/eslint-config/**',
@@ -10,6 +10,7 @@
10
10
 
11
11
  const { AdminScriptBuilder } = require('./admin-script-builder');
12
12
  const { ValidationResult } = require('../shared/base-builder');
13
+ const { itBundlesOnlyTheTargetPrismaEngine } = require('../../__tests__/helpers/bundled-prisma-engine-excludes');
13
14
 
14
15
  describe('AdminScriptBuilder', () => {
15
16
  let adminScriptBuilder;
@@ -168,6 +169,21 @@ describe('AdminScriptBuilder', () => {
168
169
  expect(result.resources.AdminScriptQueue.Properties.VisibilityTimeout).toBe(900); // 15 minutes
169
170
  });
170
171
 
172
+ it('registers AdminScriptQueue under custom so frigg start creates it locally', async () => {
173
+ const appDefinition = {
174
+ adminScripts: [{ Definition: { name: 'test-script' } }],
175
+ };
176
+
177
+ const result = await adminScriptBuilder.build(appDefinition, {});
178
+
179
+ expect(result.custom.AdminScriptQueue).toBe(
180
+ '${self:service}-${self:provider.stage}-AdminScriptQueue'
181
+ );
182
+ expect(result.resources.AdminScriptQueue.Properties.QueueName).toBe(
183
+ '${self:custom.AdminScriptQueue}'
184
+ );
185
+ });
186
+
171
187
  it('should configure AdminScriptQueue redrive policy to InternalErrorQueue', async () => {
172
188
  const appDefinition = {
173
189
  adminScripts: [
@@ -621,6 +637,21 @@ describe('AdminScriptBuilder', () => {
621
637
  });
622
638
 
623
639
  describe('reports (ReportQueue + reportExecutor)', () => {
640
+ it('registers ReportQueue under custom so frigg start creates it locally', async () => {
641
+ const appDefinition = {
642
+ reports: [{ Definition: { name: 'my-report', version: '1.0.0' } }],
643
+ };
644
+
645
+ const result = await adminScriptBuilder.build(appDefinition, {});
646
+
647
+ expect(result.custom.ReportQueue).toBe(
648
+ '${self:service}-${self:provider.stage}-ReportQueue'
649
+ );
650
+ expect(result.resources.ReportQueue.Properties.QueueName).toBe(
651
+ '${self:custom.ReportQueue}'
652
+ );
653
+ });
654
+
624
655
  it('creates ReportQueue + reportExecutor and wires REPORT_QUEUE_URL when reports are present', async () => {
625
656
  const appDefinition = {
626
657
  reports: [{ Definition: { name: 'my-report', version: '1.0.0' } }],
@@ -933,6 +964,21 @@ describe('AdminScriptBuilder', () => {
933
964
  });
934
965
  });
935
966
 
967
+ describe('Lambda architecture with usePrismaLambdaLayer=false', () => {
968
+ const functionsOf = async (usePrismaLambdaLayer, architecture) => {
969
+ const result = await adminScriptBuilder.build(
970
+ {
971
+ adminScripts: [{ Definition: { name: 'cleanup' } }],
972
+ usePrismaLambdaLayer,
973
+ ...(architecture && { architecture }),
974
+ },
975
+ {}
976
+ );
977
+ return Object.values(result.functions);
978
+ };
979
+ itBundlesOnlyTheTargetPrismaEngine(functionsOf);
980
+ });
981
+
936
982
  describe('getName()', () => {
937
983
  it('should return AdminScriptBuilder', () => {
938
984
  expect(adminScriptBuilder.getName()).toBe('AdminScriptBuilder');
@@ -995,23 +1041,23 @@ describe('AdminScriptBuilder nested node_modules (lambda.keepNestedNodeModules)'
995
1041
  result.functions.adminScriptRouter,
996
1042
  ];
997
1043
 
998
- it('excludes every nested node_modules by default', async () => {
1044
+ it('keeps nested node_modules by default, still excluding nested Frigg copies', async () => {
999
1045
  const result = await new AdminScriptBuilder().build(appDefinition(), {});
1000
1046
 
1001
1047
  for (const fn of executorAndRouter(result)) {
1002
- expect(fn.package.exclude).toContain('node_modules/**/node_modules/**');
1048
+ expect(fn.package.exclude).not.toContain('node_modules/**/node_modules/**');
1049
+ expect(fn.package.exclude).toContain('node_modules/**/node_modules/@friggframework/**');
1003
1050
  }
1004
1051
  });
1005
1052
 
1006
- it('keeps nested node_modules when the app opts in, still excluding nested Frigg copies', async () => {
1053
+ it('excludes every nested node_modules when the app opts out', async () => {
1007
1054
  const result = await new AdminScriptBuilder().build(
1008
- appDefinition({ keepNestedNodeModules: true }),
1055
+ appDefinition({ keepNestedNodeModules: false }),
1009
1056
  {}
1010
1057
  );
1011
1058
 
1012
1059
  for (const fn of executorAndRouter(result)) {
1013
- expect(fn.package.exclude).not.toContain('node_modules/**/node_modules/**');
1014
- expect(fn.package.exclude).toContain('node_modules/**/node_modules/@friggframework/**');
1060
+ expect(fn.package.exclude).toContain('node_modules/**/node_modules/**');
1015
1061
  }
1016
1062
  });
1017
1063
  });
@@ -64,7 +64,18 @@ class AuroraBuilder extends InfrastructureBuilder {
64
64
  return false;
65
65
  }
66
66
 
67
- return appDefinition.database?.postgres?.enable === true;
67
+ const postgres = appDefinition.database?.postgres;
68
+
69
+ // management='external': the app brings its own PostgreSQL (any
70
+ // provider) and connects through DATABASE_URL. Frigg creates and
71
+ // discovers no database resources and needs no VPC for it. This
72
+ // check precedes managementMode, which otherwise always manages
73
+ // Aurora. Migrations still run (MigrationBuilder) against DATABASE_URL.
74
+ if (postgres?.management === 'external') {
75
+ return false;
76
+ }
77
+
78
+ return postgres?.enable === true;
68
79
  }
69
80
 
70
81
  getDependencies() {
@@ -82,7 +93,7 @@ class AuroraBuilder extends InfrastructureBuilder {
82
93
  const dbConfig = appDefinition.database.postgres;
83
94
 
84
95
  // Validate management mode
85
- const validModes = ['discover', 'managed', 'use-existing'];
96
+ const validModes = ['discover', 'managed', 'use-existing', 'external'];
86
97
  const management = dbConfig.management || 'discover';
87
98
  if (!validModes.includes(management)) {
88
99
  result.addError(`Invalid database.postgres.management: "${management}"`);
@@ -42,6 +42,28 @@ describe('AuroraBuilder', () => {
42
42
  expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
43
43
  });
44
44
 
45
+ it('should return false when Postgres is external (bring your own DATABASE_URL)', () => {
46
+ const appDefinition = {
47
+ database: {
48
+ postgres: { enable: true, management: 'external' },
49
+ },
50
+ };
51
+
52
+ expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
53
+ });
54
+
55
+ it('should return false for external Postgres even with managementMode=managed', () => {
56
+ const appDefinition = {
57
+ managementMode: 'managed',
58
+ vpcIsolation: 'isolated',
59
+ database: {
60
+ postgres: { enable: true, management: 'external' },
61
+ },
62
+ };
63
+
64
+ expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
65
+ });
66
+
45
67
  it('should return false when database is not defined', () => {
46
68
  const appDefinition = {};
47
69
 
@@ -16,6 +16,12 @@
16
16
  const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
17
17
  const { isScopedEnvironmentActive } = require('../shared/function-environments');
18
18
  const { nestedNodeModulesExcludes } = require('../shared/utilities/nested-node-modules');
19
+ const {
20
+ resolveLambdaArchitecture,
21
+ PRISMA_ENGINES_PACKAGE_DIR,
22
+ prismaEngineFileNames,
23
+ foreignPrismaEngineExcludes,
24
+ } = require('../shared/lambda-architectures');
19
25
  const { MigrationResourceResolver } = require('./migration-resolver');
20
26
  const { createEmptyDiscoveryResult, ResourceOwnership } = require('../shared/types');
21
27
 
@@ -239,6 +245,9 @@ class MigrationBuilder extends InfrastructureBuilder {
239
245
  async createFunctionDefinitions(result, usePrismaLayer = true, appDefinition = {}) {
240
246
  console.log(' 🔍 DEBUG: createFunctionDefinitions called');
241
247
  console.log(' 🔍 DEBUG: result.functions is:', typeof result.functions, result.functions);
248
+ const architecture = resolveLambdaArchitecture(appDefinition);
249
+ const engineExcludes = foreignPrismaEngineExcludes(architecture.name);
250
+ const engines = prismaEngineFileNames(architecture.prismaBinaryTarget);
242
251
  // Migration WORKER package config (needs Prisma CLI WASM files)
243
252
  const migrationWorkerPackageConfig = {
244
253
  individually: true,
@@ -293,12 +302,14 @@ class MigrationBuilder extends InfrastructureBuilder {
293
302
  'node_modules/@friggframework/core/handlers/routers/integration-*.js',
294
303
  'node_modules/@friggframework/core/handlers/workers/integration-*.js',
295
304
 
296
- // Exclude wrong OS binaries
305
+ // Exclude the engines of every platform and architecture this
306
+ // stack does not run on
297
307
  '**/query-engine-darwin*',
298
308
  '**/schema-engine-darwin*',
299
309
  '**/libquery_engine-darwin*',
300
310
  '**/*-darwin-arm64*',
301
311
  '**/*-darwin*',
312
+ ...engineExcludes,
302
313
 
303
314
  // Migration worker DOES need Prisma CLI WASM files (for migrate deploy)
304
315
  // Only exclude runtime engine WASM (query engine internals)
@@ -385,12 +396,14 @@ class MigrationBuilder extends InfrastructureBuilder {
385
396
  'node_modules/@friggframework/core/handlers/routers/integration-*.js',
386
397
  'node_modules/@friggframework/core/handlers/workers/**',
387
398
 
388
- // Exclude wrong OS binaries
399
+ // Exclude the engines of every platform and architecture this
400
+ // stack does not run on
389
401
  '**/query-engine-darwin*',
390
402
  '**/schema-engine-darwin*',
391
403
  '**/libquery_engine-darwin*',
392
404
  '**/*-darwin-arm64*',
393
405
  '**/*-darwin*',
406
+ ...engineExcludes,
394
407
 
395
408
  // Router doesn't run migrations - exclude ALL WASM files
396
409
  '**/runtime/*.wasm',
@@ -438,6 +451,12 @@ class MigrationBuilder extends InfrastructureBuilder {
438
451
  environment: {
439
452
  // Ensure migration functions get DATABASE_URL from provider.environment
440
453
  // Note: Serverless will merge this with provider.environment
454
+
455
+ // Pin the migrate CLI to the shipped engines. With these set,
456
+ // Prisma neither downloads an engine at cold start (into the
457
+ // read-only /var/task) nor picks another file.
458
+ PRISMA_SCHEMA_ENGINE_BINARY: `/var/task/${PRISMA_ENGINES_PACKAGE_DIR}/${engines.schemaEngine}`,
459
+ PRISMA_QUERY_ENGINE_LIBRARY: `/var/task/${PRISMA_ENGINES_PACKAGE_DIR}/${engines.queryEngineLibrary}`,
441
460
  },
442
461
  events: [
443
462
  {