sequel_tools 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +27 -0
- data/lib/sequel_tools.rb +1 -0
- data/lib/sequel_tools/actions/shell.rb +33 -0
- data/lib/sequel_tools/actions/shell_postgres.rb +21 -0
- data/lib/sequel_tools/all_actions.rb +2 -0
- data/lib/sequel_tools/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 437ee89e0a2b2873e1651f948c8a89fc1a0aedf6
|
4
|
+
data.tar.gz: 4ba17eb0f479f61e39fb02be3caf45598a269115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d59d32bc56d2d39f6bf378c7be5713b253162b7f48dbca61f922d23660a5137332a2070b2fec00dccebb6fd25a2a880e6fea8575c347f758f57ce3c99c5d6bd
|
7
|
+
data.tar.gz: 15cce1e67d59678423f000e8ab192e4205726eb2f9939623b8f68eccaf7c80235f19e964a0f367aabc95d4af71b1e0e9e118b6cecbbbcef3666839d57784413b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -50,6 +50,7 @@ base_config = SequelTools.base_config(
|
|
50
50
|
sql_log_level: :debug,
|
51
51
|
dump_schema_on_migrate: false, # it's a good idea to enable it for the reference environment
|
52
52
|
pg_dump: 'pg_dump', # command used to run pg_dump
|
53
|
+
pg_dump: 'psql', # command used to run psql when calling rake db:shell if adapter is postgres
|
53
54
|
db_migrations_location: 'db/migrations',
|
54
55
|
schema_location: 'db/migrations/schema.sql',
|
55
56
|
seeds_location: 'db/seeds.rb',
|
@@ -71,6 +72,32 @@ Then you are able to run several tasks (`rake -T` will list all supported):
|
|
71
72
|
rake db:new_migration[migration_name]
|
72
73
|
rake db:migrate
|
73
74
|
rake dbtest:setup
|
75
|
+
rake dbtest:shell
|
76
|
+
|
77
|
+
You may define your own command to open a shell to your database upon the 'db:shell' task.
|
78
|
+
PostgreSQL is supported out-of-the-box, but if it wasn't, here's a sample script that would
|
79
|
+
get the job done:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
#!/bin/bash
|
83
|
+
|
84
|
+
# name it like ~/bin/opensql for example and give it execution permission
|
85
|
+
|
86
|
+
PGDATABASE=$DBNAME
|
87
|
+
PGHOST=$DBHOST
|
88
|
+
PGPORT=$DBPORT
|
89
|
+
PGUSER=$DBUSERNAME
|
90
|
+
PGPASSWORD=$DBPASSWORD
|
91
|
+
psql
|
92
|
+
```
|
93
|
+
|
94
|
+
Then you may pass `shell_command: '~/bin/opensql'` to `SequelTools.base_config`.
|
95
|
+
|
96
|
+
Alternatively you can define the `shell_#{dbadapter}` action if you prefer. Take a look at
|
97
|
+
the implementation for `shell_postgres` to see how to do that. If you want to share that action
|
98
|
+
with others you may either submit a pull request to this project or create a separate gem to
|
99
|
+
add support for your database to `sequel_tools`, which wouldn't require waiting for me to
|
100
|
+
approve your pull requests and you'd be able to maintain it independently.
|
74
101
|
|
75
102
|
## Development and running tests
|
76
103
|
|
data/lib/sequel_tools.rb
CHANGED
@@ -6,6 +6,7 @@ module SequelTools
|
|
6
6
|
DEFAULT_CONFIG = {
|
7
7
|
project_root: nil,
|
8
8
|
pg_dump: 'pg_dump', # command used to run pg_dump
|
9
|
+
psql: 'psql', # command used to run psql
|
9
10
|
maintenancedb: 'postgres', # DB to connect to for creating/dropping databases
|
10
11
|
db_migrations_location: 'db/migrations',
|
11
12
|
schema_location: 'db/migrations/schema.sql',
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require_relative '../actions_manager'
|
4
|
+
|
5
|
+
class SequelTools::ActionsManager
|
6
|
+
# TODO: this action is not currently tested automatically as it's not critical and not
|
7
|
+
# trivial to write a test for
|
8
|
+
Action.register :shell, 'Open an interactive shell to the database' do |args, context|
|
9
|
+
begin
|
10
|
+
Action[:connect_db].run({}, context)
|
11
|
+
rescue
|
12
|
+
puts 'Database does not exist - aborting.'
|
13
|
+
exit 1
|
14
|
+
else
|
15
|
+
c = context[:config]
|
16
|
+
if shell_command = c[:shell_command]
|
17
|
+
env = {
|
18
|
+
'DBHOST' => c[:dbhost], 'DBPORT' => c[:dbport].to_s, 'DBUSERNAME' => c[:username],
|
19
|
+
'DBPASSWORD' => c[:password].to_s, 'DBNAME' => c[:dbname]
|
20
|
+
}
|
21
|
+
exec env, shell_command
|
22
|
+
else
|
23
|
+
unless action = Action[:"shell_#{c[:dbadapter]}"]
|
24
|
+
puts "Opening an interactive shell is not currently supported for #{c[:dbadapter]}." +
|
25
|
+
" Aborting"
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
action.run({}, context)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require_relative '../actions_manager'
|
4
|
+
require_relative '../pg_helper'
|
5
|
+
|
6
|
+
class SequelTools::ActionsManager
|
7
|
+
# TODO: this action is not currently tested automatically as it's not critical and not
|
8
|
+
# trivial to write a test for
|
9
|
+
Action.register :shell_postgres, nil do |args, context|
|
10
|
+
c = context[:config]
|
11
|
+
psql = c[:psql]
|
12
|
+
env = {
|
13
|
+
'PGDATABASE' => c[:dbname],
|
14
|
+
'PGHOST' => c[:dbhost],
|
15
|
+
'PGPORT' => c[:dbport].to_s,
|
16
|
+
'PGUSER' => c[:username],
|
17
|
+
'PGPASSWORD' => c[:password].to_s,
|
18
|
+
}
|
19
|
+
exec env, psql
|
20
|
+
end
|
21
|
+
end
|
data/lib/sequel_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Rosenfeld Rosas
|
@@ -120,6 +120,8 @@ files:
|
|
120
120
|
- lib/sequel_tools/actions/schema_load.rb
|
121
121
|
- lib/sequel_tools/actions/seed.rb
|
122
122
|
- lib/sequel_tools/actions/setup.rb
|
123
|
+
- lib/sequel_tools/actions/shell.rb
|
124
|
+
- lib/sequel_tools/actions/shell_postgres.rb
|
123
125
|
- lib/sequel_tools/actions/status.rb
|
124
126
|
- lib/sequel_tools/actions/up.rb
|
125
127
|
- lib/sequel_tools/actions/version.rb
|