Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
733e172
Initial plan
Copilot Nov 20, 2025
cbcf158
Add SQLite support trait and integrate into DB_Command
Copilot Nov 20, 2025
711e37b
Fix sqlite_reset to not double-call sqlite_create
Copilot Nov 20, 2025
f7c1165
Add SQLite test scenarios and documentation
Copilot Nov 20, 2025
0d1fb30
Improve identifier escaping in SQLite export
Copilot Nov 20, 2025
925ed48
Undo readme change
swissspidy Nov 23, 2025
8c4e96f
Fix formatting
swissspidy Nov 23, 2025
35a91ba
PHPCS fixes
swissspidy Nov 23, 2025
a89fe31
PHPStan fixes
swissspidy Nov 23, 2025
19f6813
Some test improvements
swissspidy Nov 23, 2025
63f7865
Remove test
swissspidy Nov 23, 2025
1105c5e
Improve some tests
swissspidy Nov 23, 2025
b3bb681
Use `gmdate`
swissspidy Nov 23, 2025
75f52d2
More test fixes
swissspidy Nov 23, 2025
8eeea43
Fix regex
swissspidy Nov 23, 2025
0e1637e
More fixes
swissspidy Nov 23, 2025
1ab8410
More fixes
swissspidy Nov 24, 2025
3d5f055
Correctly load sqlite drop-in
swissspidy Nov 24, 2025
3638ff2
Update PHPStan config
swissspidy Nov 24, 2025
020b1d1
Fix another test
swissspidy Nov 24, 2025
261299f
Merge branch 'main' into copilot/add-sqlite-compatibility
swissspidy Dec 19, 2025
05b20d8
Merge branch 'main' into copilot/add-sqlite-compatibility
swissspidy Jan 19, 2026
65b4938
`wp config create --skip-check`
swissspidy Jan 19, 2026
769a79e
add missing `session_yes` file
swissspidy Jan 19, 2026
c1a4c7b
Merge branch 'main' into copilot/add-sqlite-compatibility
swissspidy Feb 7, 2026
b4bdb19
Update some tests
swissspidy Feb 8, 2026
8d89040
PHPStan fix
swissspidy Feb 8, 2026
3102f50
Adjust some tests
swissspidy Feb 8, 2026
48aa3ae
Support --skip-column-names flag for SQLite queries and use Formatter…
Copilot Feb 8, 2026
49dc6a4
Update test to reflect SQLite support for --skip-column-names flag
Copilot Feb 8, 2026
1fa16d3
Fix pass by reference
swissspidy Feb 8, 2026
fc440ff
Skip some tests
swissspidy Feb 9, 2026
7abb116
No "No text columns for table" warnings on SQLite
swissspidy Feb 9, 2026
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
16 changes: 16 additions & 0 deletions features/db-check.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Feature: Check the database

@require-mysql-or-mariadb
Scenario: Run db check to check the database
Given a WP install

Expand All @@ -13,12 +14,14 @@ Feature: Check the database
Success: Database checked.
"""

@require-mysql-or-mariadb
Scenario: db check with --quiet flag should only show errors
Given a WP install

When I run `wp db check --quiet`
Then STDOUT should be empty

@require-mysql-or-mariadb
Scenario: db check can explicitly pass --silent to mysqlcheck
Given a WP install

Expand All @@ -32,6 +35,7 @@ Feature: Check the database
Success: Database checked.
"""

@require-mysql-or-mariadb
Scenario: Run db check with MySQL defaults to check the database
Given a WP install

Expand All @@ -45,6 +49,7 @@ Feature: Check the database
Success: Database checked.
"""

@require-mysql-or-mariadb
Scenario: Run db check with --no-defaults to check the database
Given a WP install

Expand All @@ -58,6 +63,7 @@ Feature: Check the database
Success: Database checked.
"""

@require-mysql-or-mariadb
Scenario: Run db check with passed-in options
Given a WP install

Expand Down Expand Up @@ -143,6 +149,7 @@ Feature: Check the database
"""
And STDOUT should be empty

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand All @@ -155,3 +162,12 @@ Feature: Check the database
When I try `wp db check --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#

@require-sqlite
Scenario: SQLite commands that show warnings
Given a WP install

When I try `wp db check`
Then STDERR should contain:
"""
Warning: Database check is not supported for SQLite databases
"""
11 changes: 11 additions & 0 deletions features/db-cli.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Open a MySQL console

@require-sqlite
Scenario: SQLite commands that show warnings for cli
Given a WP install

When I try `wp db cli`
Then STDERR should contain:
"""
Warning: Interactive console (cli) is not supported for SQLite databases
"""
12 changes: 12 additions & 0 deletions features/db-columns.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Feature: Display information about a given table.
Couldn't find any tables matching: wp_foobar
"""

@require-mysql-or-mariadb
Scenario: Display information about a non default WordPress table
Given a WP install
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
Expand All @@ -50,3 +51,14 @@ Feature: Display information about a given table.
| Field | Type | Null | Key | Default | Extra |
| date | date | NO | PRI | | |
| awesome_stuff | text | YES | | | |

@require-sqlite
Scenario: Display information about a non default WordPress table
Given a WP install
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`

When I try `wp db columns not_wp`
Then STDOUT should be a table containing rows:
| Field | Type | Null | Key | Default |
| date | TEXT | NO | PRI | '' |
| awesome_stuff | TEXT | YES | | |
24 changes: 24 additions & 0 deletions features/db-create.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: Create a new database

@require-mysql-or-mariadb
Scenario: Create a new database
Given an empty directory
And WP files
And wp-config.php

When I run `wp db create`
Then STDOUT should contain:
"""
Success: Database created.
"""

@require-sqlite
Scenario: SQLite DB create operation should fail if already existing
Given a WP install

When I try `wp db create`
Then the return code should be 1
And STDERR should contain:
"""
Database already exists
"""
32 changes: 23 additions & 9 deletions features/db-export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ Feature: Export a WordPress database
Scenario: Exclude tables when exporting the database
Given a WP install

When I run `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
When I try `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
Then the wp_cli_test.sql file should exist
And the wp_cli_test.sql file should not contain:
"""
wp_users
"""
And the wp_cli_test.sql file should contain:
"""
wp_options
"""
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_users["`]?/
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_options["`]?/

Scenario: Export database to STDOUT
Given a WP install
Expand Down Expand Up @@ -61,6 +55,7 @@ Feature: Export a WordPress database
-- Dump completed on
"""

@require-mysql-or-mariadb
Scenario: Export database with passed-in options
Given a WP install

Expand All @@ -78,6 +73,25 @@ Feature: Export a WordPress database
"""
And STDOUT should be empty

@require-sqlite
Scenario: Export database with passed-in options
Given a WP install

When I run `wp db export - --skip-comments`
Then STDOUT should not contain:
"""
-- Table structure
"""

# dbpass has no effect on SQLite
When I try `wp db export - --dbpass=no_such_pass`
Then the return code should be 0
And STDERR should not contain:
"""
Access denied
"""

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand Down
40 changes: 39 additions & 1 deletion features/db-import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Feature: Import a WordPress database
Success: Imported from 'wp_cli_test.sql'.
"""

# SQLite doesn't support the --dbuser flag.
@require-mysql-or-mariadb
Scenario: Import from database name path by default with passed-in dbuser/dbpass
Given a WP install

Expand All @@ -77,6 +79,8 @@ Feature: Import a WordPress database
"""
And STDOUT should be empty

# SQLite doesn't support the --force flag.
@require-mysql-or-mariadb
Scenario: Import database with passed-in options
Given a WP install
And a debug.sql file:
Expand All @@ -90,6 +94,9 @@ Feature: Import a WordPress database
Success: Imported from 'debug.sql'.
"""

# For SQLite this would fail at the `wp db create` step
# because of the missing plugin/drop-in.
@require-mysql-or-mariadb
Scenario: Help runs properly at various points of a functional WP install
Given an empty directory

Expand Down Expand Up @@ -127,6 +134,8 @@ Feature: Import a WordPress database
"""
wp db import
"""

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand All @@ -142,7 +151,7 @@ Feature: Import a WordPress database
When I try `wp db import --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#

@require-wp-4.2
@require-wp-4.2 @require-mysql-or-mariadb
Scenario: Import db that has emoji in post
Given a WP install

Expand Down Expand Up @@ -178,3 +187,32 @@ Feature: Import a WordPress database
"""
🍣
"""

@require-wp-4.2 @require-sqlite
Scenario: Import db that has emoji in post
Given a WP install

When I run `wp post create --post_title="🍣"`
And I run `wp post list`
Then the return code should be 0
And STDOUT should contain:
"""
🍣
"""

When I try `wp db export wp_cli_test.sql --debug`
Then the return code should be 0
And the wp_cli_test.sql file should exist

When I run `wp db import --dbuser=wp_cli_test --dbpass=password1`
Then STDOUT should be:
"""
Success: Imported from 'wp_cli_test.sql'.
"""

When I run `wp post list`
Then the return code should be 0
And STDOUT should contain:
"""
🍣
"""
21 changes: 21 additions & 0 deletions features/db-optimize.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Optimize the database

@require-mysql-or-mariadb
Scenario: Run db optimize to optimize the database
Given a WP install

When I run `wp db optimize`
Then STDOUT should contain:
"""
Success: Database optimized.
"""

@require-sqlite
Scenario: SQLite commands that show warnings for optimize
Given a WP install

When I try `wp db optimize`
Then STDERR should contain:
"""
Warning: Database optimization is not supported for SQLite databases
"""
8 changes: 8 additions & 0 deletions features/db-query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ Feature: Query the database with WordPress' MySQL config
Error: Plugin loaded.
"""

# TODO: When using SQLite the output format should be the same
When I run `wp db query "SELECT COUNT(ID) FROM wp_users;"`
Then STDOUT should be:
"""
COUNT(ID)
1
"""

# SQLite doesn't support the --html option nor different dbuser.
@require-mysql-or-mariadb
Scenario: Database querying with passed-in options
Given a WP install

Expand All @@ -38,6 +41,8 @@ Feature: Query the database with WordPress' MySQL config
"""
And STDOUT should be empty

# SQLite doesn't support the --html option nor different dbuser.
@require-mysql-or-mariadb
Scenario: Database querying with MySQL defaults and passed-in options
Given a WP install

Expand All @@ -55,6 +60,8 @@ Feature: Query the database with WordPress' MySQL config
"""
And STDOUT should be empty

# SQLite doesn't support the --html option nor different dbuser.
@require-mysql-or-mariadb
Scenario: Database querying with --nodefaults and passed-in options
Given a WP install

Expand All @@ -72,6 +79,7 @@ Feature: Query the database with WordPress' MySQL config
"""
And STDOUT should be empty

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand Down
21 changes: 21 additions & 0 deletions features/db-repair.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Repair the database

@require-mysql-or-mariadb
Scenario: Run db repair to repair the database
Given a WP install

When I run `wp db repair`
Then STDOUT should contain:
"""
Success: Database repaired.
"""

@require-sqlite
Scenario: SQLite commands that show warnings for repair
Given a WP install

When I try `wp db repair`
Then STDERR should contain:
"""
Warning: Database repair is not supported for SQLite databases
"""
10 changes: 7 additions & 3 deletions features/db-search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ Feature: Search through the database
And the return code should be 1

When I run `wp db query "CREATE TABLE no_key ( awesome_stuff TEXT );"`
And I run `wp db query "CREATE TABLE no_text ( id int(11) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) );"`
And I try `wp db search example.com no_key --all-tables`
Then STDOUT should be empty
And STDERR should be:
Expand All @@ -273,6 +272,10 @@ Feature: Search through the database
"""
And the return code should be 0

@require-mysql-or-mariadb
Scenario: Search on a single site install - No text columns for table
Given a WP install
And I run `wp db query "CREATE TABLE no_text ( id int(11) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) );"`
When I try `wp db search example.com no_text --all-tables`
Then STDOUT should be empty
And STDERR should be:
Expand Down Expand Up @@ -999,8 +1002,9 @@ Feature: Search through the database
INSERT INTO `TABLE` (`VALUES`, `back``tick`, `single'double"quote`) VALUES ('v"v`v\'v\\v_v1', 'v"v`v\'v\\v_v1', 'v"v`v\'v\\v_v1' );
INSERT INTO `TABLE` (`VALUES`, `back``tick`, `single'double"quote`) VALUES ('v"v`v\'v\\v_v2', 'v"v`v\'v\\v_v2', 'v"v`v\'v\\v_v2' );
"""

When I run `wp db query "SOURCE esc_sql_ident.sql;"`
And save the {RUN_DIR}/esc_sql_ident.sql file as {QUERY}
When I run `wp db query 'CREATE TABLE `TABLE` (`KEY` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `VALUES` TEXT, `back``tick` TEXT, `single\'double"quote` TEXT, PRIMARY KEY (`KEY`) );'`
And I run `wp db query 'INSERT INTO `TABLE` (`VALUES`, `back``tick`, `single\'double"quote`) VALUES (\'v"v`v\\'v\\v_v1', \'v"v`v\\'v\\v_v1\', \'v"v`v\\'v\\v_v1\' );'`
Then STDERR should be empty

When I run `wp db search 'v_v' TABLE --all-tables`
Expand Down
Loading
Loading