wp-cli / db-command

Performs basic database operations using credentials stored in wp-config.php.
MIT License
71 stars 58 forks source link

Set `'utf8mb4'` when exporting without `'--default-character-set'` option #199

Closed ryotsun closed 3 years ago

ryotsun commented 3 years ago

Fixes: #144

I'm not sure whether this approach is correct. Kindly check this PR in your time.

wojsmol commented 3 years ago

@schlessera What if the database is in utf8 and by setting utf8mb4 as default same backup script will be broken?

schlessera commented 3 years ago

@wojsmol Good question. As far as I know, utf8mb4 is fully backwards compatible with utf8, so I assume any utf8 export should just work to be imported into utf8mb4. Any potential data loss would already have happened before the export, as utf8 would have already stripped any 4-byte code points.

But I'm not an expert in DB encodings. Am I maybe missing something here?

wojsmol commented 3 years ago

Regarding characters maybe, but for shore there are deferences in length of the indexes - see this make/core blog post linked in the original issue.

schlessera commented 3 years ago

@wojsmol I now added a detection of the actual character set of the wp_posts table. I think this should be safe enough now to use as a default, and reduce the risk of people actually losing their emojis on migration.

What do you think about that approach?