seamus-pasqual 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +11 -0
- data/CHANGELOG +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +2 -0
- data/bin/pasqual +6 -0
- data/lib/pasqual.rb +14 -0
- data/lib/pasqual/arglist.rb +19 -0
- data/lib/pasqual/cli.rb +118 -0
- data/lib/pasqual/command.rb +65 -0
- data/lib/pasqual/createdb.rb +22 -0
- data/lib/pasqual/database.rb +42 -0
- data/lib/pasqual/dropdb.rb +20 -0
- data/lib/pasqual/psql.rb +22 -0
- data/lib/pasqual/version.rb +3 -0
- data/pasqual.gemspec +27 -0
- data/spec/pasqual/database_spec.rb +55 -0
- data/spec/pasqual_spec.rb +17 -0
- data/spec/spec_helper.rb +5 -0
- metadata +140 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3b6ea3b9ef075f0d38fd1211c83e1ac7ca6ac288
|
|
4
|
+
data.tar.gz: 2d68abe021da7274c9ec7d47ebca6dfd57099830
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 518ac9fc203fa42988edd8361931c24c64958b8bd8ebc32a0d00b23df71d4109bdcdd33780e372b814917e0f7280586fb788a8af1714114a4e9c7b91249ddbee
|
|
7
|
+
data.tar.gz: 72e5ee83324396b9ff12eb47ba738639914b91fc9f545a42b3fbb19fb7924b24fa723f94ace4902f662801e63dc2ef6122e004124c525f4ae34b9cd3858fd0df
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Derek Kastner
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Pasqual
|
|
2
|
+
|
|
3
|
+
Run Postgres CLI commands with the help of database settings configured with environment variables.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'pasqual'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install pasqual
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
First, get an instance of Pasqual:
|
|
26
|
+
|
|
27
|
+
``` ruby
|
|
28
|
+
psql = Pasqual.for ENV['DATABASE_URL']
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### createdb
|
|
32
|
+
|
|
33
|
+
Createdb automatically uses the database name defined in `ENV`.
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
psql.createdb
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
A custom name can optionally be specified:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
psql.createdb 'foodb'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### dropdb
|
|
46
|
+
|
|
47
|
+
Dropdb automatically uses the database name defined in `ENV`.
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
psql.dropdb
|
|
51
|
+
```
|
|
52
|
+
A custom name can optionally be specified:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
psql.dropdb 'foodb'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### command
|
|
59
|
+
|
|
60
|
+
Executes an SQL script, the same as piping text into the psql command.
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
psql.command "SELECT * from users;"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### pipe
|
|
67
|
+
|
|
68
|
+
You can pipe a file into the `psql` command:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
psql.pipe_sql '/path/to/file.sql'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Contributing
|
|
75
|
+
|
|
76
|
+
1. Fork it ( https://github.com/[my-github-username]/pasqual/fork )
|
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
80
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/pasqual
ADDED
data/lib/pasqual.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Pasqual
|
|
2
|
+
|
|
3
|
+
module Arglist
|
|
4
|
+
|
|
5
|
+
def self.args(username, password, host, port, name)
|
|
6
|
+
list = []
|
|
7
|
+
list << '-h' << host if host.to_s.length > 0
|
|
8
|
+
list << '-U' << username if username.to_s.length > 0
|
|
9
|
+
list << '-p' << port.to_s if port.to_s.length > 0
|
|
10
|
+
list << '-w' if password.to_s.length == 0
|
|
11
|
+
list << '--no-psqlrc'
|
|
12
|
+
list << '--pset' << 'pager=off'
|
|
13
|
+
|
|
14
|
+
list + [name]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
data/lib/pasqual/cli.rb
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require 'thor'
|
|
2
|
+
|
|
3
|
+
require 'pasqual'
|
|
4
|
+
|
|
5
|
+
module Pasqual
|
|
6
|
+
class CLI < Thor
|
|
7
|
+
def self.exit_on_failure?
|
|
8
|
+
true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
desc "create DATABASE_URL", "create database"
|
|
12
|
+
def create(url = nil)
|
|
13
|
+
puts "Creating #{pasqual(url).name}"
|
|
14
|
+
pasqual(url).createdb
|
|
15
|
+
rescue Pasqual::Createdb::AlreadyExists
|
|
16
|
+
puts "#{pasqual(url).name} already exists, skipped creation"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
desc "drop DATABASE_URL", "drop database"
|
|
20
|
+
def drop(url = nil)
|
|
21
|
+
puts "Dropping #{pasqual(url).name}"
|
|
22
|
+
pasqual(url).dropdb
|
|
23
|
+
rescue Pasqual::Dropdb::Failed
|
|
24
|
+
puts "Could not drop #{pasqual(url).name}, skipped"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc "poll DATABASE_URL", "poll for the existence of a database server"
|
|
28
|
+
def poll(url = nil)
|
|
29
|
+
say "Waiting for Postgres to come available"
|
|
30
|
+
if attempt_connect(url)
|
|
31
|
+
say "Connected!"
|
|
32
|
+
exit 0
|
|
33
|
+
else
|
|
34
|
+
say "Failed to connect"
|
|
35
|
+
exit 1
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
desc "reset [SQL_FILE] [DATABASE_URL]", "drop, create, structure"
|
|
40
|
+
def reset(path = nil, url = nil)
|
|
41
|
+
drop(url)
|
|
42
|
+
create(url)
|
|
43
|
+
file(path, url) if path
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "psql [SQL] [DATABASE_URL]", "start a psql console or run an SQL statement"
|
|
47
|
+
def psql(*cmd_args)
|
|
48
|
+
url = nil
|
|
49
|
+
sql_args = []
|
|
50
|
+
cmd_args.each do |arg|
|
|
51
|
+
if arg =~ /postgres:/
|
|
52
|
+
url = arg
|
|
53
|
+
else
|
|
54
|
+
sql_args << arg
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
db = pasqual(url)
|
|
58
|
+
args = Pasqual::Arglist.
|
|
59
|
+
args(db.username, db.password, db.host, db.port, db.name)
|
|
60
|
+
if sql_args.any?
|
|
61
|
+
args << '-c'
|
|
62
|
+
args += sql_args.map(&:inspect)
|
|
63
|
+
puts "Executing in #{db.name}: #{sql_args.inspect}"
|
|
64
|
+
else
|
|
65
|
+
cmd = "psql #{args.join(' ')}"
|
|
66
|
+
end
|
|
67
|
+
puts "Running #{cmd}"
|
|
68
|
+
Kernel.exec({ 'PGPASSWORD' => db.password }, "psql #{args.join(' ')}")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
desc "file PATH [DATABASE_URL]", "execute an SQL script in a file"
|
|
73
|
+
def file(path, url = nil)
|
|
74
|
+
puts "Structuring #{pasqual(url).name}"
|
|
75
|
+
pasqual(url).pipe_sql path
|
|
76
|
+
rescue Errno::EPIPE
|
|
77
|
+
puts "#{pasqual(url).name} doesn't exist, skipped structure"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def pasqual(url)
|
|
83
|
+
@pasqual ||= Pasqual.for(url || ENV['DATABASE_URL'])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def pg_connection(url, no_db: false)
|
|
87
|
+
db = pasqual(url)
|
|
88
|
+
conn = PG::Connection.connect_start(
|
|
89
|
+
host: db.host,
|
|
90
|
+
port: db.port,
|
|
91
|
+
dbname: no_db ? nil : db.name,
|
|
92
|
+
user: db.username,
|
|
93
|
+
password: db.password,
|
|
94
|
+
connect_timeout: (60 * 5))
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def attempt_connect(url)
|
|
98
|
+
require 'pg'
|
|
99
|
+
|
|
100
|
+
timeout = Time.now.to_i + (60 * 5)
|
|
101
|
+
|
|
102
|
+
# Don't connect to a specific database because we may be polling the
|
|
103
|
+
# the server to know whether we can _create_ a database yet.
|
|
104
|
+
conn = pg_connection(url, no_db: true)
|
|
105
|
+
status = conn.connect_poll
|
|
106
|
+
while(Time.now.to_i < timeout && status != PG::PGRES_POLLING_OK) do
|
|
107
|
+
sleep 2
|
|
108
|
+
status = conn.connect_poll
|
|
109
|
+
|
|
110
|
+
conn = pg_connection(url, no_db: true) if status == PG::PGRES_POLLING_FAILED
|
|
111
|
+
puts "Status: #{status.inspect}, Timeout: #{Time.now.to_i - timeout}" if ENV['DEBUG']
|
|
112
|
+
end
|
|
113
|
+
conn.finish
|
|
114
|
+
status == PG::PGRES_POLLING_OK
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require 'pasqual/arglist'
|
|
2
|
+
|
|
3
|
+
module Pasqual
|
|
4
|
+
|
|
5
|
+
class Command
|
|
6
|
+
|
|
7
|
+
def self.execute(program, username, password, host, port, name, file = nil)
|
|
8
|
+
new(program, username, password, host, port, name, file).tap { |c| c.execute }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
attr_accessor :program, :username, :password, :host, :port, :name, :file,
|
|
12
|
+
:output, :status
|
|
13
|
+
|
|
14
|
+
def initialize(program, username, password, host, port, name, file = nil)
|
|
15
|
+
self.program = program
|
|
16
|
+
self.username = username
|
|
17
|
+
self.password = password
|
|
18
|
+
self.host = host
|
|
19
|
+
self.port = port
|
|
20
|
+
self.name = name
|
|
21
|
+
self.file = file
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def execute
|
|
25
|
+
outfile = Tempfile.new("pasqual-#{name}")
|
|
26
|
+
outfile.sync = true
|
|
27
|
+
|
|
28
|
+
process = ChildProcess.build program,
|
|
29
|
+
*Arglist.args(username, password, host, port, name)
|
|
30
|
+
|
|
31
|
+
process.io.stdout = process.io.stderr = outfile
|
|
32
|
+
|
|
33
|
+
process.duplex = true if file
|
|
34
|
+
|
|
35
|
+
# TODO: find out why piping to stdin doesn't work :(
|
|
36
|
+
ENV['PGPASSWORD'] = password
|
|
37
|
+
process.start
|
|
38
|
+
|
|
39
|
+
if file && File.exist?(file)
|
|
40
|
+
File.open file do |f|
|
|
41
|
+
process.io.stdin.puts f.read
|
|
42
|
+
process.io.stdin.flush
|
|
43
|
+
end
|
|
44
|
+
process.io.stdin.close
|
|
45
|
+
elsif file
|
|
46
|
+
process.io.stdin.puts file
|
|
47
|
+
process.io.stdin.flush
|
|
48
|
+
process.io.stdin.close
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
process.wait
|
|
52
|
+
ENV['PGPASSWORD'] = nil
|
|
53
|
+
|
|
54
|
+
outfile.rewind
|
|
55
|
+
self.output = outfile.read
|
|
56
|
+
self.status = process.exit_code
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def success?
|
|
60
|
+
status == 0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'childprocess'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
|
|
4
|
+
require 'pasqual/command'
|
|
5
|
+
|
|
6
|
+
module Pasqual
|
|
7
|
+
|
|
8
|
+
module Createdb
|
|
9
|
+
class AlreadyExists < StandardError; end
|
|
10
|
+
class Failed < StandardError; end
|
|
11
|
+
|
|
12
|
+
def self.execute(username, password, host, port, name)
|
|
13
|
+
cmd = Command.execute 'createdb', username, password, host, port, name
|
|
14
|
+
|
|
15
|
+
raise AlreadyExists if cmd.output =~ /already exists/
|
|
16
|
+
raise(Failed, cmd.output) unless cmd.success?
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'pasqual/createdb'
|
|
3
|
+
require 'pasqual/dropdb'
|
|
4
|
+
require 'pasqual/psql'
|
|
5
|
+
|
|
6
|
+
module Pasqual
|
|
7
|
+
|
|
8
|
+
class Database
|
|
9
|
+
attr_reader :username, :password, :host, :port, :name
|
|
10
|
+
|
|
11
|
+
def initialize(url)
|
|
12
|
+
uri = URI.parse url
|
|
13
|
+
@username = uri.user
|
|
14
|
+
@password = uri.password
|
|
15
|
+
@host = uri.host
|
|
16
|
+
@port = uri.port
|
|
17
|
+
@name = uri.path.sub(/^\//, '')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def port
|
|
21
|
+
@port ||= 5432
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def createdb(create_name = name)
|
|
25
|
+
Createdb.execute username, password, host, port, create_name
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def dropdb(drop_name = name)
|
|
29
|
+
Dropdb.execute username, password, host, port, drop_name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def command(statement)
|
|
33
|
+
Psql.command statement, username, password, host, port, name
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def pipe_sql(file, dbname = name)
|
|
37
|
+
Psql.pipe file, username, password, host, port, dbname
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'childprocess'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
|
|
4
|
+
require 'pasqual/command'
|
|
5
|
+
|
|
6
|
+
module Pasqual
|
|
7
|
+
|
|
8
|
+
module Dropdb
|
|
9
|
+
class Failed < StandardError; end
|
|
10
|
+
|
|
11
|
+
def self.execute(username, password, host, port, name)
|
|
12
|
+
cmd = Command.execute 'dropdb', username, password, host, port, name
|
|
13
|
+
|
|
14
|
+
raise Failed unless cmd.success?
|
|
15
|
+
true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
data/lib/pasqual/psql.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Pasqual
|
|
2
|
+
|
|
3
|
+
module Psql
|
|
4
|
+
class Failed < StandardError; end
|
|
5
|
+
|
|
6
|
+
def self.pipe(file, username, password, host, port, name)
|
|
7
|
+
cmd = Command.execute 'psql', username, password, host, port, name, file
|
|
8
|
+
|
|
9
|
+
raise Failed unless cmd.success?
|
|
10
|
+
true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.command(statement, username, password, host, port, name)
|
|
14
|
+
cmd = Command.execute 'psql', username, password, host, port, name, statement
|
|
15
|
+
|
|
16
|
+
raise Failed unless cmd.success?
|
|
17
|
+
cmd.output
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
data/pasqual.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'pasqual/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "seamus-pasqual"
|
|
8
|
+
spec.version = Pasqual::VERSION
|
|
9
|
+
spec.authors = ["Derek Kastner"]
|
|
10
|
+
spec.email = ["dkastner@gmail.com"]
|
|
11
|
+
spec.summary = %q{Interface easily with postgres CLI tools}
|
|
12
|
+
spec.description = %q{Shortcuts for postgres commands, with option to use ENV-configured conenction URLs}
|
|
13
|
+
spec.homepage = "https://github.com/dkastner/pasqual"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_runtime_dependency "childprocess", "~> 0.5"
|
|
22
|
+
spec.add_runtime_dependency "thor", "~> 0.5"
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0.0"
|
|
27
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'securerandom'
|
|
3
|
+
require 'pasqual/database'
|
|
4
|
+
|
|
5
|
+
describe Pasqual::Database do
|
|
6
|
+
let(:database) { Pasqual::Database.new ENV['DATABASE_URL'] }
|
|
7
|
+
|
|
8
|
+
describe '#createdb' do
|
|
9
|
+
let(:name) { SecureRandom.hex(10) }
|
|
10
|
+
|
|
11
|
+
after :each do
|
|
12
|
+
database.dropdb name
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'creates a database' do
|
|
16
|
+
expect(database.createdb(name)).to be true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'raises an error if a database already exists' do
|
|
20
|
+
database.createdb name
|
|
21
|
+
|
|
22
|
+
expect do
|
|
23
|
+
database.createdb name
|
|
24
|
+
end.to raise_error(Pasqual::Createdb::AlreadyExists)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#command' do
|
|
30
|
+
before { database.createdb rescue Pasqual::Dropdb::Failed }
|
|
31
|
+
|
|
32
|
+
it 'runs an sql command' do
|
|
33
|
+
expect do
|
|
34
|
+
database.command "SELECT 0;"
|
|
35
|
+
end.to_not raise_error
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#pipe_sql' do
|
|
41
|
+
before { database.createdb rescue Pasqual::Dropdb::Failed }
|
|
42
|
+
|
|
43
|
+
it 'runs an sql script file' do
|
|
44
|
+
file = Tempfile.new 'sql-script'
|
|
45
|
+
file.puts "SELECT 0;"
|
|
46
|
+
|
|
47
|
+
expect do
|
|
48
|
+
database.pipe_sql file.path
|
|
49
|
+
end.to_not raise_error
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'securerandom'
|
|
3
|
+
require 'pasqual'
|
|
4
|
+
|
|
5
|
+
describe Pasqual do
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
|
|
9
|
+
it 'returns a Pasqual::Database configured for a URL' do
|
|
10
|
+
p = Pasqual.new
|
|
11
|
+
expect(p).to be_a(Pasqual::Database)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: seamus-pasqual
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Derek Kastner
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-10-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: childprocess
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.5'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.5'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: thor
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.5'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.5'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.6'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.6'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '10.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '10.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 3.0.0
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 3.0.0
|
|
83
|
+
description: Shortcuts for postgres commands, with option to use ENV-configured conenction
|
|
84
|
+
URLs
|
|
85
|
+
email:
|
|
86
|
+
- dkastner@gmail.com
|
|
87
|
+
executables:
|
|
88
|
+
- pasqual
|
|
89
|
+
extensions: []
|
|
90
|
+
extra_rdoc_files: []
|
|
91
|
+
files:
|
|
92
|
+
- ".gitignore"
|
|
93
|
+
- ".travis.yml"
|
|
94
|
+
- CHANGELOG
|
|
95
|
+
- Gemfile
|
|
96
|
+
- LICENSE.txt
|
|
97
|
+
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- bin/pasqual
|
|
100
|
+
- lib/pasqual.rb
|
|
101
|
+
- lib/pasqual/arglist.rb
|
|
102
|
+
- lib/pasqual/cli.rb
|
|
103
|
+
- lib/pasqual/command.rb
|
|
104
|
+
- lib/pasqual/createdb.rb
|
|
105
|
+
- lib/pasqual/database.rb
|
|
106
|
+
- lib/pasqual/dropdb.rb
|
|
107
|
+
- lib/pasqual/psql.rb
|
|
108
|
+
- lib/pasqual/version.rb
|
|
109
|
+
- pasqual.gemspec
|
|
110
|
+
- spec/pasqual/database_spec.rb
|
|
111
|
+
- spec/pasqual_spec.rb
|
|
112
|
+
- spec/spec_helper.rb
|
|
113
|
+
homepage: https://github.com/dkastner/pasqual
|
|
114
|
+
licenses:
|
|
115
|
+
- MIT
|
|
116
|
+
metadata: {}
|
|
117
|
+
post_install_message:
|
|
118
|
+
rdoc_options: []
|
|
119
|
+
require_paths:
|
|
120
|
+
- lib
|
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
requirements: []
|
|
132
|
+
rubyforge_project:
|
|
133
|
+
rubygems_version: 2.6.8
|
|
134
|
+
signing_key:
|
|
135
|
+
specification_version: 4
|
|
136
|
+
summary: Interface easily with postgres CLI tools
|
|
137
|
+
test_files:
|
|
138
|
+
- spec/pasqual/database_spec.rb
|
|
139
|
+
- spec/pasqual_spec.rb
|
|
140
|
+
- spec/spec_helper.rb
|