Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds check for AUTO_INCREMENT attribute in SQL import #2174

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading