Skip to content

Commit

Permalink
Merge pull request #687 from humanmade/add-tableplus
Browse files Browse the repository at this point in the history
Add TablePlus command and improve Sequel Pro/Ace command
  • Loading branch information
mikelittle authored May 9, 2024
2 parents 01220ea + 2fbecaf commit 309a0be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@ Note: Altis local-server automatically collects domains names to issue the SSL c
* `composer server exec -- <command>` - Runs any command on the PHP container.
* `composer server db` - Logs into MySQL on the DB container.
* `composer server db info` - Print MySQL connection details.
* `composer server db sequel` - Opens a connection to the database in [Sequel Pro](https://sequelpro.com).
* `composer server db (sequel|spf)` - Opens a connection to the database in [Sequel Pro](https://sequelpro.com) or [Sequel Ace](https://sequel-ace.com/).
* `composer server db (tableplus|tbp)` - Opens a connection to the database in [Table Plus](https://tableplus.com/).
* `composer server import-uploads` - Syncs files from `content/uploads` to the S3 container.
31 changes: 29 additions & 2 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ protected function configure() {
shell
Database commands:
db Log into MySQL on the Database server
db sequel Generates an SPF file for Sequel Pro
db (sequel|spf) Opens Sequel Pro/Sequel Ace with the database connection
db (tableplus|tbp) Opens TablePlus with the database connection
db info Prints out Database connection details
db exec -- "<query>" Run and output the result of a SQL query.
SSL commands:
Expand Down Expand Up @@ -658,7 +659,9 @@ protected function db( InputInterface $input, OutputInterface $output ) {
EOT;
$output->write( $db_info );
break;

case 'sequel':
case 'spf':
if ( php_uname( 's' ) !== 'Darwin' ) {
$output->writeln( '<error>This command is only supported on MacOS, use composer server db info to see the database connection details.</error>' );
return 1;
Expand All @@ -676,10 +679,32 @@ protected function db( InputInterface $input, OutputInterface $output ) {

exec( "open $output_file_path", $null, $return_val );
if ( $return_val !== 0 ) {
$output->writeln( '<error>You must have Sequel Pro (https://www.sequelpro.com) installed to use this command</error>' );
$output->writeln( '<error>You must have Sequel Pro (https://www.sequelpro.com) or Sequel Ace (https://sequel-ace.com/) installed to use this command</error>' );
}

break;

case 'tableplus':
case 'tbp':
$connection_data = $this->get_db_connection_data();
$url = sprintf(
'mysql://%s:%s@%s:%s/%s',
$connection_data['MYSQL_USER'],
$connection_data['MYSQL_PASSWORD'],
$connection_data['HOST'],
$connection_data['PORT'],
$connection_data['MYSQL_DATABASE']
);
$url .= '?' . http_build_query( [
'name' => $this->get_project_subdomain(),
'env' => 'local',
] );
exec( sprintf( 'open "%s"', $url ), $null, $return_val );
if ( $return_val !== 0 ) {
$output->writeln( '<error>You must have TablePlus (https://tableplus.com/) installed to use this command</error>' );
}
break;

case 'exec':
$query = $input->getArgument( 'options' )[1] ?? null;
if ( empty( $query ) ) {
Expand All @@ -692,10 +717,12 @@ protected function db( InputInterface $input, OutputInterface $output ) {
// phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
passthru( "$base_command mysql --database=wordpress --user=root -e \"$query\"", $return_val );
break;

case null:
// phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
passthru( "$base_command mysql --database=wordpress --user=root", $return_val );
break;

default:
$output->writeln( "<error>The subcommand $db is not recognized</error>" );
$return_val = 1;
Expand Down

0 comments on commit 309a0be

Please sign in to comment.