sequel_tools 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd0f583b78b874b3cfc1701a277ef182b184c66f
4
- data.tar.gz: 980bc39cff7f7af9fcad83b4cd655d59aca0b3c3
3
+ metadata.gz: 1e39f0b05d9fa1a3655801928321ea74ad10b9b7
4
+ data.tar.gz: 839d553027e487277450f7c86cf0701e587ea950
5
5
  SHA512:
6
- metadata.gz: 912e0711195c5f895b40807d6013e899d6767f878438e2b4b173f910304e69928bf64da3c5c10db3d3ed12a9c768eb362fee42dc1b8726090278553fb86c4534
7
- data.tar.gz: 55bfdf355d5f590e1d6ee16bd2096dce9c686ecbff614335928c96e08bb5477d1539542a1e0860919fc79ba59008c88b5d620f02522ed0d6b3aa1b9f2d1609c2
6
+ metadata.gz: 783fa029e42045bbd212adf41633a4f30fb241142f8df883860d9d34e3d00f81e8487212dc8e88bf60fbf78c7f49d99e59b463b5bf96d56bd184db0b2ef7a669
7
+ data.tar.gz: 6ab2278296861e13d4636daa5f286cacb23f55e3481291137c02f296604f72b7bbb7cbdc60647d87b2c7fad90da881f579a76dc2dad620518172331c3fa270a9
data/.gitignore CHANGED
@@ -10,6 +10,7 @@
10
10
  /spec/sample_project/db/seeds.rb
11
11
  /spec/sample_project/bin/bundle
12
12
  /spec/sample_project/bin/sequel
13
+ /Gemfile.lock
13
14
 
14
15
  # rspec failure tracking
15
16
  .rspec_status
data/.travis.yml CHANGED
@@ -2,5 +2,6 @@ sudo: true
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.4.1
5
+ - jruby-9.1.9.0
5
6
  before_install: scripts/ci/travis-build.sh
6
7
  #before_install: gem install bundler -v 1.16.0
data/README.md CHANGED
@@ -21,6 +21,11 @@ Add this line to your application's Gemfile:
21
21
 
22
22
  ```ruby
23
23
  gem 'sequel_tools'
24
+ gem 'rake'
25
+
26
+ # For PostgreSQL:
27
+ gem 'pg', platform: :mri
28
+ gem 'jdbc-postgres', platform: :jruby
24
29
  ```
25
30
 
26
31
  And then execute:
@@ -54,7 +59,10 @@ base_config = SequelTools.base_config(
54
59
  migrations_location: 'db/migrations',
55
60
  schema_location: 'db/migrations/schema.sql',
56
61
  seeds_location: 'db/seeds.rb',
57
- maintenancedb: 'postgres' # for tasks such as creating the database
62
+ # for tasks such as creating the database:
63
+ # when nil, defaults to the value of the :dbadapter config.
64
+ # This is the database we should connect to before executing "create database dbname"
65
+ maintenancedb: :default,
58
66
  )
59
67
 
60
68
  namespace 'db' do
@@ -71,8 +79,29 @@ Then you are able to run several tasks (`rake -T` will list all supported):
71
79
  rake db:create
72
80
  rake db:new_migration[migration_name]
73
81
  rake db:migrate
82
+ # setup creates the database, loads the latest schema
83
+ # and import seeds when available
74
84
  rake dbtest:setup
75
- rake dbtest:shell
85
+ # reset drops (if existing) then recreate the database, run all migrations
86
+ # and import seeds when available
87
+ rake dbtest:reset
88
+ # shell opens a psql section to the database for the PostgreSQL adapter
89
+ rake db:shell
90
+ # irb runs "bundle exec sequel" pointing to the database and stores the connection in "DB"
91
+ rake db:irb
92
+ rake db:rollback
93
+ rake db:status
94
+ # version displays latest applied migration
95
+ rake db:version
96
+ rake db:seed
97
+ rake db:redo[migration_filename]
98
+ rake db:down[migration_filename]
99
+ rake db:up[migration_filename]
100
+ # schema_dump is called automatically after migrate/rollback/up/down/redo
101
+ # if passing { dump_schema_on_migrate: true } to the config
102
+ rake db:schema_dump
103
+ # database must be empty before calling db:schema_load
104
+ rake db:schema_load
76
105
 
77
106
  You may define your own command to open a shell to your database upon the 'db:shell' task.
78
107
  PostgreSQL is supported out-of-the-box, but if it wasn't, here's a sample script that would
data/lib/sequel_tools.rb CHANGED
@@ -7,7 +7,7 @@ module SequelTools
7
7
  project_root: nil,
8
8
  pg_dump: 'pg_dump', # command used to run pg_dump
9
9
  psql: 'psql', # command used to run psql
10
- maintenancedb: 'postgres', # DB to connect to for creating/dropping databases
10
+ maintenancedb: :default, # DB to connect to for creating/dropping databases
11
11
  migrations_location: 'db/migrations',
12
12
  schema_location: 'db/migrations/schema.sql',
13
13
  seeds_location: 'db/seeds.rb',
@@ -42,4 +42,15 @@ module SequelTools
42
42
  actions_manager.load_all
43
43
  actions_manager.export_as_rake_tasks rake_context
44
44
  end
45
+
46
+ def self.suppress_java_output
47
+ return yield unless RUBY_PLATFORM == 'java'
48
+ require 'java'
49
+ require 'stringio'
50
+ old_err = java.lang.System.err
51
+ java.lang.System.err = java.io.PrintStream.new(StringIO.new.to_outputstream)
52
+ yield
53
+ ensure
54
+ java.lang.System.err = old_err if RUBY_PLATFORM == 'java'
55
+ end
45
56
  end
@@ -0,0 +1,17 @@
1
+ # frozen-string-literal: true
2
+
3
+ require_relative '../actions_manager'
4
+
5
+ SequelTools::ActionsManager::Action.register :before_task, nil do |args, context|
6
+ config = context[:config]
7
+ adapter = config[:dbadapter]
8
+ action = context[:current_action]
9
+ hooks = [:before_any, :"before_#{action.name}", :"before_any_#{adapter}",
10
+ :"before_#{action.name}_#{adapter}"]
11
+ hooks.each do |h|
12
+ next unless a = SequelTools::ActionsManager::Action[h]
13
+ a.run args, context
14
+ context[:"#{h}_processed"] = true
15
+ end
16
+ config[:maintenancedb] = adapter if context[:maintenancedb] == :default
17
+ end
@@ -7,7 +7,9 @@ require_relative '../sequel_tools_logger'
7
7
  SequelTools::ActionsManager::Action.register :connect_db, nil do |args, context|
8
8
  next if context[:db]
9
9
  config = context[:config]
10
- context[:db] = db = Sequel.connect context[:uri_builder].call config
10
+ context[:db] = db = SequelTools.suppress_java_output do
11
+ Sequel.connect context[:uri_builder].call config
12
+ end
11
13
  db.sql_log_level = config[:sql_log_level]
12
14
  db.log_connection_info = false
13
15
  next unless log_level = config[:log_level]
@@ -3,8 +3,6 @@
3
3
  require_relative '../actions_manager'
4
4
 
5
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
6
  description = "Opens an IRB session started as 'sequel uri_to_database' (DB is available to irb)"
9
7
  Action.register :irb, description do |args, context|
10
8
  config = context[:config]
@@ -0,0 +1,14 @@
1
+ # frozen-string-literal: true
2
+
3
+ require_relative '../actions_manager'
4
+ require_relative 'schema_dump_postgres'
5
+ require_relative 'shell_postgres'
6
+
7
+ class SequelTools::ActionsManager
8
+ Action.register :before_any_postgres, nil do |args, context|
9
+ next if context[:before_any_postgres_processed]
10
+ config = context[:config]
11
+ config[:maintenancedb] = 'postgres' if config[:maintenancedb] == :default
12
+ config[:jdbc_adapter] = 'postgresql' if RUBY_PLATFORM == 'java'
13
+ end
14
+ end
@@ -3,8 +3,6 @@
3
3
  require_relative '../actions_manager'
4
4
 
5
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
6
  Action.register :shell, 'Open an interactive shell to the database' do |args, context|
9
7
  begin
10
8
  Action[:connect_db].run({}, context)
@@ -3,8 +3,6 @@
3
3
  require_relative '../actions_manager'
4
4
 
5
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
6
  Action.register :shell_postgres, nil do |args, context|
9
7
  c = context[:config]
10
8
  psql = c[:psql]
@@ -6,15 +6,16 @@ module SequelTools
6
6
 
7
7
  URI_BUILDER = ->(config, dbname = config[:dbname]) do
8
8
  c = config
9
- uri_parts = [ "#{c[:dbadapter]}://" ]
10
- if user = c[:username]
11
- uri_parts << user
12
- uri_parts << ':' << c[:password] if c[:password]
13
- uri_parts << '@'
14
- end
9
+ uri_parts = []
10
+ uri_parts << 'jdbc:' if RUBY_PLATFORM == 'java'
11
+ uri_parts << "#{c[:jdbc_adapter] || c[:dbadapter]}://"
15
12
  uri_parts << c[:dbhost]
16
13
  uri_parts << ':' << c[:dbport] if c[:dbport]
17
14
  uri_parts << '/' << dbname
15
+ if user = c[:username]
16
+ uri_parts << '?user=' << user
17
+ uri_parts << '&password=' << c[:password] if c[:password]
18
+ end
18
19
  uri_parts.join('')
19
20
  end
20
21
 
@@ -33,6 +34,9 @@ module SequelTools
33
34
  rake_context.instance_eval do
34
35
  desc action.description unless action.description.nil?
35
36
  task action.name, action.arg_names do |t, args|
37
+ require_relative 'actions/before_task'
38
+ ctx[:current_action] = action
39
+ Action[:before_task].run args, ctx
36
40
  action.run args, ctx
37
41
  end
38
42
  end
@@ -3,7 +3,6 @@
3
3
  require_relative 'actions/connect_db'
4
4
  require_relative 'actions/create_db'
5
5
  require_relative 'actions/drop_db'
6
- require_relative 'actions/schema_dump_postgres'
7
6
  require_relative 'actions/schema_dump'
8
7
  require_relative 'actions/schema_load'
9
8
  require_relative 'actions/new_migration'
@@ -17,6 +16,6 @@ require_relative 'actions/redo'
17
16
  require_relative 'actions/version'
18
17
  require_relative 'actions/rollback'
19
18
  require_relative 'actions/status'
20
- require_relative 'actions/shell_postgres'
21
19
  require_relative 'actions/shell'
22
20
  require_relative 'actions/irb'
21
+ require_relative 'actions/postgresql_support'
@@ -1,5 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  module SequelTools
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
data/sequel_tools.gemspec CHANGED
@@ -32,7 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
 
34
34
  spec.add_runtime_dependency 'sequel'
35
- spec.add_development_dependency 'pg'
35
+ spec.add_development_dependency 'pg' unless RUBY_PLATFORM == 'java'
36
+ spec.add_development_dependency 'jdbc-postgres' if RUBY_PLATFORM == 'java'
36
37
  spec.add_development_dependency 'bundler'
37
38
  spec.add_development_dependency 'rake'
38
39
  spec.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Rosenfeld Rosas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-17 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -99,13 +99,13 @@ files:
99
99
  - ".rspec"
100
100
  - ".travis.yml"
101
101
  - Gemfile
102
- - Gemfile.lock
103
102
  - LICENSE.txt
104
103
  - README.md
105
104
  - Rakefile
106
105
  - bin/console
107
106
  - bin/setup
108
107
  - lib/sequel_tools.rb
108
+ - lib/sequel_tools/actions/before_task.rb
109
109
  - lib/sequel_tools/actions/connect_db.rb
110
110
  - lib/sequel_tools/actions/create_db.rb
111
111
  - lib/sequel_tools/actions/down.rb
@@ -113,6 +113,7 @@ files:
113
113
  - lib/sequel_tools/actions/irb.rb
114
114
  - lib/sequel_tools/actions/migrate.rb
115
115
  - lib/sequel_tools/actions/new_migration.rb
116
+ - lib/sequel_tools/actions/postgresql_support.rb
116
117
  - lib/sequel_tools/actions/redo.rb
117
118
  - lib/sequel_tools/actions/reset.rb
118
119
  - lib/sequel_tools/actions/rollback.rb
data/Gemfile.lock DELETED
@@ -1,39 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- sequel_tools (0.1.4)
5
- sequel
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- diff-lcs (1.3)
11
- pg (0.21.0)
12
- rake (12.3.0)
13
- rspec (3.7.0)
14
- rspec-core (~> 3.7.0)
15
- rspec-expectations (~> 3.7.0)
16
- rspec-mocks (~> 3.7.0)
17
- rspec-core (3.7.0)
18
- rspec-support (~> 3.7.0)
19
- rspec-expectations (3.7.0)
20
- diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.7.0)
22
- rspec-mocks (3.7.0)
23
- diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.7.0)
25
- rspec-support (3.7.0)
26
- sequel (5.3.0)
27
-
28
- PLATFORMS
29
- ruby
30
-
31
- DEPENDENCIES
32
- bundler
33
- pg
34
- rake
35
- rspec
36
- sequel_tools!
37
-
38
- BUNDLED WITH
39
- 1.16.0