sequel-rails 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +24 -41
  4. data/History.md +8 -0
  5. data/README.md +38 -3
  6. data/ci/rails-3.2.gemfile +3 -0
  7. data/ci/rails-5.0.gemfile +25 -0
  8. data/lib/action_dispatch/middleware/session/sequel_store.rb +1 -1
  9. data/lib/generators/sequel/migration/migration_generator.rb +32 -16
  10. data/lib/sequel_rails.rb +23 -0
  11. data/lib/sequel_rails/configuration.rb +5 -4
  12. data/lib/sequel_rails/db_config.rb +19 -19
  13. data/lib/sequel_rails/railtie.rb +19 -9
  14. data/lib/sequel_rails/railties/controller_runtime.rb +2 -1
  15. data/lib/sequel_rails/railties/database.rake +30 -30
  16. data/lib/sequel_rails/railties/log_subscriber.rb +4 -2
  17. data/lib/sequel_rails/railties/spring_support.rb +13 -0
  18. data/lib/sequel_rails/sequel/database/active_support_notification.rb +2 -2
  19. data/lib/sequel_rails/shellwords.rb +1 -1
  20. data/lib/sequel_rails/storage.rb +1 -1
  21. data/lib/sequel_rails/storage/abstract.rb +3 -4
  22. data/lib/sequel_rails/storage/postgres.rb +0 -1
  23. data/lib/sequel_rails/version.rb +1 -1
  24. data/rubocop-todo.yml +9 -0
  25. data/sequel-rails.gemspec +3 -3
  26. data/spec/internal/config/database.yml +6 -0
  27. data/spec/internal/db/migrate/1273253849_add_twitter_handle_to_users.rb +0 -2
  28. data/spec/lib/generators/sequel/migration_spec.rb +0 -1
  29. data/spec/lib/generators/sequel/session_migration_spec.rb +0 -1
  30. data/spec/lib/sequel_rails/configuration_spec.rb +12 -27
  31. data/spec/lib/sequel_rails/db_config_spec.rb +26 -20
  32. data/spec/lib/sequel_rails/railtie_spec.rb +4 -4
  33. data/spec/lib/sequel_rails/railties/database_rake_spec.rb +18 -19
  34. data/spec/lib/sequel_rails/storage/postgres_spec.rb +1 -1
  35. metadata +15 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44b6703d7b0e5a73f9539c3a89e7d4cad0dcfff3
4
- data.tar.gz: eb21ad4107e1eacf55d4f21175e815be2ef308b2
3
+ metadata.gz: f373b19d13b5acc804458b3a6402e1ad71a5480b
4
+ data.tar.gz: d204a4d3aa6756161d9cc94b8dcf8733b65722da
5
5
  SHA512:
6
- metadata.gz: b0d73d406b6477ecbe4dc74d3870fd0b70cafaa4b27e1cd1deb14126d4b46c9606aa2225e11f536f0e27f12de3c916bdbcd09f0405f1611c75469b217675afee
7
- data.tar.gz: 1a5b250db4634b304caf5e9d9169801e51415e21c3819d8400dacb11126e8985bc2adb52716c360c13d126c870957db4df59b4d648ff3d907c0d07c531ec155e
6
+ metadata.gz: 06590d5d6130a9ef1a8c81928b6e3cea9fd7aedd85115e133bf2d81a27ef21446e15b9040611a6cedf2a44edee1a555c3e639ed168a8aacaa6821c64cdca40a7
7
+ data.tar.gz: c244b95d90081edf5fe865ceedaf7b712b3445177a088d0eba8430c0726331945fa52d0550204aa9741973ffa7159d354e0261bf7a02b96bf18159f486be0caf
@@ -8,7 +8,7 @@ AllCops:
8
8
  - '**/*.gemspec'
9
9
  Exclude:
10
10
  - 'lib/sequel-rails.rb'
11
- - 'ci/*'
11
+ - 'ci/**/*'
12
12
 
13
13
  HashSyntax:
14
14
  EnforcedStyle: hash_rockets
@@ -6,10 +6,12 @@ rvm:
6
6
  - 1.8.7
7
7
  - 1.9.3
8
8
  - 2.0.0
9
- - 2.1
10
- - 2.2
9
+ - 2.1.8
10
+ - 2.2.4
11
+ - 2.3.0
11
12
  - jruby-18mode
12
13
  - jruby-19mode
14
+ - jruby-9.0.1.0
13
15
  env:
14
16
  - SEQUEL='~> 3.0'
15
17
  - SEQUEL='~> 4.0'
@@ -18,68 +20,49 @@ gemfile:
18
20
  - ci/rails-4.0.gemfile
19
21
  - ci/rails-4.1.gemfile
20
22
  - ci/rails-4.2.gemfile
23
+ - ci/rails-5.0.gemfile
21
24
  matrix:
25
+ allow_failures:
26
+ - gemfile: ci/rails-5.0.gemfile
22
27
  exclude:
23
- - rvm: 2.2
28
+ - rvm: 2.2.4
24
29
  gemfile: ci/rails-3.2.gemfile
25
- env: SEQUEL='~> 3.0'
26
- - rvm: 2.2
30
+ - rvm: 2.3.0
31
+ gemfile: ci/rails-3.2.gemfile
32
+ - rvm: jruby-9.0.1.0
27
33
  gemfile: ci/rails-3.2.gemfile
28
- env: SEQUEL='~> 4.0'
29
- - rvm: ree
30
- gemfile: ci/rails-4.0.gemfile
31
- env: SEQUEL='~> 3.0'
32
34
  - rvm: ree
33
35
  gemfile: ci/rails-4.0.gemfile
34
- env: SEQUEL='~> 4.0'
35
- - rvm: 1.8.7
36
- gemfile: ci/rails-4.0.gemfile
37
- env: SEQUEL='~> 3.0'
38
36
  - rvm: 1.8.7
39
37
  gemfile: ci/rails-4.0.gemfile
40
- env: SEQUEL='~> 4.0'
41
38
  - rvm: jruby-18mode
42
39
  gemfile: ci/rails-4.0.gemfile
43
- env: SEQUEL='~> 3.0'
44
- - rvm: jruby-18mode
45
- gemfile: ci/rails-4.0.gemfile
46
- env: SEQUEL='~> 4.0'
47
40
  - rvm: ree
48
41
  gemfile: ci/rails-4.1.gemfile
49
- env: SEQUEL='~> 3.0'
50
- - rvm: ree
51
- gemfile: ci/rails-4.1.gemfile
52
- env: SEQUEL='~> 4.0'
53
- - rvm: 1.8.7
54
- gemfile: ci/rails-4.1.gemfile
55
- env: SEQUEL='~> 3.0'
56
42
  - rvm: 1.8.7
57
43
  gemfile: ci/rails-4.1.gemfile
58
- env: SEQUEL='~> 4.0'
59
- - rvm: jruby-18mode
60
- gemfile: ci/rails-4.1.gemfile
61
- env: SEQUEL='~> 3.0'
62
44
  - rvm: jruby-18mode
63
45
  gemfile: ci/rails-4.1.gemfile
64
- env: SEQUEL='~> 4.0'
65
- - rvm: ree
66
- gemfile: ci/rails-4.2.gemfile
67
- env: SEQUEL='~> 3.0'
68
46
  - rvm: ree
69
47
  gemfile: ci/rails-4.2.gemfile
70
- env: SEQUEL='~> 4.0'
71
48
  - rvm: 1.8.7
72
49
  gemfile: ci/rails-4.2.gemfile
73
- env: SEQUEL='~> 3.0'
74
- - rvm: 1.8.7
75
- gemfile: ci/rails-4.2.gemfile
76
- env: SEQUEL='~> 4.0'
77
50
  - rvm: jruby-18mode
78
51
  gemfile: ci/rails-4.2.gemfile
79
- env: SEQUEL='~> 3.0'
52
+ - rvm: ree
53
+ gemfile: ci/rails-5.0.gemfile
54
+ - rvm: 1.8.7
55
+ gemfile: ci/rails-5.0.gemfile
80
56
  - rvm: jruby-18mode
81
- gemfile: ci/rails-4.2.gemfile
82
- env: SEQUEL='~> 4.0'
57
+ gemfile: ci/rails-5.0.gemfile
58
+ - rvm: jruby-19mode
59
+ gemfile: ci/rails-5.0.gemfile
60
+ - rvm: 1.9.3
61
+ gemfile: ci/rails-5.0.gemfile
62
+ - rvm: 2.0.0
63
+ gemfile: ci/rails-5.0.gemfile
64
+ - rvm: 2.1.8
65
+ gemfile: ci/rails-5.0.gemfile
83
66
  notifications:
84
67
  email:
85
68
  - jonathan.tron@metrilio.com
data/History.md CHANGED
@@ -1,3 +1,11 @@
1
+ 0.9.12 (2016-01-18)
2
+ ===================
3
+
4
+ * Remove `-i` option from `pg_dump`, removed in PostgreSQL 9.5 (Joseph Halter)
5
+ * Add support for [Spring](https://github.com/rails/spring) (Jan Berdajs) [#99](https://github.com/TalentBox/sequel-rails/pull/99)
6
+ * Allow `config.sequel.logger` to be overridden by environments [#98](https://github.com/TalentBox/sequel-rails/issues/98)
7
+ * Allow Rake tasks `db:` namespace to be reconfigured to something else (John Anderson) [#89](https://github.com/TalentBox/sequel-rails/pull/89)
8
+
1
9
  0.9.11 (2015-03-13)
2
10
  ===================
3
11
 
data/README.md CHANGED
@@ -57,6 +57,28 @@ require "action_mailer/railtie"
57
57
  require "sprockets/railtie"
58
58
  ```
59
59
 
60
+ Then you need to get rid of `ActiveRecord` configurations, that is if you
61
+ didn't generate the new app with `-O` (or the long form `--skip-active-record`):
62
+
63
+ `config/application.rb` and `config/environments/*.rb`
64
+
65
+ For example in a fresh `Rails 4.2.4`, you would need to remove those lines:
66
+
67
+ ```
68
+ config/application.rb
69
+ line 27: config.active_record.raise_in_transactional_callbacks = true
70
+ ```
71
+
72
+ ```
73
+ config/environments/development.rb
74
+ line 23: config.active_record.migration_error = :page_load
75
+ ```
76
+
77
+ ```
78
+ config/environments/production.rb
79
+ line 78: config.active_record.dump_schema_after_migration = false
80
+ ```
81
+
60
82
  Starting with sequel-rails 0.4.0.pre3 we don't change default Sequel behaviour
61
83
  nor include any plugin by default, if you want to get back the previous
62
84
  behaviour, you can create a new initializer (eg: `config/initializers/sequel.rb`)
@@ -149,12 +171,22 @@ You can configure some options with the usual rails mechanism, in
149
171
  config.sequel.max_connections = 16
150
172
  config.sequel.search_path = %w(mine public)
151
173
 
152
- # Configure whether database's rake tasks will be loaded or not
174
+ # Configure whether database's rake tasks will be loaded or not.
175
+ #
176
+ # If passed a String or Symbol, this will replace the `db:` namespace for
177
+ # the database's Rake tasks.
178
+ #
179
+ # ex: config.sequel.load_database_tasks = :sequel
180
+ # will results in `rake db:migrate` to become `rake sequel:migrate`
181
+ #
153
182
  # Defaults to true
154
183
  config.sequel.load_database_tasks = false
155
184
 
156
185
  # This setting disabled the automatic connect after Rails init
157
186
  config.sequel.skip_connect = true
187
+
188
+ # If you want to use a specific logger
189
+ config.sequel.logger = MyLogger.new($stdout)
158
190
  ```
159
191
 
160
192
  The connection settings are read from the file `config/database.yml` and is
@@ -327,7 +359,7 @@ Previous maintainer
327
359
  Contributors
328
360
  ============
329
361
 
330
- Improvements has been made by those awesome contributors:
362
+ Improvements have been made by those awesome contributors:
331
363
 
332
364
  * Benjamin Atkin (benatkin)
333
365
  * Gabor Ratky (rgabo)
@@ -354,11 +386,14 @@ Improvements has been made by those awesome contributors:
354
386
  * Nico Rieck (gix)
355
387
  * Alexander Birkner (BirknerAlex)
356
388
  * kr3ssh (kressh)
389
+ * John Anderson (djellemah)
390
+ * Larivact (Larivact)
391
+ * Jan Berdajs (mrbrdo)
357
392
 
358
393
  Credits
359
394
  =======
360
395
 
361
- The [dm-rails](http://github.com/datamapper/dm-rails) team wrote most of the original code, I just sequel-ized it, but since then most of it as been either adapted or rewritten.
396
+ The [dm-rails](http://github.com/datamapper/dm-rails) team wrote most of the original code, I just sequel-ized it, but since then most of it has been either adapted or rewritten.
362
397
 
363
398
  Copyright
364
399
  =========
@@ -14,6 +14,9 @@ gem 'tzinfo'
14
14
  if RUBY_VERSION < '1.9'
15
15
  gem 'i18n', '< 0.7.0'
16
16
  end
17
+ if RUBY_VERSION < '2.0'
18
+ gem "rack-cache", "< 1.3.0"
19
+ end
17
20
 
18
21
  # MRI/Rubinius Adapter Dependencies
19
22
  platform :ruby do
@@ -0,0 +1,25 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 5.0.0.beta1'
4
+ gem 'activemodel', '~> 5.0.0.beta1'
5
+
6
+ gemspec :path => '../'
7
+
8
+ gem 'sequel', "#{ENV['SEQUEL']}"
9
+
10
+ gem 'fakefs', '0.5.3', :require => 'fakefs/safe'
11
+
12
+ # MRI/Rubinius Adapter Dependencies
13
+ platform :ruby do
14
+ gem 'pg'
15
+ gem 'mysql'
16
+ gem 'mysql2'
17
+ gem 'sqlite3'
18
+ end
19
+
20
+ # JRuby Adapter Dependencies
21
+ platform :jruby do
22
+ gem 'jdbc-sqlite3'
23
+ gem 'jdbc-mysql'
24
+ gem 'jdbc-postgres'
25
+ end
@@ -7,7 +7,7 @@ module ActionDispatch
7
7
  module Session
8
8
  class SequelStore < AbstractStore
9
9
  SESSION_RECORD_KEY = 'rack.session.record'.freeze
10
- ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
10
+ ENV_SESSION_OPTIONS_KEY = 'rack.session.options'.freeze
11
11
 
12
12
  cattr_accessor :session_class
13
13
  def self.session_class
@@ -23,27 +23,43 @@ module Sequel
23
23
 
24
24
  def set_local_assigns!
25
25
  if file_name =~ /^(add|drop|remove)_.*_(?:to|from)_(.*)/
26
- @table_action = 'alter'
27
- @table_name = Regexp.last_match[2].pluralize
28
- @column_action = Regexp.last_match[1] == 'add' ? 'add' : 'drop'
29
- @use_change = @column_action == 'add' ? true : false
26
+ column_action = Regexp.last_match[1]
27
+ set_alter!(
28
+ Regexp.last_match[2].pluralize,
29
+ column_action,
30
+ column_action == 'add'
31
+ )
30
32
  elsif file_name =~ /^(create|drop)_(.*)$/
31
- @table_action = Regexp.last_match[1]
32
- @table_name = Regexp.last_match[2].pluralize
33
- @column_action = 'add'
34
- @use_change = @table_action == 'create' ? true : false
33
+ table_action = Regexp.last_match[1]
34
+ set_other!(
35
+ Regexp.last_match[2].pluralize,
36
+ table_action,
37
+ table_action == 'create'
38
+ )
35
39
  else
36
- @table_action = 'alter'
37
- if file_name =~ /^(alter)_(.*)/
38
- @table_name = Regexp.last_match[2].pluralize
39
- else
40
- @table_name = file_name.pluralize
41
- end
42
- @use_change = false
43
- @column_action = 'add'
40
+ table_name = if file_name =~ /^(alter)_(.*)/
41
+ Regexp.last_match[2].pluralize
42
+ else
43
+ file_name.pluralize
44
+ end
45
+ set_alter! table_name, 'add', false
44
46
  end
45
47
  end
46
48
 
49
+ def set_other!(table_name, table_action, use_change)
50
+ @table_name = table_name
51
+ @table_action = table_action
52
+ @column_action = 'add'
53
+ @use_change = use_change
54
+ end
55
+
56
+ def set_alter!(table_name, column_action, use_change)
57
+ @table_action = 'alter'
58
+ @table_name = table_name
59
+ @column_action = column_action == 'add' ? 'add' : 'drop'
60
+ @use_change = use_change
61
+ end
62
+
47
63
  def validate_file_name!
48
64
  fail IllegalMigrationNameError file_name unless file_name =~ /^[_a-z0-9]+$/
49
65
  end
@@ -6,4 +6,27 @@ module SequelRails
6
6
  def self.jruby?
7
7
  (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby') || defined?(JRUBY_VERSION)
8
8
  end
9
+
10
+ if Hash.public_instance_methods.include? :deep_symbolize_keys
11
+ def self.deep_symbolize_keys(hash)
12
+ hash.deep_symbolize_keys
13
+ end
14
+ else
15
+ def self.deep_symbolize_keys(hash)
16
+ h = {}
17
+ hash.each { |key, value| h[key.to_sym] = deep_symbolize_keys_map(value) }
18
+ h
19
+ end
20
+
21
+ def self.deep_symbolize_keys_map(value)
22
+ case value
23
+ when Hash
24
+ deep_symbolize_keys(value)
25
+ when Array
26
+ value.map { |v| deep_symbolize_keys_map(v) }
27
+ else
28
+ value
29
+ end
30
+ end
31
+ end
9
32
  end
@@ -22,7 +22,7 @@ module SequelRails
22
22
  super
23
23
  self.root = Rails.root
24
24
  self.raw = nil
25
- self.logger = Rails.logger
25
+ self.logger = nil
26
26
  self.migration_dir = nil
27
27
  self.schema_dump = default_schema_dump
28
28
  self.load_database_tasks = true
@@ -39,7 +39,8 @@ module SequelRails
39
39
  # default config - use just the environment variable
40
40
  Hash.new normalize_repository_config({})
41
41
  ) do |normalized, environment|
42
- name, config = environment.first, environment.last
42
+ name = environment.first
43
+ config = environment.last
43
44
  normalized[name] = normalize_repository_config(config)
44
45
  normalized
45
46
  end
@@ -54,9 +55,9 @@ module SequelRails
54
55
  end
55
56
 
56
57
  if normalized_config['url']
57
- ::Sequel.connect normalized_config['url'], normalized_config
58
+ ::Sequel.connect normalized_config['url'], SequelRails.deep_symbolize_keys(normalized_config)
58
59
  else
59
- ::Sequel.connect normalized_config
60
+ ::Sequel.connect SequelRails.deep_symbolize_keys(normalized_config)
60
61
  end.tap { after_connect.call if after_connect.respond_to?(:call) }
61
62
  end
62
63
 
@@ -25,7 +25,7 @@ module SequelRails
25
25
  # the gsub transforms foo:/bar
26
26
  # (which jdbc doesn't like)
27
27
  # into foo:///bar
28
- self[:url] || make_url.to_s.gsub(/:\/(?=\w)/, ':///')
28
+ self[:url] || make_url.to_s.gsub(%r{:/(?=\w)}, ':///')
29
29
  end
30
30
 
31
31
  private
@@ -48,18 +48,19 @@ module SequelRails
48
48
 
49
49
  def normalize_db(root)
50
50
  return unless include? :adapter
51
- if root && adapter.include?('sqlite') && database != ':memory:'
52
- # sqlite expects path as the database name
53
- self[:database] = File.expand_path database.to_s, root
54
- end
51
+ return unless root
52
+ return unless adapter.include?('sqlite') && database != ':memory:'
53
+ # sqlite expects path as the database name
54
+ self[:database] = File.expand_path database.to_s, root
55
55
  end
56
56
 
57
57
  def make_url
58
58
  if adapter =~ /^(jdbc|do):/
59
59
  scheme, subadapter = adapter.split ':'
60
- return URI::Generic.build \
61
- :scheme => scheme,
62
- :opaque => build_url(to_hash.merge 'adapter' => subadapter).to_s
60
+ URI::Generic.build(
61
+ :scheme => scheme,
62
+ :opaque => build_url(to_hash.merge 'adapter' => subadapter).to_s
63
+ )
63
64
  else
64
65
  build_url to_hash
65
66
  end
@@ -67,11 +68,9 @@ module SequelRails
67
68
 
68
69
  def build_url(cfg)
69
70
  if (adapter = cfg['adapter']) =~ /sqlite/ &&
70
- (database = cfg['database']) =~ /^:/
71
+ (database = cfg['database']) =~ /^:/
71
72
  # magic sqlite databases
72
- return URI::Generic.build \
73
- :scheme => adapter,
74
- :opaque => database
73
+ return URI::Generic.build(:scheme => adapter, :opaque => database)
75
74
  end
76
75
 
77
76
  # these four are handled separately
@@ -84,17 +83,18 @@ module SequelRails
84
83
  end
85
84
 
86
85
  path = cfg['database'].to_s
87
- path = "/#{path}" if path =~ /^(?!\/)/
86
+ path = "/#{path}" if path =~ %r{^(?!/)}
88
87
 
89
88
  q = URI.encode_www_form(params)
90
89
  q = nil if q.empty?
91
90
 
92
- URI::Generic.build \
93
- :scheme => cfg['adapter'],
94
- :host => cfg['host'],
95
- :port => cfg['port'],
96
- :path => path,
97
- :query => q
91
+ URI::Generic.build(
92
+ :scheme => cfg['adapter'],
93
+ :host => cfg['host'],
94
+ :port => cfg['port'],
95
+ :path => path,
96
+ :query => q
97
+ )
98
98
  end
99
99
  end
100
100
  end