From 4ee7fb1be123a0ff047da56f7ee537c7ebe00b08 Mon Sep 17 00:00:00 2001 From: Wes Rasada Date: Thu, 4 Jun 2026 15:59:17 -0700 Subject: [PATCH] fix(dev-env): use -o so myloader drops existing tables before import myloader >= 0.20 deprecated --overwrite-tables into a no-op that no longer sets the purge mode, so imports fail with ERROR 1050 on any pre-existing table. -o maps to the correct behavior on every myloader version. Co-Authored-By: Claude Opus 4.8 (1M context) --- __tests__/commands/dev-env-import-sql.ts | 36 ++++++++++++++++++++++++ src/commands/dev-env-import-sql.ts | 4 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 __tests__/commands/dev-env-import-sql.ts diff --git a/__tests__/commands/dev-env-import-sql.ts b/__tests__/commands/dev-env-import-sql.ts new file mode 100644 index 000000000..b193e8a10 --- /dev/null +++ b/__tests__/commands/dev-env-import-sql.ts @@ -0,0 +1,36 @@ +/** + * @format + */ + +import { DevEnvImportSQLCommand } from '../../src/commands/dev-env-import-sql'; +import { SqlDumpType } from '../../src/lib/database'; + +describe( 'commands/DevEnvImportSQLCommand', () => { + describe( '.getImportArgs', () => { + const command = new DevEnvImportSQLCommand( + 'dump.sql', + { inPlace: false, skipValidate: true, quiet: true }, + 'test-slug' + ); + + it( 'uses the mysql client for mysqldump files', () => { + const args = command.getImportArgs( { type: SqlDumpType.MYSQLDUMP, sourceDb: undefined } ); + expect( args[ 0 ] ).toBe( 'db' ); + } ); + + it( 'passes -o (not --overwrite-tables) to myloader for mydumper files', () => { + const args = command.getImportArgs( { + type: SqlDumpType.MYDUMPER, + sourceDb: 'some_db', + } ); + + expect( args[ 0 ] ).toBe( 'db-myloader' ); + // `-o` drops existing tables on every myloader version; + // `--overwrite-tables` became a silent no-op in myloader >= 0.20. + expect( args ).toContain( '-o' ); + expect( args ).not.toContain( '--overwrite-tables' ); + expect( args ).toContain( '--source-db=some_db' ); + expect( args ).toContain( '--stream' ); + } ); + } ); +} ); diff --git a/src/commands/dev-env-import-sql.ts b/src/commands/dev-env-import-sql.ts index 9014d3c58..c3c18c7f3 100644 --- a/src/commands/dev-env-import-sql.ts +++ b/src/commands/dev-env-import-sql.ts @@ -164,7 +164,9 @@ export class DevEnvImportSQLCommand { importArg = [ 'db-myloader', - '--overwrite-tables', + // Drop existing tables before restoring. Do not use the long form: + // `--overwrite-tables` is a silent no-op on myloader >= 0.20. + '-o', ...( dumpDetails.sourceDb ? [ `--source-db=${ dumpDetails.sourceDb }` ] : [] ), `--threads=${ threadCount }`, '--max-threads-for-schema-creation=10',