Skip to content

Commit 0a08a90

Browse files
swissspidyclaude
andcommitted
Rework wp db status on top of current main
The previous implementation called the removed get_mysql_command() helper, so every scenario failed after main moved on. - Read everything with a single information_schema query against the configured database instead of escaping DB_NAME into literals. - Derive the charset from the collation name, as joining COLLATION_CHARACTER_SET_APPLICABILITY duplicates rows on MariaDB 10.10+. - Error out when the database can't be queried, instead of printing zeros. - Detect table errors reported by mysqlcheck, which still exits with 0. - Support SQLite, add --skip-check and --format=json. - Use {DB_NAME}/{DB_USER} in tests and tag them per database type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent 4a4639f commit 0a08a90

2 files changed

Lines changed: 205 additions & 164 deletions

File tree

‎features/db-status.feature‎

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
Feature: Display database status overview
22

3+
@require-mysql-or-mariadb
34
Scenario: Display database status for a WordPress install
45
Given a WP install
56

67
When I run `wp db status`
78
Then STDOUT should contain:
89
"""
9-
Database Name: wp_cli_test
10+
Database Name: {DB_NAME}
1011
"""
1112
And STDOUT should match /^Tables:\s+\d+$/m
12-
And STDOUT should match /^Total Size:\s+[\d.]+ \wB$/m
13+
And STDOUT should match /^Total Size:\s+[\d.]+ [KM]?B$/m
1314
And STDOUT should contain:
1415
"""
1516
Prefix: wp_
@@ -22,68 +23,93 @@ Feature: Display database status overview
2223
Check Status: OK
2324
"""
2425

25-
Scenario: Run db status with MySQL defaults to check the database
26-
Given a WP install
27-
28-
When I run `wp db status --defaults`
29-
Then STDOUT should contain:
26+
When I run `wp db status --skip-check --format=json`
27+
Then STDOUT should be JSON containing:
3028
"""
31-
Database Name:
29+
{"database":"{DB_NAME}","prefix":"wp_","check":"Skipped"}
3230
"""
33-
And STDOUT should contain:
31+
And STDOUT should match /"tables":\d+,"size":\d+,/
32+
33+
@require-mysql-or-mariadb
34+
Scenario: Display database status before WordPress is installed
35+
Given an empty directory
36+
And WP files
37+
And wp-config.php
38+
And a database
39+
40+
When I run `wp db status`
41+
Then STDOUT should contain:
3442
"""
35-
Check Status: OK
43+
Database Name: {DB_NAME}
44+
Tables: 0
45+
Total Size: 0 B
46+
Prefix: wp_
47+
Engine: N/A
48+
Charset: N/A
49+
Collation: N/A
50+
Check Status: N/A
3651
"""
3752

38-
Scenario: Run db status with --no-defaults to check the database
53+
@require-mysql-or-mariadb
54+
Scenario: Report mixed table engines
3955
Given a WP install
4056

41-
When I run `wp db status --no-defaults`
57+
When I run `wp db query "CREATE TABLE wp_status_test (id INT) ENGINE=MyISAM"`
58+
And I run `wp db status --skip-check`
4259
Then STDOUT should contain:
4360
"""
44-
Database Name:
45-
"""
46-
And STDOUT should contain:
47-
"""
48-
Check Status: OK
61+
Engine: Mixed
4962
"""
5063

64+
@require-mysql-or-mariadb
5165
Scenario: Run db status with passed-in options
5266
Given a WP install
5367

54-
When I run `wp db status --dbuser=wp_cli_test`
68+
When I run `wp db status --defaults`
5569
Then STDOUT should contain:
56-
"""
57-
Database Name:
58-
"""
59-
And STDOUT should contain:
6070
"""
6171
Check Status: OK
6272
"""
6373

64-
When I run `wp db status --dbpass=password1`
74+
When I run `wp db status --no-defaults`
6575
Then STDOUT should contain:
66-
"""
67-
Database Name:
68-
"""
69-
And STDOUT should contain:
7076
"""
7177
Check Status: OK
7278
"""
7379

74-
When I run `wp db status --dbuser=wp_cli_test --dbpass=password1`
80+
When I run `wp db status --dbuser={DB_USER} --dbpass=password1`
7581
Then STDOUT should contain:
76-
"""
77-
Database Name:
78-
"""
79-
And STDOUT should contain:
8082
"""
8183
Check Status: OK
8284
"""
8385

8486
When I try `wp db status --dbuser=no_such_user`
85-
Then the return code should not be 0
87+
Then the return code should be 1
88+
And STDERR should contain:
89+
"""
90+
Error: Could not query the database:
91+
"""
8692

8793
When I try `wp db status --dbpass=no_such_pass`
88-
Then the return code should not be 0
94+
Then the return code should be 1
95+
And STDERR should contain:
96+
"""
97+
Error: Could not query the database:
98+
"""
8999

100+
@require-sqlite
101+
Scenario: Display database status for a SQLite install
102+
Given a WP install
103+
104+
When I run `wp db status`
105+
Then STDOUT should match /^Database Name:\s+\S+$/m
106+
And STDOUT should match /^Tables:\s+[1-9]\d*$/m
107+
And STDOUT should match /^Total Size:\s+[\d.]+ [KM]?B$/m
108+
And STDOUT should contain:
109+
"""
110+
Prefix: wp_
111+
Engine: SQLite
112+
Charset: N/A
113+
Collation: N/A
114+
Check Status: N/A
115+
"""

0 commit comments

Comments
 (0)