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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cedf58b1f6a6ae3c117160b80d67dc480b7e632
4
- data.tar.gz: 5475ddb9d818523ae54c1120a2a61e81dfbf778a
3
+ metadata.gz: 437ee89e0a2b2873e1651f948c8a89fc1a0aedf6
4
+ data.tar.gz: 4ba17eb0f479f61e39fb02be3caf45598a269115
5
5
  SHA512:
6
- metadata.gz: 8ec010df4d9227e688cb0fa27ab02050862cefbf0331111a90237801108e0ce8ac53803bc36c65fe4c23384a5b1af7f216b80689841ca843661ac1b3e214fe58
7
- data.tar.gz: 69685b37ca21f1c4fcc54273bb304348e125f773182d6a5eee264b1b7aa3260f54f3ce170ee644ffd770ac2c339ed9ea20ab0dd59e73e93cefb015ba46de108b
6
+ metadata.gz: 3d59d32bc56d2d39f6bf378c7be5713b253162b7f48dbca61f922d23660a5137332a2070b2fec00dccebb6fd25a2a880e6fea8575c347f758f57ce3c99c5d6bd
7
+ data.tar.gz: 15cce1e67d59678423f000e8ab192e4205726eb2f9939623b8f68eccaf7c80235f19e964a0f367aabc95d4af71b1e0e9e118b6cecbbbcef3666839d57784413b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sequel_tools (0.1.2)
4
+ sequel_tools (0.1.3)
5
5
  sequel
6
6
 
7
7
  GEM
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
 
@@ -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
@@ -17,3 +17,5 @@ require_relative 'actions/redo'
17
17
  require_relative 'actions/version'
18
18
  require_relative 'actions/rollback'
19
19
  require_relative 'actions/status'
20
+ require_relative 'actions/shell_postgres'
21
+ require_relative 'actions/shell'
@@ -1,5 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  module SequelTools
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
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.2
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