ridgepole-replace_db_task 0.5.0 → 0.6.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: 53cedd2c95e52acc6a9d4ac961c3b205a6c8a5564a30471d763d539f87495f92
4
- data.tar.gz: 07e74d2d4e6f8b9180b77f7d980295db67167d927cb1aa5dfa9e345aec3e9b17
3
+ metadata.gz: 228e262b731321fe6a0515779b36f3ef7393872a8629dc99a6372684ff209620
4
+ data.tar.gz: 3d1a722002db5bfbb670dfcf4a2023ff0a6c4f7b444d6f7594aba65f0e6c6966
5
5
  SHA512:
6
- metadata.gz: da0c6612372642b7199aa4d622faa4e4b036e8af8c1cd1fb60cf6f4b29f96c5b4d9f44d13bfc1f1d59801d14b0edcec529cfc7db5694bb55ed2e2ce52c352c6c
7
- data.tar.gz: 53fffd48addf32730d477cf135b5ee3d5a92a36f895443e9a92dcdb49ef814dded2aa35ef6c05ca272b0d352456ea96a1d3e6bf5b0cdb19c8147b0d82a447aa7
6
+ metadata.gz: 51391a63c374f02739223150788fd2f845242b38be80c78b6a761dabfb7d31c061b81d956fc0982d7997739d1b776fffdc547586b8e222f5d8b4d91b136bcb5e
7
+ data.tar.gz: 997b8fa4445425e52a9a643f29fa9c88a49c0912f5da98542c5a21187d4004def4c288e2682266675829ae3595551d7c5315b00c50f58aa8706800087c29003f
@@ -0,0 +1,33 @@
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/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', 'database.yml')
26
- config.schema_file_path = ::Rails.root.join('db', 'schemas', 'Schemafile')
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 :schema_file_path
11
- config_accessor :skip_drop_table
12
- config_accessor :ignore_tables
13
- config_accessor :migrate_with_test_when_development
14
- config_accessor :multiple_migration_settings
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 Ridgepole::ReplaceDbTask.config.schema_file_path.blank?
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 #{Ridgepole::ReplaceDbTask.config.schema_file_path} \
15
+ -f #{spec_config.schema_file_path} \
16
16
  #{ignore_tables_option} \
17
17
  #{drop_table_option} \
18
- #{@options} \
19
- -E #{@rails_env}
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 = Ridgepole::ReplaceDbTask.config.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 = Ridgepole::ReplaceDbTask.config.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
@@ -1,5 +1,5 @@
1
1
  module Ridgepole
2
2
  module ReplaceDbTask
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  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
- def self.configure(&block)
15
- yield @config ||= Config.new
16
- end
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
- configure do |config|
23
- config.ridgepole = 'bundle exec ridgepole'
24
- config.skip_drop_table = true
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
@@ -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
- ENV['RAILS_ENV'] ||= 'development'
11
- apply(ENV['RAILS_ENV'], '--apply') { |line| puts line }
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
- envs = ::Ridgepole::ReplaceDbTask.config.multiple_migration_settings.dig(ENV['RAILS_ENV'].to_sym) || []
14
- envs.each do |env|
15
- apply(env, '--apply') { |line| puts line }
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
- ENV['RAILS_ENV'] ||= 'development'
19
+ ::Ridgepole::ReplaceDbTask.config.spec_configs.each do |spec_config|
20
+ ENV['RAILS_ENV'] ||= 'development'
22
21
 
23
- apply(ENV['RAILS_ENV'], '--apply --dry-run') do |line|
24
- puts line
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.5.0
4
+ version: 0.6.0
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: 2022-04-21 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -101,6 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".github/workflows/release.yml"
104
105
  - ".gitignore"
105
106
  - ".rspec"
106
107
  - ".travis.yml"
@@ -115,13 +116,14 @@ files:
115
116
  - lib/ridgepole/replace_db_task/config.rb
116
117
  - lib/ridgepole/replace_db_task/executor.rb
117
118
  - lib/ridgepole/replace_db_task/railtie.rb
119
+ - lib/ridgepole/replace_db_task/spec_config.rb
118
120
  - lib/ridgepole/replace_db_task/version.rb
119
121
  - lib/tasks/replaced_db.rake
120
122
  - ridgepole-replace_db_task.gemspec
121
123
  homepage: https://github.com/taka0125/ridgepole-replace_db_task
122
124
  licenses: []
123
125
  metadata: {}
124
- post_install_message:
126
+ post_install_message:
125
127
  rdoc_options: []
126
128
  require_paths:
127
129
  - lib
@@ -136,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  - !ruby/object:Gem::Version
137
139
  version: '0'
138
140
  requirements: []
139
- rubygems_version: 3.0.3
140
- signing_key:
141
+ rubygems_version: 3.3.7
142
+ signing_key:
141
143
  specification_version: 4
142
144
  summary: Replace rails db:migrate to use ridgepole
143
145
  test_files: []