Automattic / vip-cli

The VIP-CLI
https://docs.wpvip.com/vip-cli/
MIT License
58 stars 17 forks source link

BB8-11725: SQL Import - Update multisite regex to match optional `IF NOT EXISTS` #2015

Closed t-wright closed 2 months ago

t-wright commented 2 months ago

Description

When importing SQL to a multisite environment, we check that the SQL file is from a multisite installation. One of the ways we do that is by checking the table name in CREATE TABLE statements are in a format like wp_\d_posts. However our regex doesn't currently match if the IF NOT EXISTS keyword is present, leading to a validation warning. This PR fixes that.

Pull request checklist

New release checklist

Steps to Test

DROP TABLE IF EXISTS `wp_5_postmeta`;

CREATE TABLE IF NOT EXISTS `wp_5_postmeta` (
  `meta_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `post_id` bigint unsigned NOT NULL DEFAULT '0',
  `meta_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `meta_value` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  PRIMARY KEY (`meta_id`),
  KEY `post_id` (`post_id`),
  KEY `vip_meta_key_value` (`meta_key`(191),`meta_value`(100))
) ENGINE=InnoDB AUTO_INCREMENT=105388 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  1. Check out PR.
  2. Run npm run build
  3. Run ./dist/bin/vip-import-sql.js path_to_file.sql @<id>.production (where the id corresponds to a multisite installation)
  4. Verify you do not receive the error: Error: You have requested a subsite SQL import but have not provided a subsite compatiable SQL dump.
github-actions[bot] commented 2 months ago

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud