Repository navigation
Expand file tree
/
Copy pathsqlite-export.feature
More file actions
240 lines (226 loc) · 8.77 KB
/
Copy pathsqlite-export.feature
File metadata and controls
240 lines (226 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Feature: WP-CLI SQLite Export Command
In order to backup or migrate a WordPress SQLite database
As a website administrator
I need to be able to export data from SQLite databases using WP-CLI
Background:
Given a WP installation
And the SQLite database contains some sample data
@require-sqlite
Scenario: Successfully export the entire SQLite database
When I run `wp sqlite export test_export.sql`
Then STDOUT should contain:
"""
Success: Exporting database...
Success: Export complete. File written to test_export.sql
"""
And the file "test_export.sql" should exist
And the file "test_export.sql" should contain:
"""
CREATE TABLE
"""
And the file "test_export.sql" should contain:
"""
INSERT INTO
"""
@require-sqlite
Scenario: Export specific tables
When I run `wp sqlite export test_export_specific.sql --tables=wp_posts,wp_users`
Then STDOUT should contain:
"""
Success: Exporting database...
Success: Export complete. File written to test_export_specific.sql
"""
And the file "test_export_specific.sql" should exist
And the file "test_export_specific.sql" should contain:
"""
CREATE TABLE `wp_posts`
"""
And the file "test_export_specific.sql" should contain:
"""
CREATE TABLE `wp_users`
"""
But the file "test_export_specific.sql" should not contain:
"""
CREATE TABLE `wp_options`
"""
@require-sqlite
Scenario: Export all tables except specific ones
When I run `wp sqlite export test_export_exclude.sql --exclude_tables=wp_posts,wp_users`
Then STDOUT should contain:
"""
Success: Exporting database...
Success: Export complete. File written to test_export_exclude.sql
"""
And the file "test_export_exclude.sql" should exist
And the file "test_export_exclude.sql" should not contain:
"""
CREATE TABLE `wp_posts``
"""
And the file "test_export_exclude.sql" should not contain:
"""
CREATE TABLE `wp_users``
"""
But the file "test_export_exclude.sql" should contain:
"""
CREATE TABLE `wp_options`
"""
@require-sqlite
Scenario: Export to STDOUT
When I run `wp sqlite export -`
Then STDOUT should contain:
"""
-- Dumping data for table
"""
And STDOUT should contain:
"""
CREATE TABLE
"""
And STDOUT should contain:
"""
INSERT INTO
"""
@require-sqlite
Scenario: Export with porcelain flag
When I run `wp sqlite export --porcelain`
Then STDOUT should match /^[\w-]+\.sql$/
And STDOUT should not contain:
"""
Success: Exporting database...
"""
@require-sqlite
Scenario: Export with both --tables and --exclude_tables
When I run `wp sqlite export test_export_both.sql --tables=wp_posts,wp_users,wp_options --exclude_tables=wp_users`
Then STDOUT should contain:
"""
Success: Exporting database...
Success: Export complete. File written to test_export_both.sql
"""
And the file "test_export_both.sql" should exist
And the file "test_export_both.sql" should contain:
"""
CREATE TABLE `wp_posts`
"""
And the file "test_export_both.sql" should contain:
"""
CREATE TABLE `wp_options`
"""
But the file "test_export_both.sql" should not contain:
"""
CREATE TABLE `wp_users`
"""
@require-sqlite
Scenario: Export should escape alphanumeric strings with e character
Given the SQLite database contains a test table with alphanumeric string hash values
When I run `wp sqlite export test_export_alphanumeric_string.sql --tables=test_export_alphanumeric_string`
Then STDOUT should contain:
"""
Success: Export complete. File written to test_export_alphanumeric_string.sql
"""
And the file "test_export_alphanumeric_string.sql" should exist
And the file "test_export_alphanumeric_string.sql" should contain:
"""
INSERT INTO `test_export_alphanumeric_string` VALUES (1,'123e99');
"""
But the file "test_export_alphanumeric_string.sql" should not contain:
"""
INSERT INTO `test_export_alphanumeric_string` VALUES (1,123e99);
"""
@require-sqlite
Scenario: Export should quote table names containing backticks
Given the SQLite database contains a table with a backtick in its name
When I run `wp sqlite export test_export_identifier.sql`
Then the file "test_export_identifier.sql" should contain:
"""
DROP TABLE IF EXISTS `test``table`;
"""
And the file "test_export_identifier.sql" should contain:
"""
INSERT INTO `test``table` VALUES (1,'Test value');
"""
@require-sqlite
Scenario: Export should keep multiline table names inside comments
Given the SQLite database contains a table with a comment injection name
When I export the table with a comment injection name
And I run `wp sqlite import test_export_comment.sql`
Then STDOUT should contain:
"""
Success: Imported from 'test_export_comment.sql'.
"""
And the SQLite database should contain a table named "wp_users"
@require-sqlite
Scenario: Export should preserve serialized settings containing a NUL byte
Given the SQLite database contains a serialized settings option with a NUL byte separator
When I run `wp sqlite export test_export_serialized_settings.sql --tables=wp_options`
Then STDOUT should contain:
"""
Success: Export complete. File written to test_export_serialized_settings.sql
"""
And the file "test_export_serialized_settings.sql" should exist
And the file "test_export_serialized_settings.sql" should contain:
"""
breadcrumb-separator";s:4:"\00bb
"""
And the file "test_export_serialized_settings.sql" should contain:
"""
global-color-palette
"""
When I run `wp sqlite import test_export_serialized_settings.sql`
Then STDOUT should contain:
"""
Success: Imported from 'test_export_serialized_settings.sql'.
"""
And the serialized settings option should preserve the NUL byte and color palette
@require-sqlite
Scenario: Export should escape SQL string special bytes
Given the SQLite database contains an option with SQL string escape bytes
When I run `wp sqlite export test_export_escape_bytes.sql --tables=wp_options`
Then STDOUT should contain:
"""
Success: Export complete. File written to test_export_escape_bytes.sql
"""
And the file "test_export_escape_bytes.sql" should exist
And the file "test_export_escape_bytes.sql" should contain:
"""
'sql-string-escape-bytes','quote\' backslash\\ nul\0 newline\n carriage\r ctrlz\Z end','yes'
"""
When I run `wp sqlite import test_export_escape_bytes.sql`
Then STDOUT should contain:
"""
Success: Imported from 'test_export_escape_bytes.sql'.
"""
And the SQL string escape bytes should be preserved
@require-sqlite
Scenario: Export should load into MySQL in any table order, like mysqldump
Given a SQL dump file named "test_fk_source.sql" with content:
"""
CREATE TABLE wp_aa_child (
id INTEGER PRIMARY KEY,
parent_id INTEGER NOT NULL,
CONSTRAINT fk_parent FOREIGN KEY (parent_id) REFERENCES wp_zz_parent(id)
);
INSERT INTO wp_aa_child (id, parent_id) VALUES (1, 1);
CREATE TABLE wp_zz_parent (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
INSERT INTO wp_zz_parent (id, name) VALUES (1, 'Parent Row');
"""
And I run `wp sqlite import test_fk_source.sql`
When I run `wp sqlite export test_fk_export.sql --tables=wp_aa_child,wp_zz_parent`
Then the file "test_fk_export.sql" should contain:
"""
CONSTRAINT `fk_parent` FOREIGN KEY (`parent_id`) REFERENCES `wp_zz_parent` (`id`)
"""
When I run `cat test_fk_export.sql`
Then STDOUT should match /^SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\s+SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\s+--\s+-- Table structure for table `wp_aa_child`.+-- Table structure for table `wp_zz_parent`.+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\s+SET SQL_MODE=@OLD_SQL_MODE;\s+-- Dump completed on \S+\n$/s
When I run `wp --exec="define( 'DB_PATH', getcwd() . '/test_fk_reimport.sqlite' );" sqlite import test_fk_export.sql`
Then STDOUT should contain:
"""
Success: Imported from 'test_fk_export.sql'.
"""
When I run `wp --exec="define( 'DB_PATH', getcwd() . '/test_fk_reimport.sqlite' );" sqlite export - --tables=wp_aa_child,wp_zz_parent`
Then STDOUT should contain:
"""
INSERT INTO `wp_aa_child` VALUES (1,1);
"""
And STDOUT should contain:
"""
INSERT INTO `wp_zz_parent` VALUES (1,'Parent Row');
"""