sequel_tools 0.1.4 → 0.1.9

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
- SHA1:
3
- metadata.gz: fd0f583b78b874b3cfc1701a277ef182b184c66f
4
- data.tar.gz: 980bc39cff7f7af9fcad83b4cd655d59aca0b3c3
2
+ SHA256:
3
+ metadata.gz: 63dc5d382e886ba9dab8842c1541baf6b152b44ca2f9c063197ea8203246e9b7
4
+ data.tar.gz: 4c26c7e3e0959e32a806fa24839f7bcea96e2aafabe75e4b99d986537a290ec2
5
5
  SHA512:
6
- metadata.gz: 912e0711195c5f895b40807d6013e899d6767f878438e2b4b173f910304e69928bf64da3c5c10db3d3ed12a9c768eb362fee42dc1b8726090278553fb86c4534
7
- data.tar.gz: 55bfdf355d5f590e1d6ee16bd2096dce9c686ecbff614335928c96e08bb5477d1539542a1e0860919fc79ba59008c88b5d620f02522ed0d6b3aa1b9f2d1609c2
6
+ metadata.gz: 65a1d13e7afa10701999bb0952f0a47c71c541ca488e086ac3de1a0b53b2eb5483e5cb8275e4320f2bdc57e9980316bfd076dab3880e7cf719227f48df42b3bf
7
+ data.tar.gz: 5cac6fb94dd0146acf742765bb0a4bf57421e221a2a54cbf1f150af1938a0278249a6ff981af962a7a0b4b9be4d8e301e685d88becea245913bbc16e9e201428
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/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ # fix warnings in Travis CI build caused by RVM using the -client option in JRUBY_OPTS
2
+ unset JRUBY_OPTS
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  sudo: true
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
4
+ - 3.0.1
5
+ #- jruby-9.2.17.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',
@@ -20,6 +20,7 @@ module SequelTools
20
20
  dump_schema_on_migrate: false,
21
21
  log_level: nil,
22
22
  sql_log_level: :debug,
23
+ migrations_table: nil,
23
24
  } # unfrozen on purpose so that one might want to update the defaults
24
25
 
25
26
  REQUIRED_KEYS = [ :project_root, :dbadapter, :dbname, :username ]
@@ -42,4 +43,15 @@ module SequelTools
42
43
  actions_manager.load_all
43
44
  actions_manager.export_as_rake_tasks rake_context
44
45
  end
46
+
47
+ def self.suppress_java_output
48
+ return yield unless RUBY_PLATFORM == 'java'
49
+ require 'java'
50
+ require 'stringio'
51
+ old_err = java.lang.System.err
52
+ java.lang.System.err = java.io.PrintStream.new(StringIO.new.to_outputstream)
53
+ yield
54
+ ensure
55
+ java.lang.System.err = old_err if RUBY_PLATFORM == 'java'
56
+ end
45
57
  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), test: true
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,12 +3,18 @@
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
- config = context[:config]
11
- uri = context[:uri_builder][config]
12
- exec "bundle exec sequel #{uri}"
8
+ # This code does the job, but for some reason the test will timeout under JRuby
9
+ #config = context[:config]
10
+ #uri = context[:uri_builder][config]
11
+ #exec "bundle exec sequel #{uri}"
12
+
13
+ Action[:connect_db].run({}, context)
14
+ require 'irb'
15
+ ::DB = context[:db]
16
+ ARGV.clear
17
+ puts 'Your database is stored in DB...'
18
+ IRB.start
13
19
  end
14
20
  end
@@ -12,6 +12,7 @@ class SequelTools::ActionsManager
12
12
  Sequel.extension :migration unless Sequel.respond_to? :migration
13
13
  options = {}
14
14
  options[:target] = args[:version].to_i if args[:version]
15
+ options[:table] = config[:migrations_table] if config[:migrations_table]
15
16
  Sequel::Migrator.run db, config[:migrations_location], options
16
17
  Action[:schema_dump].run({}, context) if config[:dump_schema_on_migrate]
17
18
  end
@@ -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
@@ -16,7 +16,8 @@ class SequelTools::ActionsManager
16
16
  puts "Schema file '#{schema_location}' does not exist. Aborting."
17
17
  exit 1
18
18
  end
19
- context[:db] << File.read(schema_location)
19
+ context[:db].run File.read(schema_location)
20
+ context[:db].disconnect # forces reconnection
20
21
  end
21
22
  end
22
23
  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'
@@ -22,6 +22,7 @@ class MigrationUtils
22
22
  options = { allow_missing_migration_files: true }
23
23
  options[:target] = 0 if direction == :down
24
24
  config = context[:config]
25
+ options[:table] = config[:migrations_table] if config[:migrations_table]
25
26
  Sequel::Migrator.migrator_class(config[:migrations_location]).
26
27
  new(context[:db], config[:migrations_location], options)
27
28
  end
@@ -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.9'
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.9
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: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -97,15 +97,16 @@ extra_rdoc_files: []
97
97
  files:
98
98
  - ".gitignore"
99
99
  - ".rspec"
100
+ - ".rvmrc"
100
101
  - ".travis.yml"
101
102
  - Gemfile
102
- - Gemfile.lock
103
103
  - LICENSE.txt
104
104
  - README.md
105
105
  - Rakefile
106
106
  - bin/console
107
107
  - bin/setup
108
108
  - lib/sequel_tools.rb
109
+ - lib/sequel_tools/actions/before_task.rb
109
110
  - lib/sequel_tools/actions/connect_db.rb
110
111
  - lib/sequel_tools/actions/create_db.rb
111
112
  - lib/sequel_tools/actions/down.rb
@@ -113,6 +114,7 @@ files:
113
114
  - lib/sequel_tools/actions/irb.rb
114
115
  - lib/sequel_tools/actions/migrate.rb
115
116
  - lib/sequel_tools/actions/new_migration.rb
117
+ - lib/sequel_tools/actions/postgresql_support.rb
116
118
  - lib/sequel_tools/actions/redo.rb
117
119
  - lib/sequel_tools/actions/reset.rb
118
120
  - lib/sequel_tools/actions/rollback.rb
@@ -153,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  - !ruby/object:Gem::Version
154
156
  version: '0'
155
157
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.6.13
158
+ rubygems_version: 3.2.15
158
159
  signing_key:
159
160
  specification_version: 4
160
161
  summary: Add Rake tasks to manage Sequel migrations
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