<feed xmlns='http://www.w3.org/2005/Atom'>
<title>dbshell-rails, branch add-support-for-shell-aliased-database-commands</title>
<subtitle>A Rake task for Ruby on Rails to painlessly open a database shell</subtitle>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/'/>
<entry>
<title>Try to add support for shell aliases through Ruby's `Kernel.exec`</title>
<updated>2017-04-29T22:23:22+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T22:23:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=1b79a1dc72e703d975effa2de806c9afd9dbaa81'/>
<id>1b79a1dc72e703d975effa2de806c9afd9dbaa81</id>
<content type='text'>
Work in progress.

Ruby's `system` and `exec` don't load shell aliases, so the executables
defined in `EXECUTABLE_NAME` will always be the ones used to launch
database shells.

The trouble is, users might have installed the command with a different
name (as in "mysql5"), or they might not have the command on their path
(as in my case when using Postgres.app).

Apparently you can use an interactive or login shell to get aliases
(using the `-l` or `-i` flags, which do slightly different things,
sourcing .profile and .bashrc separately). Here's what I was following:

http://stackoverflow.com/questions/12060863/python-subprocess-call-a-bash-alias/25099813#25099813

Unfortunately I haven't been able to get it to work. Dropping this for
now.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Work in progress.

Ruby's `system` and `exec` don't load shell aliases, so the executables
defined in `EXECUTABLE_NAME` will always be the ones used to launch
database shells.

The trouble is, users might have installed the command with a different
name (as in "mysql5"), or they might not have the command on their path
(as in my case when using Postgres.app).

Apparently you can use an interactive or login shell to get aliases
(using the `-l` or `-i` flags, which do slightly different things,
sourcing .profile and .bashrc separately). Here's what I was following:

http://stackoverflow.com/questions/12060863/python-subprocess-call-a-bash-alias/25099813#25099813

Unfortunately I haven't been able to get it to work. Dropping this for
now.
</pre>
</div>
</content>
</entry>
<entry>
<title>dbshell.rake: Add a short description to our task</title>
<updated>2017-04-29T21:47:42+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T21:47:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=f59507205062a0910d8ec9bd41269c0d0e9c3296'/>
<id>f59507205062a0910d8ec9bd41269c0d0e9c3296</id>
<content type='text'>
This has the additional benefit of making it appear in the `rake -T`
output.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This has the additional benefit of making it appear in the `rake -T`
output.
</pre>
</div>
</content>
</entry>
<entry>
<title>dbshell.rake: Add alias to `rake db:shell`</title>
<updated>2017-04-29T21:43:01+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T21:43:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=96ffac15299beca07a0671cdbed13b137a9aa4c4'/>
<id>96ffac15299beca07a0671cdbed13b137a9aa4c4</id>
<content type='text'>
Provide two ways of accessing the task. One saves a character (":") and
is reminiscent of the Django command that this project is inspired by.
The other is more Rails-like and is consistent with the other
`db:`-prefixed Rails Rake tasks.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Provide two ways of accessing the task. One saves a character (":") and
is reminiscent of the Django command that this project is inspired by.
The other is more Rails-like and is consistent with the other
`db:`-prefixed Rails Rake tasks.
</pre>
</div>
</content>
</entry>
<entry>
<title>DBShell::Client::Postgres: Convert port to string</title>
<updated>2017-04-29T21:32:17+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T21:32:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=3c522fc313f76dfbb7d1e87703965780245a432c'/>
<id>3c522fc313f76dfbb7d1e87703965780245a432c</id>
<content type='text'>
Turns out the port actually did need to be a string, contrary to what I
had assumed in e89275bc787ae17bc698ac8cdb8cdaf5ebeb7852. I ended up with
this error when passing a specific port in a real test:

    $ bake dbshell
    rake aborted!
    TypeError: no implicit conversion of Fixnum into String
    .../lib/dbshell/client/postgres.rb:8:in `exec'
    .../lib/dbshell/client/postgres.rb:8:in `runshell'
    .../lib/dbshell/client/database.rb:24:in `runshell'
    .../lib/dbshell/rails/tasks/dbshell.rake:6:in `block in &lt;top (required)&gt;'
    .../versions/2.3.3/bin/bundle:22:in `load'
    .../versions/2.3.3/bin/bundle:22:in `&lt;main&gt;'
    Tasks: TOP =&gt; dbshell
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Turns out the port actually did need to be a string, contrary to what I
had assumed in e89275bc787ae17bc698ac8cdb8cdaf5ebeb7852. I ended up with
this error when passing a specific port in a real test:

    $ bake dbshell
    rake aborted!
    TypeError: no implicit conversion of Fixnum into String
    .../lib/dbshell/client/postgres.rb:8:in `exec'
    .../lib/dbshell/client/postgres.rb:8:in `runshell'
    .../lib/dbshell/client/database.rb:24:in `runshell'
    .../lib/dbshell/rails/tasks/dbshell.rake:6:in `block in &lt;top (required)&gt;'
    .../versions/2.3.3/bin/bundle:22:in `load'
    .../versions/2.3.3/bin/bundle:22:in `&lt;main&gt;'
    Tasks: TOP =&gt; dbshell
</pre>
</div>
</content>
</entry>
<entry>
<title>DBShell::Client::Database: Add support for the 'postgis' adapter</title>
<updated>2017-04-29T21:26:59+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T21:26:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=ad34e0127eae4965f4e48c132e06b3dfba474d18'/>
<id>ad34e0127eae4965f4e48c132e06b3dfba474d18</id>
<content type='text'>
PostGIS is, for our purposes, no different from Postgres. Both should
launch `psql`.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
PostGIS is, for our purposes, no different from Postgres. Both should
launch `psql`.
</pre>
</div>
</content>
</entry>
<entry>
<title>rails.rb: Simplify the Rake task loader call</title>
<updated>2017-04-29T21:15:00+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T21:15:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=d976bb250e81c48f95eee50130e17c92a3e20a32'/>
<id>d976bb250e81c48f95eee50130e17c92a3e20a32</id>
<content type='text'>
Since we only have a single *.rake file, we can get away with making
this less general. Doing so condenses what was there previously into a
single line and is arguably more explicit.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Since we only have a single *.rake file, we can get away with making
this less general. Doing so condenses what was there previously into a
single line and is arguably more explicit.
</pre>
</div>
</content>
</entry>
<entry>
<title>rails.rb: Move Rake task loader outside of the module context</title>
<updated>2017-04-29T21:10:33+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T21:10:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=b32dfa416313a762c3e74bdd1692b36001bfb050'/>
<id>b32dfa416313a762c3e74bdd1692b36001bfb050</id>
<content type='text'>
I don't think the load call really needs to be inside the module, as
evidenced by
https://github.com/paulelliott/fabrication/blob/b470cd817e1973c14e3253cd76606cf934942ca1/lib/fabrication.rb
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
I don't think the load call really needs to be inside the module, as
evidenced by
https://github.com/paulelliott/fabrication/blob/b470cd817e1973c14e3253cd76606cf934942ca1/lib/fabrication.rb
</pre>
</div>
</content>
</entry>
<entry>
<title>Integrate MySQL support</title>
<updated>2017-04-29T20:58:11+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T20:58:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=fb9ff6eb8cbad57b3ca2bbd58dc098f208edd1e1'/>
<id>fb9ff6eb8cbad57b3ca2bbd58dc098f208edd1e1</id>
<content type='text'>
* Create a `.runshell()` method in `DBShell::Client::MySQL`
* Delegate to that class &amp; method from `DBShell::Client::Database`
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Create a `.runshell()` method in `DBShell::Client::MySQL`
* Delegate to that class &amp; method from `DBShell::Client::Database`
</pre>
</div>
</content>
</entry>
<entry>
<title>Rename `InvalidDatabaseAdapter` to `UnsupportedDatabaseAdapter`</title>
<updated>2017-04-29T20:54:27+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T20:54:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=56a002d2681431b34be36cf7247dc41a313601d9'/>
<id>56a002d2681431b34be36cf7247dc41a313601d9</id>
<content type='text'>
Tried this out with MySQL, and got this error since I haven't integrated
it yet. It struck me that "Invalid" doesn't make any sense. Really it's
something that is possible to do but that our gem doesn't support, so we
should be clearer about that fact.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Tried this out with MySQL, and got this error since I haven't integrated
it yet. It struck me that "Invalid" doesn't make any sense. Really it's
something that is possible to do but that our gem doesn't support, so we
should be clearer about that fact.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add `DBShell::Client::MySQL`</title>
<updated>2017-04-29T20:49:10+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2017-04-29T20:49:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/dbshell-rails/commit/?id=575141e4efc770a4207eb5d905819d4017731f65'/>
<id>575141e4efc770a4207eb5d905819d4017731f65</id>
<content type='text'>
For now only includes a `.build_command()` method.

Inspired again by:
https://github.com/django/django/blob/66150f7cf61bc09547fa98586790df596eff6d77/django/db/backends/mysql/client.py

although in our case we haven't handled some of the more exotic options.
Eventually we'll probably have to do that.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
For now only includes a `.build_command()` method.

Inspired again by:
https://github.com/django/django/blob/66150f7cf61bc09547fa98586790df596eff6d77/django/db/backends/mysql/client.py

although in our case we haven't handled some of the more exotic options.
Eventually we'll probably have to do that.
</pre>
</div>
</content>
</entry>
</feed>
