diff --git a/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql b/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql new file mode 100644 index 000000000..3cb6c1978 --- /dev/null +++ b/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql @@ -0,0 +1,18 @@ +DROP TABLE IF EXISTS `wp_a8c_cron_control_jobs`; + +CREATE TABLE `wp_a8c_cron_control_jobs` ( + `ID` bigint unsigned , + `timestamp` bigint unsigned NOT NULL, + `action` varchar(255) NOT NULL, + `action_hashed` varchar(32) NOT NULL, + `instance` varchar(32) NOT NULL, + `args` longtext NOT NULL, + `schedule` varchar(255) DEFAULT NULL, + `interval` int unsigned DEFAULT '0', + `status` varchar(32) NOT NULL DEFAULT 'pending', + `created` datetime NOT NULL, + `last_modified` datetime NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `ts_action_instance_status` (`timestamp`,`action`(191),`instance`,`status`), + KEY `status` (`status`) +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql.gz b/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql.gz new file mode 100644 index 000000000..02b9b0a92 Binary files /dev/null and b/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql.gz differ diff --git a/__tests__/devenv-e2e/010-import-sql.spec.js b/__tests__/devenv-e2e/010-import-sql.spec.js index 340fc9e17..0981be588 100644 --- a/__tests__/devenv-e2e/010-import-sql.spec.js +++ b/__tests__/devenv-e2e/010-import-sql.spec.js @@ -94,6 +94,19 @@ describe( 'vip dev-env import sql', () => { } ); + it.each( [ 'fail-autoIncrement-validation.sql.gz', 'fail-autoIncrement-validation.sql' ] )( + 'should fail if the file fails auto increment validation', + async baseName => { + const file = path.join( __dirname, `../../__fixtures__/dev-env-e2e/${ baseName }` ); + const result = await cliTest.spawn( + [ process.argv[ 0 ], vipDevEnvImportSQL, '--slug', slug, file ], + { env } + ); + expect( result.rc ).toBeGreaterThan( 0 ); + expect( result.stderr ).toContain( 'SQL Error: AUTO_INCREMENT attribute was not found' ); + } + ); + it.each( [ 'fail-validation.sql.gz', 'fail-validation.sql' ] )( 'should allow to bypass validation', async baseName => { diff --git a/src/lib/validations/sql.ts b/src/lib/validations/sql.ts index 75172fad9..31f37e3d5 100644 --- a/src/lib/validations/sql.ts +++ b/src/lib/validations/sql.ts @@ -379,7 +379,7 @@ const checks: Checks = { }, autoIncrement: { matcher: /\s(NOT NULL AUTO_INCREMENT,)/i, - matchHandler: ( _, results ) => ( { text: results[ 1 ] } ), + matchHandler: ( _lineNumber, results ) => ( { text: results[ 1 ] } ), outputFormatter: requiredCheckFormatter, results: [], message: 'AUTO_INCREMENT attribute',