Skip to content

Commit

Permalink
FORNO-2053: Adds autoIncrement check with requiredCheckFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
iamchughmayank committed Dec 26, 2024
1 parent 29a47ce commit 22d8b41
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions __fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql
Original file line number Diff line number Diff line change
@@ -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;
Binary file not shown.
13 changes: 13 additions & 0 deletions __tests__/devenv-e2e/010-import-sql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
11 changes: 11 additions & 0 deletions src/lib/validations/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];
Expand Down

0 comments on commit 22d8b41

Please sign in to comment.