Skip to content

Instantly share code, notes, and snippets.

@aaronbauman
Last active June 10, 2020 09:28
Show Gist options
  • Save aaronbauman/f50cc691eb3ed60a358c to your computer and use it in GitHub Desktop.
Save aaronbauman/f50cc691eb3ed60a358c to your computer and use it in GitHub Desktop.
Connect to a Pantheon database in Sequel Pro
#!/bin/sh
# exit on any errors:
set -e
if [ $# -lt 1 ]
then
echo "Usage: $0 @pantheon-alias"
exit 1
fi
# Path to drush goes here:
DRUSH='/opt/local/bin/drush'
# can't do this anymore:
# PANTHEON_USER='XXXX'
# PANTHEON_PASS='XXXX'
# see the following file:
TEMPLATE='spf-template.spf'
# may need to change this:
TMP_SPF='/tmp/tmp.spf'
# pauth doesn't work anymore. Need to use terminus login instead before running this script:
# $DRUSH pauth $PANTHEON_USER --password=$PANTHEON_PASS
# paliases still works for now:
$DRUSH paliases
# could also change this to "terminus sites aliases"
echo "fetching connection string"
CONNECTION_STRING=`$DRUSH $1 sql-connect`
echo $CONNECTION_STRING
DATABASE=`echo $CONNECTION_STRING | sed -e 's/.*--database=\([^\\ ]*\).*/\1/g'`
HOST=`echo $CONNECTION_STRING | sed -e 's/.*--host=\([^\\ ]*\).*/\1/g'`
PORT=`echo $CONNECTION_STRING | sed -e 's/.*--port=\([^\\ ]*\).*/\1/g'`
PASSWORD=`echo $CONNECTION_STRING | sed -e 's/.*--password=\([^\\ ]*\).*/\1/g'`
USER=`echo $CONNECTION_STRING | sed -e 's/.*--user=\([^\\ ]*\).*/\1/g'`
# This is for Sequel Pro:
eval "echo \"$(< $TEMPLATE)\""
# For some reason, Sequel Pro or Open do not behave the same way given the -f
# flag compared to opening a file from file system. So, we write to a tmp file.
eval "echo \"$(< $TEMPLATE)\"" > $TMP_SPF
# Swap this out to fit your system:
open $TMP_SPF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ContentFilters</key>
<dict/>
<key>auto_connect</key>
<true/>
<key>data</key>
<dict>
<key>connection</key>
<dict>
<key>database</key>
<string>${DATABASE}</string>
<key>host</key>
<string>${HOST}</string>
<key>name</key>
<string>${USER}@${HOST}</string>
<key>password</key>
<string>${PASSWORD}</string>
<key>port</key>
<integer>${PORT}</integer>
<key>rdbms_type</key>
<string>mysql</string>
<key>sslCACertFileLocation</key>
<string></string>
<key>sslCACertFileLocationEnabled</key>
<integer>0</integer>
<key>sslCertificateFileLocation</key>
<string></string>
<key>sslCertificateFileLocationEnabled</key>
<integer>0</integer>
<key>sslKeyFileLocation</key>
<string></string>
<key>sslKeyFileLocationEnabled</key>
<integer>0</integer>
<key>type</key>
<string>SPTCPIPConnection</string>
<key>useSSL</key>
<integer>0</integer>
<key>user</key>
<string>${USER}</string>
</dict>
<key>session</key>
<dict/>
</dict>
<key>encrypted</key>
<false/>
<key>format</key>
<string>connection</string>
<key>queryFavorites</key>
<array/>
<key>queryHistory</key>
<array/>
<key>rdbms_type</key>
<string>mysql</string>
<key>rdbms_version</key>
<string>5.5.39-MariaDB-log</string>
<key>version</key>
<integer>1</integer>
</dict>
</plist>
@derimagia
Copy link

I expanded this to a plugin for terminus: https://github.com/derimagia/terminus-pancakes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment