ridgepole-replace_db_task 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +15 -24
- data/.github/workflows/release.yml +0 -33
- 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: 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:
|
11
|
+
date: 2023-12-15 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,16 +101,8 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- ".github/workflows/release.yml"
|
105
|
-
- ".gitignore"
|
106
|
-
- ".rspec"
|
107
|
-
- ".travis.yml"
|
108
|
-
- Gemfile
|
109
104
|
- LICENSE
|
110
105
|
- README.md
|
111
|
-
- Rakefile
|
112
|
-
- bin/console
|
113
|
-
- bin/setup
|
114
106
|
- lib/ridgepole-replace_db_task.rb
|
115
107
|
- lib/ridgepole/replace_db_task.rb
|
116
108
|
- lib/ridgepole/replace_db_task/config.rb
|
@@ -119,7 +111,6 @@ files:
|
|
119
111
|
- lib/ridgepole/replace_db_task/spec_config.rb
|
120
112
|
- lib/ridgepole/replace_db_task/version.rb
|
121
113
|
- lib/tasks/replaced_db.rake
|
122
|
-
- ridgepole-replace_db_task.gemspec
|
123
114
|
homepage: https://github.com/taka0125/ridgepole-replace_db_task
|
124
115
|
licenses: []
|
125
116
|
metadata: {}
|
@@ -138,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
129
|
- !ruby/object:Gem::Version
|
139
130
|
version: '0'
|
140
131
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.4.10
|
142
133
|
signing_key:
|
143
134
|
specification_version: 4
|
144
135
|
summary: Replace rails db:migrate to use ridgepole
|
@@ -1,33 +0,0 @@
|
|
1
|
-
name: Release gem
|
2
|
-
|
3
|
-
on:
|
4
|
-
workflow_dispatch:
|
5
|
-
inputs:
|
6
|
-
rubygems-otp-code:
|
7
|
-
description: RubyGems OTP code
|
8
|
-
required: true
|
9
|
-
|
10
|
-
permissions:
|
11
|
-
contents: write
|
12
|
-
|
13
|
-
jobs:
|
14
|
-
release-gem:
|
15
|
-
runs-on: ubuntu-latest
|
16
|
-
env:
|
17
|
-
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
18
|
-
GEM_HOST_OTP_CODE: ${{ github.event.inputs.rubygems-otp-code }}
|
19
|
-
steps:
|
20
|
-
- uses: actions/checkout@v2
|
21
|
-
with:
|
22
|
-
fetch-depth: 0 # bundle exec rake release で git tag を見るため、tagをfetchするようにしている
|
23
|
-
- uses: ruby/setup-ruby@v1
|
24
|
-
with:
|
25
|
-
ruby-version: 3.1.1
|
26
|
-
- name: Bundle install
|
27
|
-
run: bundle install
|
28
|
-
- name: Setup git config # bundle exec rake release でgit tagが打たれていない場合、タグを打ってpushしてくれるため用意している
|
29
|
-
run: |
|
30
|
-
git config --global user.email "taka0125@gmail.com"
|
31
|
-
git config --global user.name "Takahiro Ooishi"
|
32
|
-
- name: Release gem
|
33
|
-
run: bundle exec rake release
|
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
|