From 22d8b419645002a9eb3b421259b0c9128d448dbd Mon Sep 17 00:00:00 2001 From: Mayank Chugh Date: Tue, 24 Dec 2024 14:12:10 +0000 Subject: [PATCH 1/2] FORNO-2053: Adds autoIncrement check with requiredCheckFormatter --- .../fail-autoIncrement-validation.sql | 18 ++++++++++++++++++ .../fail-autoIncrement-validation.sql.gz | Bin 0 -> 403 bytes __tests__/devenv-e2e/010-import-sql.spec.js | 13 +++++++++++++ src/lib/validations/sql.ts | 11 +++++++++++ 4 files changed, 42 insertions(+) create mode 100644 __fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql create mode 100644 __fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql.gz 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 0000000000000000000000000000000000000000..02b9b0a924096484bbc0ad5b0d66a30d816f39e8 GIT binary patch literal 403 zcmV;E0c`#siwFp+yKQFx17=}qY%O7RbZ<#+V{&C}Wo~pWc42I3WMOn^Z*DGgacls6 zlEHFXI84hUcRLAjv8e67_7Gb8ILJSepf#8s6`}hTwQmporN%q^_fB((Y zTP(r1#ts5|2I$>h`6~!N_n7o4rgmiH9s7U2^V|ptS%(dm6%q z$6P2l2+3o?A~4E;;wh7gr2D^dcj1E@IL?V9RPjuNa3ne1kzDKcdipH_?}*&7s0JUp zR~#2bKS9|)2+89@c#?@&u`kt(Nm`UYBKQ+&Vbj?IB-V!|=y!*9kmGF!_6001i_zsvvt literal 0 HcmV?d00001 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 486d3d617..31f37e3d5 100644 --- a/src/lib/validations/sql.ts +++ b/src/lib/validations/sql.ts @@ -377,6 +377,17 @@ const checks: Checks = { "Ensure your application works with InnoDB and update your SQL dump to include only 'ENGINE=InnoDB' engine definitions in 'CREATE TABLE' statements. " + "We suggest you search for all 'ENGINE=X' entries and replace them with 'ENGINE=InnoDB'!", }, + autoIncrement: { + matcher: /\s(NOT NULL AUTO_INCREMENT,)/i, + matchHandler: ( _lineNumber, results ) => ( { text: results[ 1 ] } ), + outputFormatter: requiredCheckFormatter, + results: [], + message: 'AUTO_INCREMENT attribute', + excerpt: + "'AUTO_INCREMENT attribute' should be present (case-insensitive) for all CREATE TABLE statements", + recommendation: + 'Check import settings to include AUTO_INCREMENT attribute in all the CREATE TABLE statements', + }, }; const DEV_ENV_SPECIFIC_CHECKS = [ 'useStatement', 'siteHomeUrlLando' ]; From 3b9425d352534ccb682f7ae8f3ab4157a12f4310 Mon Sep 17 00:00:00 2001 From: Mayank Chugh Date: Fri, 27 Dec 2024 12:50:44 +0000 Subject: [PATCH 2/2] Adds newline to test sql file --- __fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql b/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql index 3cb6c1978..0a71c243c 100644 --- a/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql +++ b/__fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql @@ -15,4 +15,4 @@ CREATE TABLE `wp_a8c_cron_control_jobs` ( 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 +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;