@@ -401,6 +401,81 @@ describe.concurrent('deploy command', () => {
401401 } )
402402 } )
403403
404+ test ( 'should deploy DB migration files when internal migrations directory exists' , async ( t ) => {
405+ await withMockDeploy ( async ( mockApi , deployState ) => {
406+ await withSiteBuilder ( t , async ( builder ) => {
407+ builder
408+ . withContentFile ( {
409+ path : 'public/index.html' ,
410+ content : '<h1>Site with DB migrations</h1>' ,
411+ } )
412+ . withContentFile ( {
413+ path : '.netlify/internal/db/migrations/0000_oval_proudstar/migration.sql' ,
414+ content : 'CREATE TABLE users (id serial PRIMARY KEY);' ,
415+ } )
416+ . withContentFile ( {
417+ path : '.netlify/internal/db/migrations/0001_second_migration/migration.sql' ,
418+ content : 'ALTER TABLE users ADD COLUMN name text;' ,
419+ } )
420+ . withNetlifyToml ( {
421+ config : {
422+ build : { publish : 'public' } ,
423+ } ,
424+ } )
425+
426+ await builder . build ( )
427+
428+ const deploy = await callCli (
429+ [ 'deploy' , '--json' , '--no-build' , '--dir' , 'public' ] ,
430+ getCLIOptions ( { apiUrl : mockApi . apiUrl , builder } ) ,
431+ ) . then ( parseDeploy )
432+
433+ expect ( deploy . site_id ) . toBe ( 'site_id' )
434+
435+ const body = deployState . getDeployBody ( )
436+ expect ( body ) . not . toBeNull ( )
437+
438+ const fileKeys = Object . keys ( body ! . files ! )
439+ expect ( fileKeys ) . toContain ( 'index.html' )
440+ expect ( fileKeys ) . toContain ( '.netlify/internal/db/migrations/0000_oval_proudstar/migration.sql' )
441+ expect ( fileKeys ) . toContain ( '.netlify/internal/db/migrations/0001_second_migration/migration.sql' )
442+ } )
443+ } )
444+ } )
445+
446+ test ( 'should not include DB migrations in deploy when internal migrations directory does not exist' , async ( t ) => {
447+ await withMockDeploy ( async ( mockApi , deployState ) => {
448+ await withSiteBuilder ( t , async ( builder ) => {
449+ builder
450+ . withContentFile ( {
451+ path : 'public/index.html' ,
452+ content : '<h1>Site without DB migrations</h1>' ,
453+ } )
454+ . withNetlifyToml ( {
455+ config : {
456+ build : { publish : 'public' } ,
457+ } ,
458+ } )
459+
460+ await builder . build ( )
461+
462+ const deploy = await callCli (
463+ [ 'deploy' , '--json' , '--no-build' , '--dir' , 'public' ] ,
464+ getCLIOptions ( { apiUrl : mockApi . apiUrl , builder } ) ,
465+ ) . then ( parseDeploy )
466+
467+ expect ( deploy . site_id ) . toBe ( 'site_id' )
468+
469+ const body = deployState . getDeployBody ( )
470+ expect ( body ) . not . toBeNull ( )
471+
472+ const fileKeys = Object . keys ( body ! . files ! )
473+ expect ( fileKeys ) . toContain ( 'index.html' )
474+ expect ( fileKeys . some ( ( key ) => key . includes ( 'db/migrations' ) ) ) . toBe ( false )
475+ } )
476+ } )
477+ } )
478+
404479 test ( 'runs build command before deploy by default' , async ( t ) => {
405480 await withMockDeploy ( async ( mockApi , deployState ) => {
406481 await withSiteBuilder ( t , async ( builder ) => {
0 commit comments