@@ -394,4 +394,124 @@ void describe('convertSchemaToCDK', () => {
394
394
}
395
395
) ;
396
396
} ) ;
397
+
398
+ void it ( 'produces expected definition for MySQL schema with custom SSL cert' , ( ) => {
399
+ const schema = configure ( {
400
+ database : {
401
+ engine : 'mysql' ,
402
+ connectionUri : new TestBackendSecret ( 'SQL_CONNECTION_STRING' ) ,
403
+ sslCert : new TestBackendSecret ( 'CUSTOM_SSL_CERT' ) ,
404
+ } ,
405
+ } ) . schema ( {
406
+ post : a
407
+ . model ( {
408
+ id : a . integer ( ) . required ( ) ,
409
+ title : a . string ( ) ,
410
+ } )
411
+ . identifier ( [ 'id' ] )
412
+ . authorization ( ( allow ) => allow . publicApiKey ( ) ) ,
413
+ } ) ;
414
+
415
+ const modified = schema . addQueries ( {
416
+ oddList : a
417
+ . query ( )
418
+ . handler ( a . handler . inlineSql ( 'SELECT * from post where id % 2 = 1;' ) )
419
+ . returns ( a . ref ( 'post' ) )
420
+ . authorization ( ( allow ) => allow . publicApiKey ( ) ) ,
421
+ } ) ;
422
+
423
+ const convertedDefinition = convertSchemaToCDK (
424
+ modified ,
425
+ secretResolver ,
426
+ stableBackendIdentifiers
427
+ ) ;
428
+
429
+ assert . equal (
430
+ Object . values ( convertedDefinition . dataSourceStrategies ) . length ,
431
+ 1
432
+ ) ;
433
+ assert . deepEqual (
434
+ Object . values ( convertedDefinition . dataSourceStrategies ) [ 0 ] ,
435
+ {
436
+ customSqlStatements : { } ,
437
+ /* eslint-disable spellcheck/spell-checker */
438
+ dbConnectionConfig : {
439
+ connectionUriSsmPath : [
440
+ '/amplify/testBackendId/testBranchName-branch-e482a1c36f/SQL_CONNECTION_STRING' ,
441
+ '/amplify/shared/testBackendId/SQL_CONNECTION_STRING' ,
442
+ ] ,
443
+ sslCertConfig : {
444
+ ssmPath : [
445
+ '/amplify/testBackendId/testBranchName-branch-e482a1c36f/CUSTOM_SSL_CERT' ,
446
+ '/amplify/shared/testBackendId/CUSTOM_SSL_CERT' ,
447
+ ] ,
448
+ } ,
449
+ } ,
450
+ dbType : 'MYSQL' ,
451
+ name : '00034dcf3444861c3ca5mysql' ,
452
+ vpcConfiguration : undefined ,
453
+ /* eslint-enable spellcheck/spell-checker */
454
+ }
455
+ ) ;
456
+ } ) ;
457
+
458
+ void it ( 'produces expected definition for Postgresql schema with custom SSL cert' , ( ) => {
459
+ const schema = configure ( {
460
+ database : {
461
+ engine : 'postgresql' ,
462
+ connectionUri : new TestBackendSecret ( 'SQL_CONNECTION_STRING' ) ,
463
+ sslCert : new TestBackendSecret ( 'CUSTOM_SSL_CERT' ) ,
464
+ } ,
465
+ } ) . schema ( {
466
+ post : a
467
+ . model ( {
468
+ id : a . integer ( ) . required ( ) ,
469
+ title : a . string ( ) ,
470
+ } )
471
+ . identifier ( [ 'id' ] )
472
+ . authorization ( ( allow ) => allow . publicApiKey ( ) ) ,
473
+ } ) ;
474
+
475
+ const modified = schema . addQueries ( {
476
+ oddList : a
477
+ . query ( )
478
+ . handler ( a . handler . inlineSql ( 'SELECT * from post where id % 2 = 1;' ) )
479
+ . returns ( a . ref ( 'post' ) )
480
+ . authorization ( ( allow ) => allow . publicApiKey ( ) ) ,
481
+ } ) ;
482
+
483
+ const convertedDefinition = convertSchemaToCDK (
484
+ modified ,
485
+ secretResolver ,
486
+ stableBackendIdentifiers
487
+ ) ;
488
+
489
+ assert . equal (
490
+ Object . values ( convertedDefinition . dataSourceStrategies ) . length ,
491
+ 1
492
+ ) ;
493
+ assert . deepEqual (
494
+ Object . values ( convertedDefinition . dataSourceStrategies ) [ 0 ] ,
495
+ {
496
+ customSqlStatements : { } ,
497
+ /* eslint-disable spellcheck/spell-checker */
498
+ dbConnectionConfig : {
499
+ connectionUriSsmPath : [
500
+ '/amplify/testBackendId/testBranchName-branch-e482a1c36f/SQL_CONNECTION_STRING' ,
501
+ '/amplify/shared/testBackendId/SQL_CONNECTION_STRING' ,
502
+ ] ,
503
+ sslCertConfig : {
504
+ ssmPath : [
505
+ '/amplify/testBackendId/testBranchName-branch-e482a1c36f/CUSTOM_SSL_CERT' ,
506
+ '/amplify/shared/testBackendId/CUSTOM_SSL_CERT' ,
507
+ ] ,
508
+ } ,
509
+ } ,
510
+ dbType : 'POSTGRES' ,
511
+ name : '00034dcf3444861c3ca5postgresql' ,
512
+ vpcConfiguration : undefined ,
513
+ /* eslint-enable spellcheck/spell-checker */
514
+ }
515
+ ) ;
516
+ } ) ;
397
517
} ) ;
0 commit comments