Pgai
Simple CLI wrapper around Postgres.ai CLI to drop directly into a PSQL session.
Installation
Install the gem by executing:
gem install pgai
Configuration
For an overview of available commands, execute:
pgai -h
Before usage pgai config
must be executed and at least an environment must be configured with pgai env add
.
An access token will be required and it can be obtained from: https://console.postgres.ai/gitlab/tokens
Example:
pgai config --dbname=gitlabhq_dblab --prefix=<gitlab handle> --proxy=<alias> --exe=<optional /path/to/dblab>
To configure environments:
pgai env add --alias ci --id ci-database --port 12345
The environment id, port, and proxy domain can be found by clicking on the Connect
button on a database instance page.
Configuring the proxy attributes must be done via the ~/.ssh/config
file. Example:
Host <alias>
HostName <domain.postgres.ai>
User <username>
IdentityFile ~/.ssh/id_ed25519
dblab binary file
This CLI is built around around the dblab
CLI and it looks for it at the following locations:
- at the path specified in the config file if specified when running the
pgai config
command - in
$PATH
- at
~/.dblab/dblab
If it's not found at any of the specified locations, a copy will be downloaded to ~/.dblab/dblab
.
Usage
pgai connect <env alias>
Multiple connect
commands for an environment will connect to the same clone, it won't start a new one.
pgai info <env alias>
prints out a database URL variable that can be used from Rails to integrate with dblab. Example for CI
database:
CI_DATABASE_URL="postgresql://foo:bar@localhost:9000/foo_test" bin/rails c -e test
Features
- multiple psql sessions to the same clone
- multiple environments support
- automatic port forward management
- prevents system sleep while psql sessions are active via
caffeinate
Contributing
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/mbobin/pgai.