Skip to content

Commit 00a2f81

Browse files
youknowriadclaude
andcommitted
End exported dumps with a newline and load the FK export back in the test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c4f65cf commit 00a2f81

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎features/sqlite-export.feature‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,25 @@ Feature: WP-CLI SQLite Export Command
216216
INSERT INTO wp_zz_parent (id, name) VALUES (1, 'Parent Row');
217217
"""
218218
And I run `wp sqlite --enable-ast-driver import test_fk_source.sql`
219-
When I run `wp sqlite --enable-ast-driver export - --tables=wp_aa_child,wp_zz_parent`
220-
Then STDOUT should match /SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\s+SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\s+--\s+-- Table structure for table `wp_aa_child`.+-- Table structure for table `wp_zz_parent`.+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\s+SET SQL_MODE=@OLD_SQL_MODE;\s+-- Dump completed/s
219+
When I run `wp sqlite --enable-ast-driver export test_fk_export.sql --tables=wp_aa_child,wp_zz_parent`
220+
Then the file "test_fk_export.sql" should contain:
221+
"""
222+
CONSTRAINT `fk_parent` FOREIGN KEY (`parent_id`) REFERENCES `wp_zz_parent` (`id`)
223+
"""
224+
When I run `cat test_fk_export.sql`
225+
Then STDOUT should match /^SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\s+SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\s+--\s+-- Table structure for table `wp_aa_child`.+-- Table structure for table `wp_zz_parent`.+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\s+SET SQL_MODE=@OLD_SQL_MODE;\s+-- Dump completed on \S+\n$/s
226+
227+
When I run `wp --exec="define( 'DB_PATH', getcwd() . '/test_fk_reimport.sqlite' );" sqlite --enable-ast-driver import test_fk_export.sql`
228+
Then STDOUT should contain:
229+
"""
230+
Success: Imported from 'test_fk_export.sql'.
231+
"""
232+
When I run `wp --exec="define( 'DB_PATH', getcwd() . '/test_fk_reimport.sqlite' );" sqlite --enable-ast-driver export - --tables=wp_aa_child,wp_zz_parent`
233+
Then STDOUT should contain:
234+
"""
235+
INSERT INTO `wp_aa_child` VALUES (1,1);
236+
"""
237+
And STDOUT should contain:
238+
"""
239+
INSERT INTO `wp_zz_parent` VALUES (1,'Parent Row');
240+
"""

‎src/Export.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function write_sql_statements( $handle ) {
117117

118118
fwrite( $handle, 'SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;' . PHP_EOL );
119119
fwrite( $handle, 'SET SQL_MODE=@OLD_SQL_MODE;' . PHP_EOL . PHP_EOL );
120-
fwrite( $handle, sprintf( '-- Dump completed on %s', gmdate( 'c' ) ) );
120+
fwrite( $handle, sprintf( '-- Dump completed on %s', gmdate( 'c' ) ) . PHP_EOL );
121121
}
122122

123123
/**

0 commit comments

Comments
 (0)