@friggframework/devtools 2.0.0--canary.474.898a56c.0 → 2.0.0--canary.474.6a0bba7.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.
@@ -58,6 +58,7 @@ class MigrationBuilder extends InfrastructureBuilder {
58
58
  appDefinition = this.translateLegacyConfig(appDefinition, discoveredResources);
59
59
 
60
60
  const result = {
61
+ functions: {}, // Lambda function definitions
61
62
  resources: {},
62
63
  iamStatements: [],
63
64
  environment: {},
@@ -227,11 +228,208 @@ class MigrationBuilder extends InfrastructureBuilder {
227
228
  }
228
229
  }
229
230
 
231
+ /**
232
+ * Create Lambda function definitions for database migrations
233
+ * Based on refactor/add-better-support-for-commands branch implementation
234
+ */
235
+ async createFunctionDefinitions(result) {
236
+ console.log(' 🔍 DEBUG: createFunctionDefinitions called');
237
+ console.log(' 🔍 DEBUG: result.functions is:', typeof result.functions, result.functions);
238
+ // Migration WORKER package config (needs Prisma CLI WASM files)
239
+ const migrationWorkerPackageConfig = {
240
+ exclude: [
241
+ // Exclude AWS SDK (provided by Lambda runtime)
242
+ 'node_modules/aws-sdk/**',
243
+ 'node_modules/@aws-sdk/**',
244
+ // Exclude build tools
245
+ 'node_modules/esbuild/**',
246
+ 'node_modules/@esbuild/**',
247
+ 'node_modules/typescript/**',
248
+ 'node_modules/webpack/**',
249
+ 'node_modules/osls/**',
250
+ 'node_modules/serverless-esbuild/**',
251
+ 'node_modules/serverless-jetpack/**',
252
+ 'node_modules/serverless-offline/**',
253
+ 'node_modules/serverless-offline-sqs/**',
254
+ 'node_modules/serverless-dotenv-plugin/**',
255
+ 'node_modules/serverless-kms-grants/**',
256
+ 'node_modules/@friggframework/test/**',
257
+ 'node_modules/@friggframework/eslint-config/**',
258
+ 'node_modules/@friggframework/prettier-config/**',
259
+ 'node_modules/@friggframework/devtools/**',
260
+ 'node_modules/@friggframework/serverless-plugin/**',
261
+ 'node_modules/jest/**',
262
+ 'node_modules/prettier/**',
263
+ 'node_modules/eslint/**',
264
+ 'node_modules/@friggframework/core/generated/prisma-mongodb/**',
265
+ 'node_modules/@friggframework/core/integrations/**',
266
+ 'node_modules/@friggframework/core/user/**',
267
+ '**/query-engine-darwin*',
268
+ '**/schema-engine-darwin*',
269
+ '**/libquery_engine-darwin*',
270
+ '**/*-darwin-arm64*',
271
+ '**/*-darwin*',
272
+ // Migration worker DOES need Prisma CLI WASM files (for migrate deploy)
273
+ // Only exclude runtime engine WASM (query engine internals)
274
+ '**/runtime/*.wasm',
275
+ // Additional size optimizations
276
+ '**/*.map',
277
+ '**/*.md',
278
+ '**/examples/**',
279
+ '**/docs/**',
280
+ '**/*.d.ts',
281
+ 'src/**',
282
+ 'test/**',
283
+ 'layers/**',
284
+ 'coverage/**',
285
+ 'deploy.log',
286
+ '.env.backup',
287
+ 'docker-compose.yml',
288
+ 'jest.config.js',
289
+ 'jest.unit.config.js',
290
+ 'package-lock.json',
291
+ '**/*.test.js',
292
+ '**/*.spec.js',
293
+ '**/.claude-flow/**',
294
+ '**/.swarm/**',
295
+ ],
296
+ };
297
+
298
+ // Migration ROUTER package config (lighter, no Prisma CLI needed)
299
+ const migrationRouterPackageConfig = {
300
+ exclude: [
301
+ // Exclude AWS SDK (provided by Lambda runtime)
302
+ 'node_modules/aws-sdk/**',
303
+ 'node_modules/@aws-sdk/**',
304
+ // Exclude build tools
305
+ 'node_modules/esbuild/**',
306
+ 'node_modules/@esbuild/**',
307
+ 'node_modules/typescript/**',
308
+ 'node_modules/webpack/**',
309
+ 'node_modules/serverless-esbuild/**',
310
+ 'node_modules/serverless-jetpack/**',
311
+ 'node_modules/serverless-offline/**',
312
+ 'node_modules/serverless-offline-sqs/**',
313
+ 'node_modules/serverless-dotenv-plugin/**',
314
+ 'node_modules/serverless-kms-grants/**',
315
+ 'node_modules/@friggframework/test/**',
316
+ 'node_modules/@friggframework/eslint-config/**',
317
+ 'node_modules/@friggframework/prettier-config/**',
318
+ 'node_modules/@friggframework/devtools/**',
319
+ 'node_modules/@friggframework/serverless-plugin/**',
320
+ 'node_modules/jest/**',
321
+ 'node_modules/prettier/**',
322
+ 'node_modules/eslint/**',
323
+ 'node_modules/@friggframework/core/generated/prisma-mongodb/**',
324
+ 'node_modules/@friggframework/core/user/**',
325
+ '**/query-engine-darwin*',
326
+ '**/schema-engine-darwin*',
327
+ '**/libquery_engine-darwin*',
328
+ '**/*-darwin-arm64*',
329
+ '**/*-darwin*',
330
+ // Router doesn't run migrations - exclude ALL WASM files
331
+ '**/runtime/*.wasm',
332
+ '**/*.wasm*',
333
+ // Additional size optimizations
334
+ '**/*.map',
335
+ '**/*.md',
336
+ '**/test/**',
337
+ '**/tests/**',
338
+ '**/__tests__/**',
339
+ '**/examples/**',
340
+ '**/docs/**',
341
+ '**/*.d.ts',
342
+ 'src/**',
343
+ 'test/**',
344
+ 'layers/**',
345
+ 'coverage/**',
346
+ 'deploy.log',
347
+ '.env.backup',
348
+ 'docker-compose.yml',
349
+ 'jest.config.js',
350
+ 'jest.unit.config.js',
351
+ 'package-lock.json',
352
+ '**/*.test.js',
353
+ '**/*.spec.js',
354
+ '**/.claude-flow/**',
355
+ '**/.swarm/**',
356
+ ],
357
+ };
358
+
359
+ // Create migration worker Lambda (triggered by SQS)
360
+ console.log(' 🔍 DEBUG: About to create dbMigrationWorker...');
361
+ result.functions.dbMigrationWorker = {
362
+ handler: 'node_modules/@friggframework/core/handlers/workers/db-migration.handler',
363
+ layers: [{ Ref: 'PrismaLambdaLayer' }], // Use layer for Prisma client runtime
364
+ skipEsbuild: true,
365
+ timeout: 900, // 15 minutes for long migrations
366
+ memorySize: 1024, // Extra memory for Prisma operations
367
+ reservedConcurrency: 1, // Process one migration at a time (critical for safety)
368
+ description: 'Database migration worker (triggered by SQS queue)',
369
+ package: migrationWorkerPackageConfig,
370
+ environment: {
371
+ // Ensure migration functions get DATABASE_URL from provider.environment
372
+ // Note: Serverless will merge this with provider.environment
373
+ },
374
+ events: [
375
+ {
376
+ sqs: {
377
+ arn: { 'Fn::GetAtt': ['DbMigrationQueue', 'Arn'] },
378
+ batchSize: 1, // Process one migration at a time
379
+ },
380
+ },
381
+ ],
382
+ };
383
+ console.log(' ✓ Created dbMigrationWorker function');
384
+ console.log(' 🔍 DEBUG: result.functions.dbMigrationWorker is:', !!result.functions.dbMigrationWorker);
385
+
386
+ // Create migration router Lambda (HTTP API)
387
+ console.log(' 🔍 DEBUG: About to create dbMigrationRouter...');
388
+ result.functions.dbMigrationRouter = {
389
+ handler: 'node_modules/@friggframework/core/handlers/routers/db-migration.handler',
390
+ // No Prisma layer needed - router doesn't access database
391
+ skipEsbuild: true,
392
+ timeout: 30, // Router just queues jobs, doesn't run migrations
393
+ memorySize: 512,
394
+ description: 'Database migration HTTP API (POST to trigger, GET to check status)',
395
+ package: migrationRouterPackageConfig,
396
+ environment: {
397
+ // Ensure migration functions get DATABASE_URL from provider.environment
398
+ // Note: Serverless will merge this with provider.environment
399
+ },
400
+ events: [
401
+ { httpApi: { path: '/db-migrate/status', method: 'GET' } },
402
+ { httpApi: { path: '/db-migrate', method: 'POST' } },
403
+ { httpApi: { path: '/db-migrate/{processId}', method: 'GET' } },
404
+ ],
405
+ };
406
+ console.log(' ✓ Created dbMigrationRouter function');
407
+
408
+ // Add worker function name to router environment (for Lambda invocation)
409
+ // Router needs this to invoke worker for database state checks
410
+ if (!result.functions.dbMigrationRouter.environment) {
411
+ result.functions.dbMigrationRouter.environment = {};
412
+ }
413
+ result.functions.dbMigrationRouter.environment.WORKER_FUNCTION_NAME = {
414
+ Ref: 'DbMigrationWorkerLambdaFunction',
415
+ };
416
+ console.log(' ✓ Added WORKER_FUNCTION_NAME environment variable to router');
417
+ console.log(' 🔍 DEBUG: result.functions keys:', Object.keys(result.functions));
418
+ console.log(' 🔍 DEBUG: Exiting createFunctionDefinitions');
419
+ }
420
+
230
421
  /**
231
422
  * Create migration infrastructure CloudFormation resources
232
- * Only creates S3 bucket and SQS queue - Lambda functions are defined in serverless.yml
423
+ * Creates S3 bucket, SQS queue, and Lambda function definitions
233
424
  */
234
425
  async createMigrationInfrastructure(appDefinition, result) {
426
+ console.log(' 🔍 DEBUG: createMigrationInfrastructure called');
427
+ console.log(' 🔍 DEBUG: result object before createFunctionDefinitions:', Object.keys(result));
428
+
429
+ // Create Lambda function definitions first (they reference the queue)
430
+ await this.createFunctionDefinitions(result);
431
+
432
+ console.log(' 🔍 DEBUG: result.functions after createFunctionDefinitions:', Object.keys(result.functions || {}));
235
433
 
236
434
  // Create S3 bucket for migration status tracking
237
435
  result.resources.FriggMigrationStatusBucket = {
@@ -210,6 +210,79 @@ describe('MigrationBuilder', () => {
210
210
  })
211
211
  );
212
212
  });
213
+
214
+ it('should create dbMigrationRouter function definition', async () => {
215
+ const appDef = {
216
+ database: {
217
+ postgres: {
218
+ enable: true,
219
+ },
220
+ },
221
+ };
222
+
223
+ const result = await builder.build(appDef, {});
224
+
225
+ expect(result.functions.dbMigrationRouter).toBeDefined();
226
+ expect(result.functions.dbMigrationRouter.handler).toBe(
227
+ 'node_modules/@friggframework/core/handlers/routers/db-migration.handler'
228
+ );
229
+ expect(result.functions.dbMigrationRouter.skipEsbuild).toBe(true);
230
+ expect(result.functions.dbMigrationRouter.timeout).toBe(30);
231
+ expect(result.functions.dbMigrationRouter.memorySize).toBe(512);
232
+ expect(result.functions.dbMigrationRouter.events).toHaveLength(3);
233
+ expect(result.functions.dbMigrationRouter.events).toContainEqual({
234
+ httpApi: { path: '/db-migrate/status', method: 'GET' },
235
+ });
236
+ expect(result.functions.dbMigrationRouter.events).toContainEqual({
237
+ httpApi: { path: '/db-migrate', method: 'POST' },
238
+ });
239
+ expect(result.functions.dbMigrationRouter.events).toContainEqual({
240
+ httpApi: { path: '/db-migrate/{processId}', method: 'GET' },
241
+ });
242
+ });
243
+
244
+ it('should create dbMigrationWorker function definition', async () => {
245
+ const appDef = {
246
+ database: {
247
+ postgres: {
248
+ enable: true,
249
+ },
250
+ },
251
+ };
252
+
253
+ const result = await builder.build(appDef, {});
254
+
255
+ expect(result.functions.dbMigrationWorker).toBeDefined();
256
+ expect(result.functions.dbMigrationWorker.handler).toBe(
257
+ 'node_modules/@friggframework/core/handlers/workers/db-migration.handler'
258
+ );
259
+ expect(result.functions.dbMigrationWorker.skipEsbuild).toBe(true);
260
+ expect(result.functions.dbMigrationWorker.reservedConcurrency).toBe(1);
261
+ expect(result.functions.dbMigrationWorker.timeout).toBe(900);
262
+ expect(result.functions.dbMigrationWorker.memorySize).toBe(1024);
263
+ expect(result.functions.dbMigrationWorker.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
264
+ expect(result.functions.dbMigrationWorker.events).toHaveLength(1);
265
+ expect(result.functions.dbMigrationWorker.events[0].sqs).toEqual({
266
+ arn: { 'Fn::GetAtt': ['DbMigrationQueue', 'Arn'] },
267
+ batchSize: 1,
268
+ });
269
+ });
270
+
271
+ it('should add WORKER_FUNCTION_NAME to router environment', async () => {
272
+ const appDef = {
273
+ database: {
274
+ postgres: {
275
+ enable: true,
276
+ },
277
+ },
278
+ };
279
+
280
+ const result = await builder.build(appDef, {});
281
+
282
+ expect(result.functions.dbMigrationRouter.environment.WORKER_FUNCTION_NAME).toEqual({
283
+ Ref: 'DbMigrationWorkerLambdaFunction',
284
+ });
285
+ });
213
286
  });
214
287
 
215
288
  describe('getName', () => {