ridgepole-replace_db_task 0.5.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -2
- data/lib/ridgepole/replace_db_task/config.rb +12 -7
- data/lib/ridgepole/replace_db_task/executor.rb +23 -9
- data/lib/ridgepole/replace_db_task/spec_config.rb +19 -0
- data/lib/ridgepole/replace_db_task/version.rb +1 -1
- data/lib/ridgepole/replace_db_task.rb +8 -12
- data/lib/tasks/replaced_db.rake +18 -12
- metadata +19 -26
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -7
- data/Gemfile +0 -4
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/ridgepole-replace_db_task.gemspec +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0542b411ca2d485ec4f172da09e2f59202382a52507edb7488943267ee67c89
|
4
|
+
data.tar.gz: 0c8d685ec1a525c8bbd0a5a2fa8123c3b76fe0add681d3300445d72b601eba2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4c723e47ece3ed67a4066ef8b457f5ac42b3115d71baa7a1fe51f2e4707e57f0445e026541c77e71cdfee451032e6f4690a7f68d4977157535dcff1916e8427
|
7
|
+
data.tar.gz: 81b1fc5bf896c03520b90bafe29193ab69f366b8804793e782311f8f699b9c653295211dcbc86cfa2ad88f9ae455fa860315b7c3b6332f3986da07c203fd2cc6
|
data/README.md
CHANGED
@@ -20,10 +20,37 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Make initializer file
|
22
22
|
|
23
|
+
- multiple database
|
24
|
+
|
23
25
|
```config/initializers/ridgepole/replace_db_task.rb
|
24
26
|
Ridgepole::ReplaceDbTask.configure do |config|
|
25
|
-
config.database_yml_path = ::Rails.root.join('config
|
26
|
-
|
27
|
+
config.database_yml_path = ::Rails.root.join('config/database.yml')
|
28
|
+
|
29
|
+
config.spec_configs = [
|
30
|
+
::Ridgepole::ReplaceDbTask::SpecConfig.new(
|
31
|
+
spec_name: :primary,
|
32
|
+
schema_file_path: ::Rails.root.join('db/schemas/primary/Schemafile'),
|
33
|
+
),
|
34
|
+
::Ridgepole::ReplaceDbTask::SpecConfig.new(
|
35
|
+
spec_name: :animals,
|
36
|
+
schema_file_path: ::Rails.root.join('db/schemas/animals/Schemafile'),
|
37
|
+
)
|
38
|
+
]
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
- single database
|
43
|
+
|
44
|
+
```
|
45
|
+
Ridgepole::ReplaceDbTask.configure do |config|
|
46
|
+
config.database_yml_path = ::Rails.root.join('config/database.yml')
|
47
|
+
|
48
|
+
config.spec_configs = [
|
49
|
+
::Ridgepole::ReplaceDbTask::SpecConfig.new(
|
50
|
+
spec_name: nil,
|
51
|
+
schema_file_path: ::Rails.root.join('db/schemas/Schemafile')
|
52
|
+
)
|
53
|
+
]
|
27
54
|
end
|
28
55
|
```
|
29
56
|
|
@@ -5,13 +5,18 @@ module Ridgepole
|
|
5
5
|
class Config
|
6
6
|
include ActiveSupport::Configurable
|
7
7
|
|
8
|
-
config_accessor :ridgepole
|
9
|
-
config_accessor :database_yml_path
|
10
|
-
config_accessor :
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
config_accessor :ridgepole, default: 'bundle exec ridgepole'
|
9
|
+
config_accessor :database_yml_path, default: 'config/database.yml'
|
10
|
+
config_accessor :spec_configs, default: [
|
11
|
+
::Ridgepole::ReplaceDbTask::SpecConfig.new(
|
12
|
+
spec_name: nil,
|
13
|
+
schema_file_path: 'db/schemas/Schemafile'
|
14
|
+
)
|
15
|
+
]
|
16
|
+
|
17
|
+
def spec_config(name)
|
18
|
+
spec_configs.detect { |c| c.spec_name == name }
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
@@ -1,22 +1,23 @@
|
|
1
1
|
require "open3"
|
2
2
|
|
3
3
|
class Ridgepole::ReplaceDbTask::Executor
|
4
|
-
def self.call(rails_env, options, block)
|
5
|
-
new(rails_env, options, block).call
|
4
|
+
def self.call(rails_env, spec_name, options, block)
|
5
|
+
new(rails_env, spec_name, options, block).call
|
6
6
|
end
|
7
7
|
|
8
8
|
def call
|
9
9
|
raise 'config.database_yml_path is required.' if Ridgepole::ReplaceDbTask.config.database_yml_path.blank?
|
10
|
-
raise 'config.schema_file_path is required.' if
|
10
|
+
raise 'config.schema_file_path is required.' if spec_config.schema_file_path.blank?
|
11
11
|
|
12
12
|
command = <<~EOD
|
13
13
|
#{Ridgepole::ReplaceDbTask.config.ridgepole} \
|
14
14
|
-c #{Ridgepole::ReplaceDbTask.config.database_yml_path} \
|
15
|
-
-f #{
|
15
|
+
-f #{spec_config.schema_file_path} \
|
16
16
|
#{ignore_tables_option} \
|
17
17
|
#{drop_table_option} \
|
18
|
-
#{
|
19
|
-
|
18
|
+
#{spec_name_option} \
|
19
|
+
#{options} \
|
20
|
+
-E #{rails_env}
|
20
21
|
EOD
|
21
22
|
puts command
|
22
23
|
|
@@ -37,21 +38,34 @@ EOD
|
|
37
38
|
exit(1) unless is_success
|
38
39
|
end
|
39
40
|
|
40
|
-
def initialize(rails_env, options, block)
|
41
|
+
def initialize(rails_env, spec_name, options, block)
|
41
42
|
@rails_env = rails_env
|
43
|
+
@spec_name = spec_name
|
42
44
|
@options = options
|
43
45
|
@block = block
|
44
46
|
end
|
45
47
|
|
46
48
|
private
|
47
49
|
|
50
|
+
attr_reader :rails_env, :spec_name, :options, :block
|
51
|
+
|
52
|
+
def spec_config
|
53
|
+
@spec_config ||= Ridgepole::ReplaceDbTask.config.spec_config(spec_name)
|
54
|
+
end
|
55
|
+
|
48
56
|
def ignore_tables_option
|
49
|
-
ignore_tables =
|
57
|
+
ignore_tables = spec_config.ignore_tables
|
50
58
|
ignore_tables.present? ? '--ignore-tables ' + ignore_tables.map { |t| t.is_a?(Regexp) ? t.source : "^#{t}$" }.join(',') : ''
|
51
59
|
end
|
52
60
|
|
53
61
|
def drop_table_option
|
54
|
-
skip_drop_table =
|
62
|
+
skip_drop_table = spec_config.skip_drop_table
|
55
63
|
skip_drop_table ? '' : '--drop-table'
|
56
64
|
end
|
65
|
+
|
66
|
+
def spec_name_option
|
67
|
+
return '' if spec_name.blank?
|
68
|
+
|
69
|
+
"--spec-name #{spec_name}"
|
70
|
+
end
|
57
71
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support/configurable"
|
2
|
+
|
3
|
+
module Ridgepole
|
4
|
+
module ReplaceDbTask
|
5
|
+
class SpecConfig
|
6
|
+
attr_reader :spec_name, :schema_file_path, :skip_drop_table, :ignore_tables, :multiple_migration_settings
|
7
|
+
|
8
|
+
def initialize(spec_name:, schema_file_path:, skip_drop_table: true, ignore_tables: [], multiple_migration_settings: {development: %i[test]})
|
9
|
+
@spec_name = spec_name
|
10
|
+
@schema_file_path = schema_file_path
|
11
|
+
@skip_drop_table = skip_drop_table
|
12
|
+
@ignore_tables = ignore_tables
|
13
|
+
@multiple_migration_settings = multiple_migration_settings
|
14
|
+
|
15
|
+
freeze
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -3,6 +3,7 @@ module Ridgepole
|
|
3
3
|
end
|
4
4
|
|
5
5
|
require "ridgepole/replace_db_task/version"
|
6
|
+
require "ridgepole/replace_db_task/spec_config"
|
6
7
|
require "ridgepole/replace_db_task/config"
|
7
8
|
require "ridgepole/replace_db_task/executor"
|
8
9
|
require "ridgepole/replace_db_task/railtie" if defined?(::Rails::Railtie)
|
@@ -11,19 +12,14 @@ module Ridgepole
|
|
11
12
|
module ReplaceDbTask
|
12
13
|
class Error < StandardError; end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def self.config
|
19
|
-
@config
|
20
|
-
end
|
15
|
+
class << self
|
16
|
+
def configure(&block)
|
17
|
+
yield @config ||= Config.new
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
config.ignore_tables = []
|
26
|
-
config.multiple_migration_settings = {development: %i[test]}
|
20
|
+
def config
|
21
|
+
@config
|
22
|
+
end
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
data/lib/tasks/replaced_db.rake
CHANGED
@@ -1,27 +1,33 @@
|
|
1
1
|
require "ridgepole/replace_db_task/executor"
|
2
2
|
|
3
3
|
namespace :db do
|
4
|
-
def apply(rails_env, options, &block)
|
5
|
-
::Ridgepole::ReplaceDbTask::Executor.call(rails_env, options, block)
|
6
|
-
end
|
7
|
-
|
8
4
|
desc 'db migrate use ridgepole'
|
9
5
|
task migrate: :environment do
|
10
|
-
|
11
|
-
|
6
|
+
::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 }
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
envs = spec_config.multiple_migration_settings.dig(ENV['RAILS_ENV'].to_sym) || []
|
11
|
+
envs.each do |env|
|
12
|
+
apply(env, spec_config.spec_name, '--apply') { |line| puts line }
|
13
|
+
end
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
17
|
desc 'apply dry run'
|
20
18
|
task apply_dry_run: :environment do
|
21
|
-
|
19
|
+
::Ridgepole::ReplaceDbTask.config.spec_configs.each do |spec_config|
|
20
|
+
ENV['RAILS_ENV'] ||= 'development'
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
apply(ENV['RAILS_ENV'], spec_config.spec_name, '--apply --dry-run') do |line|
|
23
|
+
puts line
|
24
|
+
end
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def apply(rails_env, spec_name, options, &block)
|
31
|
+
::Ridgepole::ReplaceDbTask::Executor.call(rails_env, spec_name, options, block)
|
32
|
+
end
|
27
33
|
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: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takahiro Ooishi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -56,44 +56,44 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
description: Replace rails db:migrate to use ridgepole
|
98
98
|
email:
|
99
99
|
- taka0125@gmail.com
|
@@ -101,27 +101,20 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".rspec"
|
106
|
-
- ".travis.yml"
|
107
|
-
- Gemfile
|
108
104
|
- LICENSE
|
109
105
|
- README.md
|
110
|
-
- Rakefile
|
111
|
-
- bin/console
|
112
|
-
- bin/setup
|
113
106
|
- lib/ridgepole-replace_db_task.rb
|
114
107
|
- lib/ridgepole/replace_db_task.rb
|
115
108
|
- lib/ridgepole/replace_db_task/config.rb
|
116
109
|
- lib/ridgepole/replace_db_task/executor.rb
|
117
110
|
- lib/ridgepole/replace_db_task/railtie.rb
|
111
|
+
- lib/ridgepole/replace_db_task/spec_config.rb
|
118
112
|
- lib/ridgepole/replace_db_task/version.rb
|
119
113
|
- lib/tasks/replaced_db.rake
|
120
|
-
- ridgepole-replace_db_task.gemspec
|
121
114
|
homepage: https://github.com/taka0125/ridgepole-replace_db_task
|
122
115
|
licenses: []
|
123
116
|
metadata: {}
|
124
|
-
post_install_message:
|
117
|
+
post_install_message:
|
125
118
|
rdoc_options: []
|
126
119
|
require_paths:
|
127
120
|
- lib
|
@@ -136,8 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
129
|
- !ruby/object:Gem::Version
|
137
130
|
version: '0'
|
138
131
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
-
signing_key:
|
132
|
+
rubygems_version: 3.4.10
|
133
|
+
signing_key:
|
141
134
|
specification_version: 4
|
142
135
|
summary: Replace rails db:migrate to use ridgepole
|
143
136
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "ridgepole/replace_db_task"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "ridgepole/replace_db_task/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "ridgepole-replace_db_task"
|
8
|
-
spec.version = Ridgepole::ReplaceDbTask::VERSION
|
9
|
-
spec.authors = ["Takahiro Ooishi"]
|
10
|
-
spec.email = ["taka0125@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Replace rails db:migrate to use ridgepole}
|
13
|
-
spec.description = %q{Replace rails db:migrate to use ridgepole}
|
14
|
-
spec.homepage = "https://github.com/taka0125/ridgepole-replace_db_task"
|
15
|
-
|
16
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
end
|
19
|
-
spec.bindir = "exe"
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.add_dependency "railties", ">= 5.0"
|
24
|
-
spec.add_dependency "activesupport", ">= 5.0"
|
25
|
-
spec.add_dependency "ridgepole", ">= 1.0"
|
26
|
-
|
27
|
-
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
-
end
|