Repository navigation
Add support for the new SQLite storage #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5965c5a
Align import fixtures with supported driver behavior
JanJakes 7a3e60a
Align PHP compatibility checks with PHP 7.4
JanJakes a49c4de
Add support for the new SQLite storage
JanJakes 5c08fcf
Reject in-memory SQLite databases
JanJakes 6780603
Report SQLite driver errors as command errors
JanJakes 211877f
Open the import file before the database
JanJakes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| @require-sqlite | ||
| Feature: SQLite database storage | ||
| Commands use the same database as WordPress before its database drop-in loads. | ||
|
|
||
| Background: | ||
| Given a WP installation | ||
|
|
||
| Scenario: Use an existing legacy database without migrating storage | ||
| Given a SQL dump file named "test_import.sql" with content: | ||
| """ | ||
| CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT); | ||
| INSERT INTO test_table VALUES (1, 'Imported data'); | ||
| """ | ||
| When I run `wp eval 'echo defined( "DB_PATH" ) ? DB_PATH : FQDB;'` | ||
| Then save STDOUT as {DATABASE_PATH} | ||
| When I run `cp "{DATABASE_PATH}" original.sqlite` | ||
| And I run `rm -r wp-content/database` | ||
| And I run `mkdir wp-content/database` | ||
| And I run `mv original.sqlite wp-content/database/.ht.sqlite` | ||
| And I run `wp sqlite export backup.sql` | ||
| Then the backup.sql file should contain: | ||
| """ | ||
| WP CLI Site | ||
| """ | ||
| When I run `wp sqlite import test_import.sql` | ||
| And I run `wp sqlite export -` | ||
| Then STDOUT should contain: | ||
| """ | ||
| Imported data | ||
| """ | ||
| And the wp-content/database/.ht.sqlite file should exist | ||
| And the wp-content/database/db-path.php file should not exist | ||
|
|
||
| Scenario: Only import initializes fresh default storage | ||
| When I run `wp sqlite export backup.sql` | ||
| And I run `rm -r wp-content/database` | ||
| And I try `wp sqlite export missing.sql` | ||
| Then the return code should be 1 | ||
| And the missing.sql file should not exist | ||
| When I try `wp sqlite tables` | ||
| Then the return code should be 1 | ||
| And the wp-content/database directory should not exist | ||
| When I try `wp sqlite import missing.sql` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| Unable to open file: missing.sql | ||
| """ | ||
| And the wp-content/database directory should not exist | ||
| When I run `mkdir wp-content/database` | ||
| And I run `wp sqlite import backup.sql` | ||
| Then STDOUT should contain: | ||
| """ | ||
| Success: Imported from 'backup.sql'. | ||
| """ | ||
| When I run `wp sqlite tables` | ||
| Then STDOUT should contain: | ||
| """ | ||
| wp_options | ||
| """ | ||
| When I run `wp eval 'echo get_option( "blogname" );'` | ||
| Then STDOUT should be: | ||
| """ | ||
| WP CLI Site | ||
| """ | ||
|
brandonpayton marked this conversation as resolved.
|
||
|
|
||
| Scenario: Use DB_PATH without changing existing storage | ||
| When I run `wp eval 'echo defined( "DB_PATH" ) ? DB_PATH : FQDB;'` | ||
| Then save STDOUT as {DATABASE_PATH} | ||
| When I run `mkdir custom-database` | ||
| And I run `cp "{DATABASE_PATH}" 'custom-database/custom;database.sqlite'` | ||
| And I run `wp config set DB_PATH "dirname( __FILE__ ) . '/custom-database/custom;database.sqlite'" --raw` | ||
| And I run `wp sqlite export backup.sql` | ||
| And I run `wp sqlite import backup.sql` | ||
| Then the custom-database/db-path.php file should not exist | ||
| And the custom-database/.htaccess file should not exist | ||
| And the custom-database/.ht.sqlite.lock file should not exist | ||
| When I run `wp sqlite export -` | ||
| Then STDOUT should contain: | ||
| """ | ||
| WP CLI Site | ||
| """ | ||
|
|
||
| Scenario: Only import creates a missing explicit database | ||
| Given a SQL dump file named "test_import.sql" with content: | ||
| """ | ||
| CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT); | ||
| INSERT INTO test_table VALUES (1, 'Imported data'); | ||
| """ | ||
| When I run `wp config set DB_PATH '{RUN_DIR}/new.sqlite'` | ||
| And I try `wp sqlite export backup.sql` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| The SQLite database does not exist. | ||
| """ | ||
| And the new.sqlite file should not exist | ||
| And the backup.sql file should not exist | ||
| When I try `wp sqlite tables` | ||
| Then the return code should be 1 | ||
| And the new.sqlite file should not exist | ||
| When I try `wp sqlite import missing.sql` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| Unable to open file: missing.sql | ||
| """ | ||
| And the new.sqlite file should not exist | ||
| When I run `wp sqlite import test_import.sql` | ||
| And I run `wp sqlite tables` | ||
| Then STDOUT should contain: | ||
| """ | ||
| test_table | ||
| """ | ||
| When I run `wp sqlite export -` | ||
| Then STDOUT should contain: | ||
| """ | ||
| Imported data | ||
| """ | ||
|
|
||
| Scenario: Use the legacy FQDB override | ||
| When I run `wp eval 'echo defined( "DB_PATH" ) ? DB_PATH : FQDB;'` | ||
| Then save STDOUT as {DB_PATH} | ||
| When I run `cp "{DB_PATH}" custom.sqlite` | ||
| And I run `wp config set FQDB '{RUN_DIR}/custom.sqlite'` | ||
| And I run `wp sqlite export backup.sql` | ||
| And I run `wp sqlite import backup.sql` | ||
| And I run `wp eval 'echo get_option( "blogname" );'` | ||
| Then STDOUT should be: | ||
| """ | ||
| WP CLI Site | ||
| """ | ||
|
|
||
| Scenario: Reject an invalid DB_PATH without falling back to existing storage | ||
| Given a SQL dump file named "test_import.sql" with content: | ||
| """ | ||
| CREATE TABLE test_table (id INTEGER PRIMARY KEY); | ||
| """ | ||
| When I run `wp config set DB_PATH null --raw` | ||
| And I try `wp sqlite import test_import.sql` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| Error: Could not open the SQLite database: | ||
| """ | ||
| When I try `wp sqlite export backup.sql` | ||
| Then the return code should be 1 | ||
| And the backup.sql file should not exist | ||
| When I try `wp sqlite tables` | ||
| Then the return code should be 1 | ||
| When I run `wp config delete DB_PATH` | ||
| And I run `wp sqlite tables` | ||
| Then STDOUT should not contain: | ||
| """ | ||
| test_table | ||
| """ | ||
|
|
||
| Scenario: Reject an in-memory database | ||
| Given a SQL dump file named "test_import.sql" with content: | ||
| """ | ||
| CREATE TABLE test_table (id INTEGER PRIMARY KEY); | ||
| """ | ||
| When I run `wp config set DB_PATH ':memory:'` | ||
| And I try `wp sqlite import test_import.sql` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| In-memory databases are not supported. | ||
| """ | ||
| When I try `wp sqlite export backup.sql` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| In-memory databases are not supported. | ||
| """ | ||
| And the backup.sql file should not exist | ||
| When I try `wp sqlite tables` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| In-memory databases are not supported. | ||
| """ | ||
|
|
||
| Scenario: Report a database that cannot be opened | ||
| Given a SQL dump file named "test_import.sql" with content: | ||
| """ | ||
| CREATE TABLE test_table (id INTEGER PRIMARY KEY); | ||
| """ | ||
| When I run `wp config set DB_PATH '{RUN_DIR}/missing-directory/database.sqlite'` | ||
| And I try `wp sqlite import test_import.sql` | ||
| Then the return code should be 1 | ||
| And STDERR should contain: | ||
| """ | ||
| Error: Could not open the SQLite database: | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.