sequel-rails 0.9.16 → 1.1.1
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 +5 -5
- data/.travis.yml +39 -60
- data/Gemfile +4 -13
- data/History.md +54 -0
- data/README.md +28 -10
- data/Rakefile +1 -1
- data/ci/rails-4.0.gemfile +3 -11
- data/ci/rails-4.1.gemfile +3 -11
- data/ci/rails-4.2.gemfile +3 -11
- data/ci/rails-5.0.gemfile +3 -3
- data/ci/rails-5.1.gemfile +28 -0
- data/ci/rails-5.2.gemfile +28 -0
- data/ci/rails-6.0.gemfile +28 -0
- data/lib/action_dispatch/middleware/session/sequel_store.rb +21 -9
- data/lib/generators/sequel.rb +7 -7
- data/lib/generators/sequel/migration/migration_generator.rb +1 -1
- data/lib/generators/sequel/migration/templates/migration.rb.erb +2 -0
- data/lib/generators/sequel/model/model_generator.rb +2 -1
- data/lib/generators/sequel/session_migration/session_migration_generator.rb +1 -1
- data/lib/sequel_rails/configuration.rb +7 -4
- data/lib/sequel_rails/db_config.rb +8 -4
- data/lib/sequel_rails/migrations.rb +23 -7
- data/lib/sequel_rails/railtie.rb +21 -5
- data/lib/sequel_rails/railties/database.rake +31 -6
- data/lib/sequel_rails/sequel/plugins/rails_extensions.rb +1 -1
- data/lib/sequel_rails/storage.rb +2 -4
- data/lib/sequel_rails/storage/abstract.rb +17 -5
- data/lib/sequel_rails/storage/jdbc.rb +2 -2
- data/lib/sequel_rails/storage/mysql.rb +1 -0
- data/lib/sequel_rails/storage/postgres.rb +7 -3
- data/lib/sequel_rails/version.rb +1 -1
- data/rubocop-todo.yml +4 -1
- data/sequel-rails.gemspec +13 -21
- data/spec/helpers/io.rb +1 -5
- data/spec/integration/sessions_controller_spec.rb +6 -1
- data/spec/lib/generators/sequel/migration_spec.rb +9 -1
- data/spec/lib/generators/sequel/session_migration_spec.rb +1 -1
- data/spec/lib/sequel_rails/configuration_spec.rb +78 -0
- data/spec/lib/sequel_rails/migrations_spec.rb +21 -4
- data/spec/lib/sequel_rails/railtie_spec.rb +1 -1
- data/spec/lib/sequel_rails/railties/database_rake_spec.rb +42 -0
- data/spec/lib/sequel_rails/storage/mysql_spec.rb +1 -1
- data/spec/lib/sequel_rails/storage/postgres_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -2
- metadata +29 -34
- data/ci/rails-3.2.gemfile +0 -42
data/lib/sequel_rails/storage.rb
CHANGED
@@ -51,8 +51,6 @@ module SequelRails
|
|
51
51
|
lookup_class(config['adapter']).new config
|
52
52
|
end
|
53
53
|
|
54
|
-
private
|
55
|
-
|
56
54
|
def self.parse_url(value)
|
57
55
|
URI(value) if value.present?
|
58
56
|
rescue ArgumentError
|
@@ -106,12 +104,12 @@ module SequelRails
|
|
106
104
|
end
|
107
105
|
|
108
106
|
def self.lookup_class(adapter)
|
109
|
-
|
107
|
+
raise 'Adapter not specified in config, please set the :adapter key.' unless adapter
|
110
108
|
return Jdbc if adapter =~ /jdbc/
|
111
109
|
|
112
110
|
klass_name = adapter.camelize.to_sym
|
113
111
|
unless self.const_defined?(klass_name)
|
114
|
-
|
112
|
+
raise "Adapter #{adapter} not supported (#{klass_name.inspect})"
|
115
113
|
end
|
116
114
|
|
117
115
|
const_get klass_name
|
@@ -80,13 +80,13 @@ module SequelRails
|
|
80
80
|
if inserts.any?
|
81
81
|
res = inserts.join("\n")
|
82
82
|
unless sql_dump
|
83
|
-
res = <<-
|
83
|
+
res = <<-RUBY.strip_heredoc
|
84
84
|
Sequel.migration do
|
85
85
|
change do
|
86
86
|
#{res}
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
RUBY
|
90
90
|
end
|
91
91
|
end
|
92
92
|
res
|
@@ -127,7 +127,19 @@ module SequelRails
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def safe_exec(args)
|
130
|
-
|
130
|
+
if !Gem.win_platform?
|
131
|
+
exec SequelRails::Shellwords.join(Array(args))
|
132
|
+
else
|
133
|
+
jarg = args.map do |arg|
|
134
|
+
str = arg.to_s
|
135
|
+
return "''" if str.empty?
|
136
|
+
str = str.dup
|
137
|
+
str.gsub!(%r{([^A-Za-z0-9_\-.,:/@\n])}, '\\1')
|
138
|
+
str.gsub!(/\n/, "'\n'")
|
139
|
+
str
|
140
|
+
end
|
141
|
+
exec jarg.join(' ')
|
142
|
+
end
|
131
143
|
end
|
132
144
|
|
133
145
|
def schema_information_inserts(migrator, sql_dump)
|
@@ -146,14 +158,14 @@ module SequelRails
|
|
146
158
|
if sql_dump
|
147
159
|
res = "#{set_search_path_sql};\n#{res}"
|
148
160
|
else
|
149
|
-
res = <<-
|
161
|
+
res = <<-RUBY.strip_heredoc
|
150
162
|
Sequel.migration do
|
151
163
|
change do
|
152
164
|
self << #{set_search_path_sql.inspect}
|
153
165
|
#{res}
|
154
166
|
end
|
155
167
|
end
|
156
|
-
|
168
|
+
RUBY
|
157
169
|
end
|
158
170
|
end
|
159
171
|
res
|
@@ -58,7 +58,7 @@ module SequelRails
|
|
58
58
|
adapter = ::SequelRails::Storage::Postgres.new(config)
|
59
59
|
adapter._dump(filename)
|
60
60
|
else
|
61
|
-
|
61
|
+
raise NotImplementedError
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -67,7 +67,7 @@ module SequelRails
|
|
67
67
|
adapter = ::SequelRails::Storage::Postgres.new(config)
|
68
68
|
adapter._load(filename)
|
69
69
|
else
|
70
|
-
|
70
|
+
raise NotImplementedError
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -22,6 +22,7 @@ module SequelRails
|
|
22
22
|
with_pgpassword do
|
23
23
|
commands = ['dropdb']
|
24
24
|
add_connection_settings commands
|
25
|
+
add_flag commands, '--if-exists'
|
25
26
|
commands << database
|
26
27
|
safe_exec commands
|
27
28
|
end
|
@@ -64,6 +65,9 @@ module SequelRails
|
|
64
65
|
# command. Seems to be only way to ensure *all* test connections
|
65
66
|
# are closed
|
66
67
|
nil
|
68
|
+
rescue Sequel::DatabaseConnectionError
|
69
|
+
# Will raise an error if the database doesn't exist.
|
70
|
+
nil
|
67
71
|
end
|
68
72
|
|
69
73
|
def encoding
|
@@ -104,9 +108,9 @@ module SequelRails
|
|
104
108
|
end
|
105
109
|
|
106
110
|
def add_connection_settings(commands)
|
107
|
-
add_option commands, '--username', username
|
108
|
-
add_option commands, '--host', host
|
109
|
-
add_option commands, '--port', port.to_s
|
111
|
+
add_option commands, '--username', username unless username.blank?
|
112
|
+
add_option commands, '--host', host unless host.blank?
|
113
|
+
add_option commands, '--port', port.to_s unless port.to_s.blank? || port.to_s == '0'
|
110
114
|
end
|
111
115
|
end
|
112
116
|
end
|
data/lib/sequel_rails/version.rb
CHANGED
data/rubocop-todo.yml
CHANGED
data/sequel-rails.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
4
|
|
4
5
|
require 'sequel_rails/version'
|
@@ -20,29 +21,20 @@ Gem::Specification.new do |s|
|
|
20
21
|
s.rdoc_options = ['--charset=UTF-8']
|
21
22
|
s.license = 'MIT'
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
!!! sequel-rails
|
27
|
-
NOTE: Support for Ruby < 1.9.3 (this is 1.8.x, 1.9.0, 1.9.2) in sequel-rails
|
28
|
-
is deprecated and will be dropped in the next major release. If you really
|
29
|
-
rely on it please complain at http://git.io/WgfgZQ to delay the inevitable.
|
30
|
-
!!!
|
31
|
-
|
32
|
-
NOTE
|
33
|
-
end
|
24
|
+
s.required_ruby_version = '>= 2.2.2'
|
25
|
+
s.required_rubygems_version = '>= 1.8.11'
|
34
26
|
|
35
|
-
s.add_dependency 'activemodel'
|
36
|
-
s.add_dependency 'railties', '>=
|
37
|
-
s.add_dependency 'actionpack', '>=
|
38
|
-
s.add_dependency 'sequel', ['>= 3.28', '<
|
27
|
+
s.add_dependency 'activemodel', '>= 4.0.0'
|
28
|
+
s.add_dependency 'railties', '>= 4.0.0'
|
29
|
+
s.add_dependency 'actionpack', '>= 4.0.0'
|
30
|
+
s.add_dependency 'sequel', ['>= 3.28', '< 6.0']
|
39
31
|
|
40
32
|
s.add_development_dependency 'combustion'
|
41
33
|
s.add_development_dependency 'generator_spec'
|
42
|
-
s.add_development_dependency 'rake', '>= 0.8.7', '<
|
43
|
-
s.add_development_dependency 'rspec', '~> 3.
|
44
|
-
s.add_development_dependency 'rspec-rails', '~> 3.
|
45
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
46
|
-
s.add_development_dependency 'ammeter', '1.1.
|
47
|
-
s.add_development_dependency 'test-unit'
|
34
|
+
s.add_development_dependency 'rake', '>= 0.8.7', '< 12.1'
|
35
|
+
s.add_development_dependency 'rspec', '~> 3.7'
|
36
|
+
s.add_development_dependency 'rspec-rails', '~> 3.7'
|
37
|
+
s.add_development_dependency 'rubocop', '~> 0.52.0'
|
38
|
+
s.add_development_dependency 'ammeter', '1.1.4'
|
39
|
+
s.add_development_dependency 'test-unit'
|
48
40
|
end
|
data/spec/helpers/io.rb
CHANGED
@@ -2,11 +2,7 @@ module IOSpecHelper
|
|
2
2
|
def pretend_file_not_exists(pattern)
|
3
3
|
allow(IO).to receive(:read).and_wrap_original do |m, *a|
|
4
4
|
# if this isn't a good use for case equality I don't know what is
|
5
|
-
|
6
|
-
fail Errno::ENOENT
|
7
|
-
else
|
8
|
-
m.call(*a)
|
9
|
-
end
|
5
|
+
pattern === a.first ? raise(Errno::ENOENT) : m.call(*a) # rubocop:disable CaseEquality
|
10
6
|
end
|
11
7
|
end
|
12
8
|
end
|
@@ -4,7 +4,12 @@ describe SessionsController, :type => :request do
|
|
4
4
|
let(:session_class) { ::ActionDispatch::Session::SequelStore.session_class }
|
5
5
|
|
6
6
|
def login
|
7
|
-
|
7
|
+
opts = if ActionPack::VERSION::MAJOR >= 5
|
8
|
+
{params: {:status => 'logged_in'}}
|
9
|
+
else
|
10
|
+
{:status => 'logged_in'}
|
11
|
+
end
|
12
|
+
post '/session', opts
|
8
13
|
end
|
9
14
|
|
10
15
|
describe '#create' do
|
@@ -21,7 +21,7 @@ describe Sequel::Generators::MigrationGenerator do
|
|
21
21
|
it 'refuses to generate migration with invalid filename' do
|
22
22
|
expect do
|
23
23
|
run_generator ['add_something:datetime']
|
24
|
-
end.to raise_error
|
24
|
+
end.to raise_error(Sequel::IllegalMigrationNameError)
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when name starts with create' do
|
@@ -251,5 +251,13 @@ describe Sequel::Generators::MigrationGenerator do
|
|
251
251
|
}
|
252
252
|
end
|
253
253
|
end
|
254
|
+
|
255
|
+
context 'when invalid migration name' do
|
256
|
+
it 'raises error' do
|
257
|
+
expect { run_generator ['invalid:file:name'] }
|
258
|
+
.to raise_error(Sequel::IllegalMigrationNameError)
|
259
|
+
.with_message("Illegal name for migration file: invalid:file:name (only lower case letters, numbers, and '_' allowed)")
|
260
|
+
end
|
261
|
+
end
|
254
262
|
end
|
255
263
|
end
|
@@ -11,7 +11,7 @@ describe Sequel::Generators::SessionMigrationGenerator do
|
|
11
11
|
it 'refuses to generate migration with invalid filename' do
|
12
12
|
expect do
|
13
13
|
run_generator ['add:sessions']
|
14
|
-
end.to raise_error
|
14
|
+
end.to raise_error(Sequel::IllegalMigrationNameError)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'creates a new migration for sessions table' do
|
@@ -96,6 +96,22 @@ describe SequelRails::Configuration do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
describe '#test_connect' do
|
100
|
+
it 'defaults to true' do
|
101
|
+
expect(subject.test_connect).to be true
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'can be assigned' do
|
105
|
+
subject.test_connect = true
|
106
|
+
expect(subject.test_connect).to be true
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'can be set from merging another hash' do
|
110
|
+
subject.merge!(:test_connect => true)
|
111
|
+
expect(subject.test_connect).to be true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
99
115
|
describe '#connect' do
|
100
116
|
let(:environments) do
|
101
117
|
{
|
@@ -135,6 +151,22 @@ describe SequelRails::Configuration do
|
|
135
151
|
context 'when stubbing SequelRails.jruby?' do
|
136
152
|
before { allow(SequelRails).to receive(:jruby?).and_return(is_jruby) }
|
137
153
|
|
154
|
+
shared_examples 'test_connect' do
|
155
|
+
context 'test_connect' do
|
156
|
+
it 'passes the value' do
|
157
|
+
expect(::Sequel).to receive(:connect) do |hash_or_url, *_|
|
158
|
+
if hash_or_url.is_a? Hash
|
159
|
+
expect(hash_or_url[:test]).to eq true
|
160
|
+
else
|
161
|
+
expect(hash_or_url).to include('test=true')
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
subject.connect environment
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
138
170
|
shared_examples 'max_connections' do
|
139
171
|
context 'with max_connections=7 config option' do
|
140
172
|
let(:max_connections) { 31_337 }
|
@@ -172,6 +204,44 @@ describe SequelRails::Configuration do
|
|
172
204
|
end
|
173
205
|
end
|
174
206
|
|
207
|
+
shared_examples 'servers' do
|
208
|
+
context 'servers' do
|
209
|
+
let(:servers) { { read_only: { host: 'replica' } } }
|
210
|
+
|
211
|
+
shared_examples 'passes the value only through options hash' do
|
212
|
+
it 'passes the value only through options hash' do
|
213
|
+
expect(::Sequel).to receive(:connect) do |hash_or_url, *_|
|
214
|
+
if hash_or_url.is_a? Hash
|
215
|
+
servers.keys.each do |k|
|
216
|
+
expect(hash_or_url[:servers][k]).to eq servers[k]
|
217
|
+
end
|
218
|
+
else
|
219
|
+
puts hash_or_url
|
220
|
+
expect(hash_or_url).not_to include('servers=')
|
221
|
+
end
|
222
|
+
end
|
223
|
+
subject.connect environment
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'with servers set in config' do
|
228
|
+
before do
|
229
|
+
subject.servers = servers
|
230
|
+
end
|
231
|
+
|
232
|
+
include_examples 'passes the value only through options hash'
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'with servers set in environment' do
|
236
|
+
before do
|
237
|
+
environments[environment]['servers'] = servers
|
238
|
+
end
|
239
|
+
|
240
|
+
include_examples 'passes the value only through options hash'
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
175
245
|
shared_examples 'with DATABASE_URL in ENV' do
|
176
246
|
let(:database_url) { 'adapter://user:pass@host/db' }
|
177
247
|
def with_database_url_env
|
@@ -248,8 +318,10 @@ describe SequelRails::Configuration do
|
|
248
318
|
let(:environment) { 'development' }
|
249
319
|
|
250
320
|
context 'in C-Ruby' do
|
321
|
+
include_examples 'test_connect'
|
251
322
|
include_examples 'max_connections'
|
252
323
|
include_examples 'search_path'
|
324
|
+
include_examples 'servers'
|
253
325
|
include_examples 'with DATABASE_URL in ENV'
|
254
326
|
|
255
327
|
let(:is_jruby) { false }
|
@@ -263,8 +335,10 @@ describe SequelRails::Configuration do
|
|
263
335
|
end
|
264
336
|
|
265
337
|
context 'in JRuby' do
|
338
|
+
include_examples 'test_connect'
|
266
339
|
include_examples 'max_connections'
|
267
340
|
include_examples 'search_path'
|
341
|
+
include_examples 'servers'
|
268
342
|
include_examples 'with DATABASE_URL in ENV'
|
269
343
|
|
270
344
|
let(:is_jruby) { true }
|
@@ -296,7 +370,9 @@ describe SequelRails::Configuration do
|
|
296
370
|
let(:environment) { 'remote' }
|
297
371
|
|
298
372
|
context 'in C-Ruby' do
|
373
|
+
include_examples 'test_connect'
|
299
374
|
include_examples 'max_connections'
|
375
|
+
include_examples 'servers'
|
300
376
|
include_examples 'with DATABASE_URL in ENV'
|
301
377
|
|
302
378
|
let(:is_jruby) { false }
|
@@ -310,7 +386,9 @@ describe SequelRails::Configuration do
|
|
310
386
|
end
|
311
387
|
|
312
388
|
context 'in JRuby' do
|
389
|
+
include_examples 'test_connect'
|
313
390
|
include_examples 'max_connections'
|
391
|
+
include_examples 'servers'
|
314
392
|
include_examples 'with DATABASE_URL in ENV'
|
315
393
|
|
316
394
|
let(:is_jruby) { true }
|
@@ -8,23 +8,40 @@ describe SequelRails::Migrations do
|
|
8
8
|
describe ".#{migration_method}" do
|
9
9
|
let(:result) { double(:result) }
|
10
10
|
context 'with no version specified' do
|
11
|
-
let(:opts) { {} }
|
12
11
|
it 'runs migrations using Sequel::Migrator' do
|
13
12
|
expect(::Sequel::Migrator).to receive(:run).with(
|
14
|
-
db, Rails.root.join('db/migrate'),
|
13
|
+
db, Rails.root.join('db/migrate'), allow_missing_migration_files: false
|
15
14
|
).and_return result
|
16
15
|
expect(described_class.send(migration_method)).to be(result)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
context 'with version specified' do
|
20
|
-
let(:opts) { { :target => 1 } }
|
21
19
|
it 'runs migrations using Sequel::Migrator' do
|
22
20
|
expect(::Sequel::Migrator).to receive(:run).with(
|
23
|
-
db, Rails.root.join('db/migrate'),
|
21
|
+
db, Rails.root.join('db/migrate'), allow_missing_migration_files: false, target: 1
|
24
22
|
).and_return result
|
25
23
|
expect(described_class.send(migration_method, 1)).to be(result)
|
26
24
|
end
|
27
25
|
end
|
26
|
+
|
27
|
+
context 'with allow_missing_migration_files' do
|
28
|
+
around do |ex|
|
29
|
+
option = SequelRails.configuration.allow_missing_migration_files
|
30
|
+
SequelRails.configuration.allow_missing_migration_files = true
|
31
|
+
|
32
|
+
ex.run
|
33
|
+
|
34
|
+
SequelRails.configuration.allow_missing_migration_files = option
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'runs migrations using Sequel::Migrator' do
|
38
|
+
expect(::Sequel::Migrator).to receive(:run).with(
|
39
|
+
db, Rails.root.join('db/migrate'), allow_missing_migration_files: true
|
40
|
+
).and_return result
|
41
|
+
|
42
|
+
described_class.send(migration_method)
|
43
|
+
end
|
44
|
+
end
|
28
45
|
end
|
29
46
|
end
|
30
47
|
|