@@ -346,7 +346,7 @@ describe('createMigrationHandler with missing D1 binding', () => {
346346describe ( 'createMigrationHandler D1 execution' , ( ) => {
347347 const proxyToken = 'test-token-123' ;
348348
349- function createMockD1 ( ) {
349+ function createMockD1 ( options ?: { failExec ?: ( sql : string ) => Error | undefined } ) {
350350 const calls = {
351351 batch : 0 ,
352352 exec : [ ] as Array < string > ,
@@ -361,6 +361,10 @@ describe('createMigrationHandler D1 execution', () => {
361361 } ,
362362 async exec ( sql : string ) {
363363 calls . exec . push ( sql ) ;
364+ const error = options ?. failExec ?.( sql ) ;
365+ if ( error ) {
366+ throw error ;
367+ }
364368 } ,
365369 prepare ( sql : string ) {
366370 let bound : Array < unknown > = [ ] ;
@@ -428,6 +432,49 @@ describe('createMigrationHandler D1 execution', () => {
428432 expect ( calls . batch ) . toBe ( 0 ) ;
429433 } ) ;
430434
435+ it ( 'applies scaffolded multiline single-statement D1 migrations without raw exec' , async ( ) => {
436+ const sql = [
437+ 'CREATE TABLE `posts` (' ,
438+ '\t`id` integer PRIMARY KEY NOT NULL,' ,
439+ '\t`title` text NOT NULL' ,
440+ ');' ,
441+ ] . join ( '\n' ) ;
442+ const { calls, db } = createMockD1 ( {
443+ failExec : ( executedSql ) =>
444+ executedSql . includes ( '\n' )
445+ ? new Error ( 'D1_EXEC_ERROR: Error in line 1: CREATE TABLE `posts` (: incomplete input' )
446+ : undefined ,
447+ } ) ;
448+ const handler = createMigrationHandler (
449+ { __VOID_PROXY_TOKEN : proxyToken , DB : db } ,
450+ [ { name : '0000_generated.sql' , sql } ] ,
451+ 'sqlite' ,
452+ ) ;
453+
454+ const response = await handler (
455+ new Request ( 'https://example.com/__void/migrate' , {
456+ method : 'POST' ,
457+ headers : { 'x-void-internal' : proxyToken } ,
458+ } ) ,
459+ ) ;
460+ const body = ( await response . json ( ) ) as MigrationResponse ;
461+
462+ expect ( response . status ) . toBe ( 200 ) ;
463+ expect ( body . ok ) . toBe ( true ) ;
464+ expect ( body . migrations ) . toEqual ( [
465+ { name : '0000_generated.sql' , applied : true , durationMs : expect . any ( Number ) } ,
466+ ] ) ;
467+ expect ( calls . exec ) . toEqual ( [ ] ) ;
468+ expect ( calls . run ) . toEqual ( [
469+ `CREATE TABLE IF NOT EXISTS _void_migrations (
470+ name TEXT PRIMARY KEY,
471+ applied_at TEXT NOT NULL
472+ )` ,
473+ sql ,
474+ 'INSERT OR IGNORE INTO _void_migrations (name, applied_at) VALUES (?, ?)' ,
475+ ] ) ;
476+ } ) ;
477+
431478 it ( 'applies Drizzle statement breakpoint chunks separately on D1' , async ( ) => {
432479 const sql = [
433480 'CREATE TABLE `account` (' ,
0 commit comments