ridgepole-replace_db_task 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ridgepole-replace_db_task.rb +1 -0
- data/lib/ridgepole/replace_db_task.rb +28 -0
- data/lib/ridgepole/replace_db_task/config.rb +15 -0
- data/lib/ridgepole/replace_db_task/executor.rb +57 -0
- data/lib/ridgepole/replace_db_task/railtie.rb +5 -0
- data/lib/ridgepole/replace_db_task/version.rb +5 -0
- data/lib/tasks/db.rake +25 -0
- data/ridgepole-replace_db_task.gemspec +30 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59fd5b67c158bfb71d38167b7040cb5dbe53036efbf90423fdb055b996d9e571
|
4
|
+
data.tar.gz: a1c62493f236aa07c3ae1e1adab49d0d806425a349d4fdf6e0db42be83cf23a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7226b6db03167a61b59c6e4f4e1286383ac162bb659e1cf7cfe2d5086671548d4e75cbaaf4c35abecfe05f341135515d117face938884cb35498afd91c0e239c
|
7
|
+
data.tar.gz: 421ab38dc2db7571f64ba1b51b1503f173ab052a0fe9eb34f641dd52202b635cc582dec94f3ed5eb7e3f9cb777ff45923fad26c71d3c9c7fa5ced778a628adf7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Takahiro Ooishi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Ridgepole::ReplaceDbTask
|
2
|
+
|
3
|
+
Replace rails db:migrate to use ridgepole
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ridgepole-replace_db_task'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ridgepole-replace_db_task
|
20
|
+
|
21
|
+
## Make initializer file
|
22
|
+
|
23
|
+
```config/initializers/ridgepole/replace_db_task.rb
|
24
|
+
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
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/taka0125/ridgepole-replace_db_task.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "ridgepole/replace_db_task"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ridgepole
|
2
|
+
module ReplaceDbTask; end
|
3
|
+
end
|
4
|
+
|
5
|
+
require "ridgepole/replace_db_task/version"
|
6
|
+
require "ridgepole/replace_db_task/config"
|
7
|
+
require "ridgepole/replace_db_task/executor"
|
8
|
+
require "ridgepole/replace_db_task/railtie" if defined?(::Rails::Railtie)
|
9
|
+
|
10
|
+
module Ridgepole
|
11
|
+
module ReplaceDbTask
|
12
|
+
class Error < StandardError; end
|
13
|
+
|
14
|
+
def self.configure(&block)
|
15
|
+
yield @config ||= Config.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.config
|
19
|
+
@config
|
20
|
+
end
|
21
|
+
|
22
|
+
configure do |config|
|
23
|
+
config.ridgepole = 'bundle exec ridgepole'
|
24
|
+
config.skip_drop_table = false
|
25
|
+
config.ignore_tables = []
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "active_support/configurable"
|
2
|
+
|
3
|
+
module Ridgepole
|
4
|
+
module ReplaceDbTask
|
5
|
+
class Config
|
6
|
+
include ActiveSupport::Configurable
|
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
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
3
|
+
class Ridgepole::ReplaceDbTask::Executor
|
4
|
+
def self.call(rails_env, options, block)
|
5
|
+
new(rails_env, options, block).call
|
6
|
+
end
|
7
|
+
|
8
|
+
def call
|
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?
|
11
|
+
|
12
|
+
command = <<~EOD
|
13
|
+
#{Ridgepole::ReplaceDbTask.config.ridgepole} \
|
14
|
+
-c #{Ridgepole::ReplaceDbTask.config.database_yml_path} \
|
15
|
+
-f #{Ridgepole::ReplaceDbTask.config.schema_file_path} \
|
16
|
+
#{ignore_tables_option} \
|
17
|
+
#{skip_drop_table_option} \
|
18
|
+
#{@options} \
|
19
|
+
-E #{@rails_env}
|
20
|
+
EOD
|
21
|
+
puts command
|
22
|
+
|
23
|
+
out = []
|
24
|
+
is_success = Open3.popen2e(command) do |stdin, stdout_and_stderr, wait_thr|
|
25
|
+
stdin.close
|
26
|
+
|
27
|
+
stdout_and_stderr.each_line do |line|
|
28
|
+
out << line
|
29
|
+
@block.call(line)
|
30
|
+
end
|
31
|
+
|
32
|
+
wait_thr.value.success?
|
33
|
+
end
|
34
|
+
|
35
|
+
out.join("\n")
|
36
|
+
|
37
|
+
exit(1) unless is_success
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(rails_env, options, block)
|
41
|
+
@rails_env = rails_env
|
42
|
+
@options = options
|
43
|
+
@block = block
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def ignore_tables_option
|
49
|
+
ignore_tables = Ridgepole::ReplaceDbTask.config.ignore_tables
|
50
|
+
ignore_tables.present? ? '--ignore-tables ' + ignore_tables.map { |t| t.is_a?(Regexp) ? t.source : "^#{t}$" }.join(',') : ''
|
51
|
+
end
|
52
|
+
|
53
|
+
def skip_drop_table_option
|
54
|
+
skip_drop_table = Ridgepole::ReplaceDbTask.config.skip_drop_table
|
55
|
+
skip_drop_table ? '--skip-drop-table' : ''
|
56
|
+
end
|
57
|
+
end
|
data/lib/tasks/db.rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "ridgepole/replace_db_task/executor"
|
2
|
+
|
3
|
+
namespace :db do
|
4
|
+
def apply(rails_env, options, &block)
|
5
|
+
::Ridgepole::ReplaceDbTask::Executor.call(rails_env, options, block)
|
6
|
+
end
|
7
|
+
|
8
|
+
task migrate: :environment do
|
9
|
+
ENV['RAILS_ENV'] ||= 'development'
|
10
|
+
apply(ENV['RAILS_ENV'], '--apply') { |line| puts line }
|
11
|
+
|
12
|
+
if ENV['RAILS_ENV'] == 'development'
|
13
|
+
apply('test', '--apply') { |line| puts line }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'apply dry run'
|
18
|
+
task apply_dry_run: :environment do
|
19
|
+
ENV['RAILS_ENV'] ||= 'development'
|
20
|
+
|
21
|
+
apply(ENV['RAILS_ENV'], '--apply --dry-run') do |line|
|
22
|
+
puts line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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", ">= 0.7"
|
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
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ridgepole-replace_db_task
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takahiro Ooishi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ridgepole
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Replace rails db:migrate to use ridgepole
|
98
|
+
email:
|
99
|
+
- taka0125@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/ridgepole-replace_db_task.rb
|
114
|
+
- lib/ridgepole/replace_db_task.rb
|
115
|
+
- lib/ridgepole/replace_db_task/config.rb
|
116
|
+
- lib/ridgepole/replace_db_task/executor.rb
|
117
|
+
- lib/ridgepole/replace_db_task/railtie.rb
|
118
|
+
- lib/ridgepole/replace_db_task/version.rb
|
119
|
+
- lib/tasks/db.rake
|
120
|
+
- ridgepole-replace_db_task.gemspec
|
121
|
+
homepage: https://github.com/taka0125/ridgepole-replace_db_task
|
122
|
+
licenses: []
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubygems_version: 3.0.3
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Replace rails db:migrate to use ridgepole
|
143
|
+
test_files: []
|