@@ -9,7 +9,7 @@ function run(overrides) {
99 process . execPath ,
1010 [ fileURLToPath ( new URL ( "./migrate-on-deploy.mjs" , import . meta. url ) ) ] ,
1111 {
12- env : { ...process . env , DATABASE_URL_UNPOOLED : "" , ...overrides } ,
12+ env : { ...process . env , DATABASE_URL_UNPOOLED : "" , DATABASE_URL : "" , ...overrides } ,
1313 stdio : [ "ignore" , "pipe" , "pipe" ] ,
1414 } ,
1515 ) ;
@@ -25,28 +25,44 @@ function run(overrides) {
2525 } ) ;
2626}
2727
28- test ( "local and preview builds never require or connect to production storage" , async ( ) => {
29- for ( const VERCEL_ENV of [ "" , "preview" , " development"] ) {
28+ test ( "local builds never require or connect to deployment storage" , async ( ) => {
29+ for ( const VERCEL_ENV of [ "" , "development" ] ) {
3030 assert . equal ( ( await run ( { VERCEL_ENV , DATABASE_URL_UNPOOLED : "invalid" } ) ) . code , 0 ) ;
3131 }
3232} ) ;
3333
34- test ( "production fails closed without a direct connection" , async ( ) => {
35- assert . equal ( ( await run ( { VERCEL_ENV : "production" } ) ) . code , 1 ) ;
36- const result = await run ( {
37- VERCEL_ENV : "production" ,
38- DATABASE_URL_UNPOOLED : "postgres://user:secret@ep-example-pooler.neon.tech/neondb" ,
39- } ) ;
40- assert . equal ( result . code , 1 ) ;
41- assert . ok ( ! result . output . includes ( "secret" ) ) ;
34+ test ( "deployment builds fail closed without matching direct and runtime connections" , async ( ) => {
35+ for ( const VERCEL_ENV of [ "production" , "preview" ] ) {
36+ assert . equal ( ( await run ( { VERCEL_ENV } ) ) . code , 1 ) ;
37+ const result = await run ( {
38+ VERCEL_ENV ,
39+ DATABASE_URL_UNPOOLED : "postgres://user:secret@ep-example-pooler.neon.tech/neondb" ,
40+ DATABASE_URL : "postgres://user:secret@ep-example-pooler.neon.tech/neondb" ,
41+ } ) ;
42+ assert . equal ( result . code , 1 ) ;
43+ assert . ok ( ! result . output . includes ( "secret" ) ) ;
44+ const mismatch = await run ( {
45+ VERCEL_ENV ,
46+ DATABASE_URL : "postgres://user:secret@ep-preview-pooler.neon.tech/neondb" ,
47+ DATABASE_URL_UNPOOLED : "postgres://user:secret@ep-main.neon.tech/neondb" ,
48+ } ) ;
49+ assert . equal ( mismatch . code , 1 ) ;
50+ assert . match ( mismatch . output , / s a m e d a t a b a s e b r a n c h / ) ;
51+ }
4252} ) ;
4353
4454test (
45- "production migration retries and concurrent builds are idempotent" ,
55+ "preview and production migration retries are idempotent" ,
4656 { skip : ! process . env . TEST_DATABASE_URL } ,
4757 async ( ) => {
48- const env = { VERCEL_ENV : "production" , DATABASE_URL_UNPOOLED : process . env . TEST_DATABASE_URL } ;
49- for ( const result of await Promise . all ( [ run ( env ) , run ( env ) ] ) ) {
58+ const env = {
59+ DATABASE_URL : process . env . TEST_DATABASE_URL ,
60+ DATABASE_URL_UNPOOLED : process . env . TEST_DATABASE_URL ,
61+ } ;
62+ for ( const result of await Promise . all ( [
63+ run ( { ...env , VERCEL_ENV : "preview" } ) ,
64+ run ( { ...env , VERCEL_ENV : "production" } ) ,
65+ ] ) ) {
5066 assert . equal ( result . code , 0 , result . output ) ;
5167 assert . match ( result . output , / s c h e m a i s u p t o d a t e / ) ;
5268 }
0 commit comments