ridgepole-replace_db_task 0.6.1 → 1.0.0

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
  SHA256:
3
- metadata.gz: b0542b411ca2d485ec4f172da09e2f59202382a52507edb7488943267ee67c89
4
- data.tar.gz: 0c8d685ec1a525c8bbd0a5a2fa8123c3b76fe0add681d3300445d72b601eba2d
3
+ metadata.gz: 46e478f03e19180dd99d1c4268e65f22b28719ada11236b2d22a6049dc88e491
4
+ data.tar.gz: 5061259fbe6201b46864ecd336862a57543d68d5db02687b8dd744f98460f123
5
5
  SHA512:
6
- metadata.gz: b4c723e47ece3ed67a4066ef8b457f5ac42b3115d71baa7a1fe51f2e4707e57f0445e026541c77e71cdfee451032e6f4690a7f68d4977157535dcff1916e8427
7
- data.tar.gz: 81b1fc5bf896c03520b90bafe29193ab69f366b8804793e782311f8f699b9c653295211dcbc86cfa2ad88f9ae455fa860315b7c3b6332f3986da07c203fd2cc6
6
+ metadata.gz: ca853a0f22bd1f8403f2d87921c226ca82744e98628b654549acbbbf65d302b89d673e41eb68f0763a6d2a4db360a59605196264c1349afd4393ae66d65347f6
7
+ data.tar.gz: 77b02f498e58b6a2928f6848d14e559f863482a01051648460476c7e3cda592890ca1493cb6e68e8eb6f894745ea9f61f3b5f6312aee777d77a84db4b0eb2e2c
data/README.md CHANGED
@@ -30,6 +30,10 @@ Ridgepole::ReplaceDbTask.configure do |config|
30
30
  ::Ridgepole::ReplaceDbTask::SpecConfig.new(
31
31
  spec_name: :primary,
32
32
  schema_file_path: ::Rails.root.join('db/schemas/primary/Schemafile'),
33
+ other_options: [
34
+ '--ignore-tables=users',
35
+ '--skip-column-comment-change'
36
+ ],
33
37
  ),
34
38
  ::Ridgepole::ReplaceDbTask::SpecConfig.new(
35
39
  spec_name: :animals,
@@ -1,24 +1,27 @@
1
1
  require "open3"
2
2
 
3
3
  class Ridgepole::ReplaceDbTask::Executor
4
- def self.call(rails_env, spec_name, options, block)
5
- new(rails_env, spec_name, options, block).call
4
+ private_class_method :new
5
+
6
+ class << self
7
+ def call(env:, spec_name:, block:, other_options: [], dry_run: true)
8
+ new(env, spec_name, block, other_options, dry_run).call
9
+ end
6
10
  end
7
11
 
8
12
  def call
9
13
  raise 'config.database_yml_path is required.' if Ridgepole::ReplaceDbTask.config.database_yml_path.blank?
10
14
  raise 'config.schema_file_path is required.' if spec_config.schema_file_path.blank?
11
15
 
12
- command = <<~EOD
13
- #{Ridgepole::ReplaceDbTask.config.ridgepole} \
14
- -c #{Ridgepole::ReplaceDbTask.config.database_yml_path} \
15
- -f #{spec_config.schema_file_path} \
16
- #{ignore_tables_option} \
17
- #{drop_table_option} \
18
- #{spec_name_option} \
19
- #{options} \
20
- -E #{rails_env}
21
- EOD
16
+ options = other_options.dup
17
+ options << "--config #{Ridgepole::ReplaceDbTask.config.database_yml_path}"
18
+ options << "--file #{spec_config.schema_file_path}"
19
+ options << "--env #{env}"
20
+ options << "--apply"
21
+ options << "--dry-run" if dry_run
22
+ options << "--spec-name #{spec_name}" if spec_name.present?
23
+
24
+ command = "#{Ridgepole::ReplaceDbTask.config.ridgepole} #{options.join(' ')}"
22
25
  puts command
23
26
 
24
27
  out = []
@@ -38,34 +41,19 @@ EOD
38
41
  exit(1) unless is_success
39
42
  end
40
43
 
41
- def initialize(rails_env, spec_name, options, block)
42
- @rails_env = rails_env
43
- @spec_name = spec_name
44
- @options = options
45
- @block = block
46
- end
47
-
48
44
  private
49
45
 
50
- attr_reader :rails_env, :spec_name, :options, :block
46
+ attr_reader :env, :spec_name, :other_options, :block, :dry_run, :spec_config
51
47
 
52
- def spec_config
53
- @spec_config ||= Ridgepole::ReplaceDbTask.config.spec_config(spec_name)
54
- end
55
-
56
- def ignore_tables_option
57
- ignore_tables = spec_config.ignore_tables
58
- ignore_tables.present? ? '--ignore-tables ' + ignore_tables.map { |t| t.is_a?(Regexp) ? t.source : "^#{t}$" }.join(',') : ''
59
- end
60
-
61
- def drop_table_option
62
- skip_drop_table = spec_config.skip_drop_table
63
- skip_drop_table ? '' : '--drop-table'
64
- end
48
+ def initialize(env, spec_name, block, other_options, dry_run)
49
+ @env = env
50
+ @spec_name = spec_name
51
+ @block = block
52
+ @other_options = other_options
53
+ @dry_run = dry_run
65
54
 
66
- def spec_name_option
67
- return '' if spec_name.blank?
55
+ @spec_config = Ridgepole::ReplaceDbTask.config.spec_config(spec_name)
68
56
 
69
- "--spec-name #{spec_name}"
57
+ freeze
70
58
  end
71
59
  end
@@ -3,14 +3,13 @@ require "active_support/configurable"
3
3
  module Ridgepole
4
4
  module ReplaceDbTask
5
5
  class SpecConfig
6
- attr_reader :spec_name, :schema_file_path, :skip_drop_table, :ignore_tables, :multiple_migration_settings
6
+ attr_reader :spec_name, :schema_file_path, :multiple_migration_settings, :other_options
7
7
 
8
- def initialize(spec_name:, schema_file_path:, skip_drop_table: true, ignore_tables: [], multiple_migration_settings: {development: %i[test]})
8
+ def initialize(spec_name:, schema_file_path:, multiple_migration_settings: { development: %i[test] }, other_options: [])
9
9
  @spec_name = spec_name
10
10
  @schema_file_path = schema_file_path
11
- @skip_drop_table = skip_drop_table
12
- @ignore_tables = ignore_tables
13
11
  @multiple_migration_settings = multiple_migration_settings
12
+ @other_options = other_options
14
13
 
15
14
  freeze
16
15
  end
@@ -1,5 +1,5 @@
1
1
  module Ridgepole
2
2
  module ReplaceDbTask
3
- VERSION = "0.6.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -3,31 +3,44 @@ require "ridgepole/replace_db_task/executor"
3
3
  namespace :db do
4
4
  desc 'db migrate use ridgepole'
5
5
  task migrate: :environment do
6
+ rails_env = ENV.fetch('RAILS_ENV', 'development')
7
+
6
8
  ::Ridgepole::ReplaceDbTask.config.spec_configs.each do |spec_config|
7
- ENV['RAILS_ENV'] ||= 'development'
8
- apply(ENV['RAILS_ENV'], spec_config.spec_name, '--apply') { |line| puts line }
9
+ apply(rails_env, spec_config)
9
10
 
10
- envs = spec_config.multiple_migration_settings.dig(ENV['RAILS_ENV'].to_sym) || []
11
+ envs = spec_config.multiple_migration_settings.dig(rails_env.to_sym) || []
11
12
  envs.each do |env|
12
- apply(env, spec_config.spec_name, '--apply') { |line| puts line }
13
+ apply(env, spec_config)
13
14
  end
14
15
  end
15
16
  end
16
17
 
17
18
  desc 'apply dry run'
18
19
  task apply_dry_run: :environment do
19
- ::Ridgepole::ReplaceDbTask.config.spec_configs.each do |spec_config|
20
- ENV['RAILS_ENV'] ||= 'development'
20
+ rails_env = ENV.fetch('RAILS_ENV', 'development')
21
21
 
22
- apply(ENV['RAILS_ENV'], spec_config.spec_name, '--apply --dry-run') do |line|
23
- puts line
24
- end
22
+ ::Ridgepole::ReplaceDbTask.config.spec_configs.each do |spec_config|
23
+ dry_run(rails_env, spec_config)
25
24
  end
26
25
  end
27
26
 
28
27
  private
29
28
 
30
- def apply(rails_env, spec_name, options, &block)
31
- ::Ridgepole::ReplaceDbTask::Executor.call(rails_env, spec_name, options, block)
29
+ def apply(env, spec_config)
30
+ execute_ridgepole(env, spec_config.spec_name, spec_config.other_options, false) { |line| puts line }
31
+ end
32
+
33
+ def dry_run(env, spec_config)
34
+ execute_ridgepole(env, spec_config.spec_name, spec_config.other_options, true) { |line| puts line }
35
+ end
36
+
37
+ def execute_ridgepole(env, spec_name, other_options, dry_run, &block)
38
+ ::Ridgepole::ReplaceDbTask::Executor.call(
39
+ env: env,
40
+ spec_name: spec_name,
41
+ other_options: other_options,
42
+ block: block,
43
+ dry_run: dry_run
44
+ )
32
45
  end
33
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole-replace_db_task
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties