ridgepole-replace_db_task 0.6.0 → 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: 228e262b731321fe6a0515779b36f3ef7393872a8629dc99a6372684ff209620
4
- data.tar.gz: 3d1a722002db5bfbb670dfcf4a2023ff0a6c4f7b444d6f7594aba65f0e6c6966
3
+ metadata.gz: 46e478f03e19180dd99d1c4268e65f22b28719ada11236b2d22a6049dc88e491
4
+ data.tar.gz: 5061259fbe6201b46864ecd336862a57543d68d5db02687b8dd744f98460f123
5
5
  SHA512:
6
- metadata.gz: 51391a63c374f02739223150788fd2f845242b38be80c78b6a761dabfb7d31c061b81d956fc0982d7997739d1b776fffdc547586b8e222f5d8b4d91b136bcb5e
7
- data.tar.gz: 997b8fa4445425e52a9a643f29fa9c88a49c0912f5da98542c5a21187d4004def4c288e2682266675829ae3595551d7c5315b00c50f58aa8706800087c29003f
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.0"
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.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: 2022-10-31 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
@@ -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: '2.0'
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: '2.0'
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: '10.0'
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: '10.0'
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: '3.0'
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: '3.0'
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.3.7
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
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
-
13
- vendor/
14
- Gemfile.lock
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 2.0.1
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in ridgepole-replace_db_task.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
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,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -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