ridgepole 0.8.4 → 0.8.9

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +38 -4
  3. data/.travis.yml +5 -7
  4. data/README.md +13 -1
  5. data/bin/ridgepole +4 -2
  6. data/lib/ridgepole/cli/config.rb +5 -3
  7. data/lib/ridgepole/delta.rb +29 -22
  8. data/lib/ridgepole/diff.rb +13 -1
  9. data/lib/ridgepole/dsl_parser.rb +2 -1
  10. data/lib/ridgepole/dsl_parser/context.rb +5 -2
  11. data/lib/ridgepole/external_sql_executer.rb +1 -1
  12. data/lib/ridgepole/version.rb +1 -1
  13. data/spec/dsl_parser/context_spec.rb +16 -0
  14. data/spec/fixtures/for_require_relative_spec.rb +3 -0
  15. data/spec/mysql/cli/config_spec.rb +54 -1
  16. data/spec/mysql/cli/ridgepole_spec.rb +1 -0
  17. data/spec/mysql/collation/collation_spec.rb +6 -0
  18. data/spec/mysql/diff/diff2_spec.rb +3 -3
  19. data/spec/mysql/diff/diff_spec.rb +3 -3
  20. data/spec/mysql/fk/migrate_create_fk_spec.rb +27 -7
  21. data/spec/mysql/fk/migrate_drop_fk_spec.rb +1 -1
  22. data/spec/mysql/fk/migrate_fk_with_column_spec.rb +2 -2
  23. data/spec/mysql/migrate/migrate_add_column_spec.rb +5 -5
  24. data/spec/mysql/migrate/migrate_change_column8_spec.rb +1 -1
  25. data/spec/mysql/migrate/migrate_change_column_spec.rb +5 -5
  26. data/spec/mysql/migrate/migrate_change_index_spec.rb +9 -9
  27. data/spec/mysql/migrate/migrate_change_table_comment_spec.rb +1 -1
  28. data/spec/mysql/migrate/migrate_change_table_option_spec.rb +1 -1
  29. data/spec/mysql/migrate/migrate_create_index_spec.rb +6 -6
  30. data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +7 -7
  31. data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +8 -8
  32. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +4 -4
  33. data/spec/mysql/migrate/migrate_drop_column_spec.rb +3 -3
  34. data/spec/mysql/migrate/migrate_drop_index_spec.rb +6 -6
  35. data/spec/mysql/migrate/migrate_rename_column_spec.rb +3 -3
  36. data/spec/mysql/migrate/migrate_script_error_spec.rb +1 -1
  37. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +4 -1
  38. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +1 -1
  39. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +1 -1
  40. data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +7 -7
  41. data/spec/postgresql/diff/diff_spec.rb +2 -2
  42. data/spec/postgresql/fk/migrate_create_fk_spec.rb +2 -2
  43. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +1 -1
  44. data/spec/postgresql/migrate/migrate_add_column_spec.rb +5 -5
  45. data/spec/postgresql/migrate/migrate_change_column_spec.rb +4 -4
  46. data/spec/postgresql/migrate/migrate_change_index_spec.rb +9 -9
  47. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +3 -3
  48. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +5 -5
  49. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +1 -1
  50. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +6 -6
  51. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +2 -2
  52. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +1 -1
  53. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +1 -1
  54. data/spec/spec_condition.rb +0 -4
  55. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a09a114ad24ead5072a479593d757ea2dad1d0f42ebf9ae84febad36db8ba78
4
- data.tar.gz: e4e14f15a869ac1b66cff3b869f4ca5d246975e4b62e4a8f5e8ecf040efe9d9c
3
+ metadata.gz: b4a820687bccfcbcfaa3290b28536a0ea3599d32a35a16e897f37a20a4e1ef75
4
+ data.tar.gz: c25c8a48b003aa297f7b1a979f609898b776c3393628d42c2dc2a0897d87be0e
5
5
  SHA512:
6
- metadata.gz: a664d190502ef67c91b9dc96f95cf4289812195939f8193354fea005de1bb83a31e479758dc0c64115dae02b6c7d62588fcd89f9129ebc2664c0bf8eef5906c1
7
- data.tar.gz: ac81928fe43c71c13542686361af7d54868782728a1d02731f431827dba66204098baf6b2a674cf817b239f285b94b5e2edf48d842997e7cdf47b238234aac71
6
+ metadata.gz: d58fae0cd35607eb2980be9600b0d31b04605c559445932d7f73ab7cec066267bb45da5ef783c0ab577fec2272f664214afd190d088c1976f299fcfb30a6c54a
7
+ data.tar.gz: 498c6a55c4d7480a7ac019e58ddc63a8212961bda3d587f9d30d860be1d04d8a8f33e5bcbac72044d759919a3abba46f36750cc4cf2bcd44b87d4af352f7318d
@@ -6,7 +6,7 @@ AllCops:
6
6
  Bundler/OrderedGems:
7
7
  Include:
8
8
  - 'Appraisals'
9
- Layout/IndentHeredoc:
9
+ Layout/HeredocIndentation:
10
10
  Enabled: false
11
11
  Metrics/AbcSize:
12
12
  Enabled: false
@@ -18,7 +18,7 @@ Metrics/ClassLength:
18
18
  Enabled: false
19
19
  Metrics/CyclomaticComplexity:
20
20
  Enabled: false
21
- Metrics/LineLength:
21
+ Layout/LineLength:
22
22
  Enabled: false
23
23
  Metrics/MethodLength:
24
24
  Enabled: false
@@ -30,8 +30,6 @@ Style/Documentation:
30
30
  Enabled: false
31
31
  Style/GuardClause:
32
32
  Enabled: false
33
- Style/MethodMissingSuper:
34
- Enabled: false
35
33
  Style/MixinUsage:
36
34
  Exclude:
37
35
  - 'spec/**/*'
@@ -41,3 +39,39 @@ Layout/ClosingHeredocIndentation:
41
39
  Enabled: false
42
40
  Style/NumericPredicate:
43
41
  Enabled: false
42
+ Layout/EmptyLinesAroundAttributeAccessor:
43
+ Enabled: true
44
+ Layout/SpaceAroundMethodCallOperator:
45
+ Enabled: true
46
+ Lint/DeprecatedOpenSSLConstant:
47
+ Enabled: true
48
+ Lint/MissingSuper:
49
+ Enabled: false
50
+ Lint/MixedRegexpCaptureTypes:
51
+ Enabled: true
52
+ Lint/RaiseException:
53
+ Enabled: true
54
+ Lint/StructNewOverride:
55
+ Enabled: true
56
+ Style/AccessorGrouping:
57
+ Enabled: true
58
+ Style/BisectedAttrAccessor:
59
+ Enabled: true
60
+ Style/ExponentialNotation:
61
+ Enabled: true
62
+ Style/HashEachMethods:
63
+ Enabled: true
64
+ Style/HashTransformKeys:
65
+ Enabled: true
66
+ Style/HashTransformValues:
67
+ Enabled: true
68
+ Style/RedundantAssignment:
69
+ Enabled: true
70
+ Style/RedundantFetchBlock:
71
+ Enabled: true
72
+ Style/RedundantRegexpCharacterClass:
73
+ Enabled: true
74
+ Style/RedundantRegexpEscape:
75
+ Enabled: true
76
+ Style/SlicingWithRange:
77
+ Enabled: true
@@ -4,11 +4,11 @@ group: edge
4
4
  language: ruby
5
5
  cache:
6
6
  - bundler
7
- - apt
8
7
  rvm:
9
- - 2.4.6
10
- - 2.5.5
11
- - 2.6.3
8
+ - 2.4.9
9
+ - 2.5.7
10
+ - 2.6.5
11
+ - 2.7.1
12
12
  before_script:
13
13
  - sudo service mysql stop
14
14
  - sudo service postgresql stop
@@ -41,7 +41,5 @@ addons:
41
41
  - postgresql-client-9.4
42
42
  matrix:
43
43
  exclude:
44
- - rvm: 2.3.8
45
- gemfile: gemfiles/activerecord_6.0.gemfile
46
- - rvm: 2.4.6
44
+ - rvm: 2.4.9
47
45
  gemfile: gemfiles/activerecord_6.0.gemfile
data/README.md CHANGED
@@ -109,6 +109,17 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
109
109
  * Fix "topological sort failed" error ([pull#287](https://github.com/winebarrel/ridgepole/pull/287))
110
110
  * `>= 0.8.4`
111
111
  * Display a warning if an InnoDB table doesn't have any indexes on a column where it has a foreign key ([pull#290](https://github.com/winebarrel/ridgepole/pull/290))
112
+ * `>= 0.8.5`
113
+ * Improve warning message on table options ([pull#291](https://github.com/winebarrel/ridgepole/pull/291))
114
+ * `>= 0.8.6`
115
+ * Support multiple databases feature ([pull#297](https://github.com/winebarrel/ridgepole/pull/297))
116
+ * `>= 0.8.7`
117
+ * Support `require_relative` ([pull#298](https://github.com/winebarrel/ridgepole/pull/298))
118
+ * `>= 0.8.8`
119
+ * Fix keyword arguments warnings in Ruby 2.7 ([pull#303](https://github.com/winebarrel/ridgepole/pull/303))
120
+ * `>= 0.8.9`
121
+ * Fix unexpected differences on text types and blob types on Rails 6 ([pull#306](https://github.com/winebarrel/ridgepole/pull/306))
122
+ * Fix unexpected warning when a foreign key is added on the primary key ([pull#307](https://github.com/winebarrel/ridgepole/pull/307))
112
123
  </details>
113
124
 
114
125
  ## Installation
@@ -150,6 +161,7 @@ sudo /opt/ridgepole/embedded/bin/gem install mysql2
150
161
  Usage: ridgepole [options]
151
162
  -c, --config CONF_OR_FILE
152
163
  -E, --env ENVIRONMENT
164
+ -s, --spec-name SPEC_NAME
153
165
  -a, --apply
154
166
  -m, --merge
155
167
  -f, --file SCHEMAFILE
@@ -186,6 +198,7 @@ Usage: ridgepole [options]
186
198
  --ignore-table-comment
187
199
  --skip-column-comment-change
188
200
  --create-table-with-index
201
+ --allow-pk-change
189
202
  --mysql-dump-auto-increment
190
203
  -r, --require LIBS
191
204
  --log-file LOG_FILE
@@ -302,7 +315,6 @@ end
302
315
  ```
303
316
 
304
317
  ## Collation/Charset
305
- You can use the column collation by passing `--enable-mysql-awesome` ([activerecord-mysql-awesome](https://github.com/kamipo/activerecord-mysql-awesome) is required)
306
318
 
307
319
  ```ruby
308
320
  create_table "articles", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
@@ -38,6 +38,7 @@ split = false
38
38
  diff_files = nil
39
39
  diff_with_apply = false
40
40
  exit_code = 0
41
+ spec_name = ''
41
42
 
42
43
  options = {
43
44
  dry_run: false,
@@ -76,6 +77,7 @@ ARGV.options do |opt|
76
77
  begin
77
78
  opt.on('-c', '--config CONF_OR_FILE') { |v| config = v }
78
79
  opt.on('-E', '--env ENVIRONMENT') { |v| env = v }
80
+ opt.on('-s', '--spec-name SPEC_NAME') { |v| spec_name = v }
79
81
  opt.on('-a', '--apply') { set_mode[:apply] }
80
82
  opt.on('-m', '--merge') do
81
83
  set_mode[:apply]
@@ -168,7 +170,7 @@ begin
168
170
  logger = Ridgepole::Logger.instance
169
171
  logger.debug = options[:debug]
170
172
 
171
- client = Ridgepole::Client.new(Ridgepole::Config.load(config, env), options) if config
173
+ client = Ridgepole::Client.new(Ridgepole::Config.load(config, env, spec_name), options) if config
172
174
 
173
175
  ActiveRecord::Base.logger = logger
174
176
  ActiveSupport::LogSubscriber.colorize_logging = options[:color]
@@ -247,7 +249,7 @@ begin
247
249
  file_ext = File.extname(diff_file)
248
250
 
249
251
  if %w[.yml .yaml].include?(file_ext)
250
- Ridgepole::Config.load(diff_file, env)
252
+ Ridgepole::Config.load(diff_file, env, spec_name)
251
253
  else
252
254
  File.open(diff_file)
253
255
  end
@@ -6,7 +6,7 @@ require 'yaml'
6
6
  module Ridgepole
7
7
  class Config
8
8
  class << self
9
- def load(config, env = 'development')
9
+ def load(config, env = 'development', spec_name = '')
10
10
  config = ENV.fetch(Regexp.last_match(1)) if config =~ /\Aenv:(.+)\z/
11
11
 
12
12
  parsed_config = if File.exist?(config)
@@ -26,8 +26,10 @@ module Ridgepole
26
26
 
27
27
  parsed_config = parse_database_url(config) unless parsed_config.is_a?(Hash)
28
28
 
29
- if parsed_config.key?(env.to_s)
30
- parsed_config.fetch(env.to_s)
29
+ parsed_config = parsed_config.fetch(env.to_s) if parsed_config.key?(env.to_s)
30
+
31
+ if parsed_config.key?(spec_name.to_s)
32
+ parsed_config.fetch(spec_name.to_s)
31
33
  else
32
34
  parsed_config
33
35
  end
@@ -246,7 +246,7 @@ create_table(#{table_name.inspect}, #{inspect_options_include_default_proc(optio
246
246
  end
247
247
 
248
248
  buf.puts(<<-RUBY)
249
- end
249
+ end
250
250
  RUBY
251
251
 
252
252
  if !(@options[:create_table_with_index]) && !indices.empty?
@@ -326,7 +326,7 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
326
326
  end
327
327
 
328
328
  def append_change_table(table_name, buf)
329
- buf.puts "change_table(#{table_name.inspect}, {:bulk => true}) do |t|" if @options[:bulk_change]
329
+ buf.puts "change_table(#{table_name.inspect}, bulk: true) do |t|" if @options[:bulk_change]
330
330
  yield
331
331
  buf.puts 'end' if @options[:bulk_change]
332
332
  end
@@ -429,11 +429,11 @@ remove_column(#{table_name.inspect}, #{column_name.inspect})
429
429
 
430
430
  if force_bulk_change || @options[:bulk_change]
431
431
  buf.puts(<<-RUBY)
432
- t.index(#{column_name.inspect}, #{options.inspect})
432
+ t.index(#{column_name.inspect}, **#{options.inspect})
433
433
  RUBY
434
434
  else
435
435
  buf.puts(<<-RUBY)
436
- add_index(#{table_name.inspect}, #{column_name.inspect}, #{options.inspect})
436
+ add_index(#{table_name.inspect}, #{column_name.inspect}, **#{options.inspect})
437
437
  RUBY
438
438
  end
439
439
  end
@@ -441,15 +441,20 @@ add_index(#{table_name.inspect}, #{column_name.inspect}, #{options.inspect})
441
441
  def append_remove_index(table_name, _index_name, attrs, buf)
442
442
  column_name = attrs.fetch(:column_name)
443
443
  options = attrs[:options] || {}
444
- target = options[:name] ? { name: options[:name] } : column_name
444
+ target =
445
+ if options[:name]
446
+ "name: #{options[:name].inspect}"
447
+ else
448
+ column_name.inspect
449
+ end
445
450
 
446
451
  if @options[:bulk_change]
447
452
  buf.puts(<<-RUBY)
448
- t.remove_index(#{target.inspect})
453
+ t.remove_index(#{target})
449
454
  RUBY
450
455
  else
451
456
  buf.puts(<<-RUBY)
452
- remove_index(#{table_name.inspect}, #{target.inspect})
457
+ remove_index(#{table_name.inspect}, #{target})
453
458
  RUBY
454
459
  end
455
460
  end
@@ -469,7 +474,7 @@ remove_index(#{table_name.inspect}, #{target.inspect})
469
474
  attrs_options = attrs[:options] || {}
470
475
 
471
476
  buf.puts(<<-RUBY)
472
- add_foreign_key(#{table_name.inspect}, #{to_table.inspect}, #{attrs_options.inspect})
477
+ add_foreign_key(#{table_name.inspect}, #{to_table.inspect}, **#{attrs_options.inspect})
473
478
  RUBY
474
479
  end
475
480
 
@@ -478,13 +483,13 @@ add_foreign_key(#{table_name.inspect}, #{to_table.inspect}, #{attrs_options.insp
478
483
  fk_name = attrs_options[:name]
479
484
 
480
485
  target = if fk_name
481
- { name: fk_name }
486
+ "name: #{fk_name.inspect}"
482
487
  else
483
- attrs.fetch(:to_table)
488
+ attrs.fetch(:to_table).inspect
484
489
  end
485
490
 
486
491
  buf.puts(<<-RUBY)
487
- remove_foreign_key(#{table_name.inspect}, #{target.inspect})
492
+ remove_foreign_key(#{table_name.inspect}, #{target})
488
493
  RUBY
489
494
  end
490
495
 
@@ -500,17 +505,19 @@ remove_foreign_key(#{table_name.inspect}, #{target.inspect})
500
505
  def inspect_options_include_default_proc(options)
501
506
  options = options.dup
502
507
 
503
- if options[:default].is_a?(Proc)
504
- proc_default = options.delete(:default)
505
- proc_default = ":default=>proc{#{proc_default.call.inspect}}"
506
- options_inspect = options.inspect
507
- options_inspect.sub!(/\}\z/, '')
508
- options_inspect << ', ' if options_inspect !~ /\{\z/
509
- options_inspect << proc_default << '}'
510
- options_inspect
511
- else
512
- options.inspect
513
- end
508
+ kwargs =
509
+ if options[:default].is_a?(Proc)
510
+ proc_default = options.delete(:default)
511
+ proc_default = ":default=>proc{#{proc_default.call.inspect}}"
512
+ options_inspect = options.inspect
513
+ options_inspect.sub!(/\}\z/, '')
514
+ options_inspect << ', ' if options_inspect !~ /\{\z/
515
+ options_inspect << proc_default << '}'
516
+ options_inspect
517
+ else
518
+ options.inspect
519
+ end
520
+ "**#{kwargs}"
514
521
  end
515
522
  end
516
523
  end
@@ -169,7 +169,7 @@ module Ridgepole
169
169
 
170
170
  unless from == to
171
171
  @logger.warn(<<-MSG)
172
- [WARNING] No difference of schema configuration for table `#{table_name}` but table options differ.
172
+ [WARNING] Table option changes are ignored on `#{table_name}`.
173
173
  from: #{from}
174
174
  to: #{to}
175
175
  MSG
@@ -386,6 +386,18 @@ module Ridgepole
386
386
  attrs[:type] = :bigint
387
387
  opts.delete(:limit)
388
388
  end
389
+
390
+ if opts[:size] && (attrs[:type] == :text || attrs[:type] == :blob || attrs[:type] == :binary)
391
+ case opts.delete(:size)
392
+ when :tiny
393
+ attrs[:type] = :blob if attrs[:type] == :binary
394
+ opts[:limit] = 255
395
+ when :medium
396
+ opts[:limit] = 16_777_215
397
+ when :long
398
+ opts[:limit] = 4_294_967_295
399
+ end
400
+ end
389
401
  end
390
402
  end
391
403
 
@@ -37,10 +37,11 @@ module Ridgepole
37
37
  attrs[:foreign_keys].each do |_, foreign_key_attrs|
38
38
  fk_index = foreign_key_attrs[:options][:column] || "#{foreign_key_attrs[:to_table].singularize}_id"
39
39
  next if attrs[:indices]&.any? { |_k, v| v[:column_name].first == fk_index }
40
+ next if attrs[:options][:primary_key] == fk_index
40
41
 
41
42
  Ridgepole::Logger.instance.warn(<<-MSG)
42
43
  [WARNING] Table `#{table_name}` has a foreign key on `#{fk_index}` column, but doesn't have any indexes on the column.
43
- Although an index will be added automatically by InnoDB, please add an index explicitly for your future operations.
44
+ Although an index will be added automatically by InnoDB, please add an index explicitly before the next operation.
44
45
  MSG
45
46
  end
46
47
  end
@@ -3,8 +3,7 @@
3
3
  module Ridgepole
4
4
  class DSLParser
5
5
  class Context
6
- attr_reader :__definition
7
- attr_reader :__execute
6
+ attr_reader :__definition, :__execute
8
7
 
9
8
  def initialize(opts = {})
10
9
  @__working_dir = File.expand_path(opts[:path] ? File.dirname(opts[:path]) : Dir.pwd)
@@ -104,6 +103,10 @@ module Ridgepole
104
103
  end
105
104
  end
106
105
 
106
+ def require_relative(relative_path)
107
+ require(File.expand_path(relative_path, File.dirname(caller[0])))
108
+ end
109
+
107
110
  def execute(sql, _name = nil, &cond)
108
111
  @__execute << {
109
112
  sql: sql,
@@ -41,7 +41,7 @@ module Ridgepole
41
41
  end
42
42
  end
43
43
  end
44
- rescue EOFError # rubocop:disable Lint/HandleExceptions
44
+ rescue EOFError
45
45
  # nothing to do
46
46
  end
47
47
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ridgepole
4
- VERSION = '0.8.4'
4
+ VERSION = '0.8.9'
5
5
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Ridgepole::DSLParser::Context do
4
+ describe '#require_relative' do
5
+ subject { context.require_relative(relative_path) }
6
+
7
+ let!(:context) do
8
+ Ridgepole::DSLParser::Context.new
9
+ end
10
+ let!(:relative_path) do
11
+ '../fixtures/for_require_relative_spec.rb'
12
+ end
13
+
14
+ it { is_expected.to be_truthy }
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ 'This file is used by dsl_parser/context_spec.'
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe Ridgepole::Config do
4
- subject { Ridgepole::Config.load(config, env) }
4
+ subject { Ridgepole::Config.load(config, env, spec_name) }
5
+
6
+ let(:spec_name) { '' }
5
7
 
6
8
  context 'when passed toplevel yaml' do
7
9
  let(:config) do
@@ -154,4 +156,55 @@ describe Ridgepole::Config do
154
156
  expect(subject['port']).to eq 3307
155
157
  }
156
158
  end
159
+
160
+ context 'when passed rails database.yml multiple databases style yaml' do
161
+ let(:config) do
162
+ <<-YAML.strip_heredoc
163
+ development:
164
+ primary:
165
+ adapter: sqlspecifye
166
+ database: db/sample.db
167
+ production:
168
+ primary:
169
+ adapter: mysql2
170
+ encoding: utf8
171
+ database: blog
172
+ username: root
173
+ primary_replica:
174
+ adapter: mysql2
175
+ encoding: utf8
176
+ database: blog
177
+ username: readonly
178
+ YAML
179
+ end
180
+
181
+ context 'in development env with primary spec name' do
182
+ let(:env) { 'development' }
183
+ let(:spec_name) { 'primary' }
184
+ specify do
185
+ expect(subject['adapter']).to eq 'sqlspecifye'
186
+ expect(subject['database']).to eq 'db/sample.db'
187
+ expect(subject['username']).to be_nil
188
+ end
189
+ end
190
+
191
+ context 'in production env with primary spec name' do
192
+ let(:env) { 'production' }
193
+ let(:spec_name) { 'primary' }
194
+ specify do
195
+ expect(subject['adapter']).to eq 'mysql2'
196
+ expect(subject['encoding']).to eq 'utf8'
197
+ expect(subject['database']).to eq 'blog'
198
+ expect(subject['username']).to eq 'root'
199
+ end
200
+ end
201
+
202
+ context 'in production env with primary_replica spec name' do
203
+ let(:env) { 'production' }
204
+ let(:spec_name) { 'primary_replica' }
205
+ specify do
206
+ expect(subject['username']).to eq 'readonly'
207
+ end
208
+ end
209
+ end
157
210
  end