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 +4 -4
- data/README.md +4 -0
- data/lib/ridgepole/replace_db_task/executor.rb +24 -36
- data/lib/ridgepole/replace_db_task/spec_config.rb +3 -4
- data/lib/ridgepole/replace_db_task/version.rb +1 -1
- data/lib/tasks/replaced_db.rake +24 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46e478f03e19180dd99d1c4268e65f22b28719ada11236b2d22a6049dc88e491
|
4
|
+
data.tar.gz: 5061259fbe6201b46864ecd336862a57543d68d5db02687b8dd744f98460f123
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
5
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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 :
|
46
|
+
attr_reader :env, :spec_name, :other_options, :block, :dry_run, :spec_config
|
51
47
|
|
52
|
-
def
|
53
|
-
@
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
67
|
-
return '' if spec_name.blank?
|
55
|
+
@spec_config = Ridgepole::ReplaceDbTask.config.spec_config(spec_name)
|
68
56
|
|
69
|
-
|
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, :
|
6
|
+
attr_reader :spec_name, :schema_file_path, :multiple_migration_settings, :other_options
|
7
7
|
|
8
|
-
def initialize(spec_name:, schema_file_path:,
|
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
|
data/lib/tasks/replaced_db.rake
CHANGED
@@ -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
|
-
|
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(
|
11
|
+
envs = spec_config.multiple_migration_settings.dig(rails_env.to_sym) || []
|
11
12
|
envs.each do |env|
|
12
|
-
apply(env, spec_config
|
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
|
-
|
20
|
-
ENV['RAILS_ENV'] ||= 'development'
|
20
|
+
rails_env = ENV.fetch('RAILS_ENV', 'development')
|
21
21
|
|
22
|
-
|
23
|
-
|
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(
|
31
|
-
|
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.
|
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-
|
11
|
+
date: 2023-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|