Skip to content

Conversation

@sejas
Copy link
Member

@sejas sejas commented Nov 25, 2024

Description

  • It adds a new command to get all the tables from the SQLite database
  • It returns the results in two formats: list and csv

Examples

wp sqlite tables --require=path/to/wp-cli-sqlite-command/command.php

wp_users
wp_usermeta
wp_termmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts

wp sqlite tables --format=csv --require=/path/to/wp-cli-sqlite-command/command.php

wp_users,wp_usermeta,wp_termmeta,wp_terms,wp_term_taxonomy,wp_term_relationships,wp_commentmeta,wp_comments,wp_links,wp_options,wp_postmeta,wp_posts

Testing instructions

  1. Run composer install --no-dev in this repo
  2. Open your terminal and cd into the root directory of a Studio site
  3. Copy the local path to this repository to use it in the next command:
  4. Run wp sqlite tables --format=csv --require=/path/to/wp-cli-sqlite-command/command.php
  5. Run wp sqlite tables --require=/path/to/wp-cli-sqlite-command/command.php

@sejas sejas self-assigned this Nov 25, 2024
@sejas sejas requested a review from a team November 25, 2024 07:02
@wojtekn
Copy link
Contributor

wojtekn commented Nov 25, 2024

Works well @sejas!

We will need to update docs and add tests before we merge, though.

Copy link
Contributor

@wojtekn wojtekn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, works as expected. Thanks for updating readme.

$tables = $stmt->fetchAll( PDO::FETCH_COLUMN );

// Remove system tables
$tables_to_exclude = array( '_mysql_data_types_cache' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are ignoring some tables as a part of the SQL query, would it make sense to do the same for this one?

@wojtekn wojtekn merged commit e8a0970 into main Nov 26, 2024
3 checks passed
@sejas sejas deleted the add/sqlite-tables-command branch November 29, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants