batch_rollback 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 +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +7 -0
- data/Rakefile +2 -0
- data/batch_rollback.gemspec +22 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/batch_rollback/migration_step.rb +19 -0
- data/lib/batch_rollback/railtie.rb +45 -0
- data/lib/batch_rollback.rb +4 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4608d171b41f2ae0408b2770211517c2eaf1e74a916118dcb1c01af5fb5923c5
|
4
|
+
data.tar.gz: ca5c138f4877813ccc43c3b15e980f0c093574e84e898f03a89054ea10b19fec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d0fab61d1fb6ab571fe13fcf061c68f43132f6fe6abb6316a6b64c637fbdfb8be5e2e45fa43d113053f77abc89291fa14c4ad04dfcadb08a20dee623be67398
|
7
|
+
data.tar.gz: 1558f554ed6452fa79a172de317c952fd60fe7e93cbf5cd57db4a6954536b98d06927ebc20394355426eb36017ec2e283c42666df3dcc2f9180e3b99c7a5fee7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Naoto Kaneko
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "batch_rollback"
|
6
|
+
spec.version = "0.1.0"
|
7
|
+
spec.authors = ["Naoto Kaneko"]
|
8
|
+
spec.email = ["naoty.k@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = "A rubygem to enable db:rollback to rollback all versions previously migrated"
|
11
|
+
spec.homepage = "https://github.com/naoty/batch_rollback"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
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.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", "~> 5.2"
|
22
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "batch_rollback"
|
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,19 @@
|
|
1
|
+
module BatchRollback
|
2
|
+
class MigrationStep < ActiveRecord::Base
|
3
|
+
class << self
|
4
|
+
def table_name
|
5
|
+
"br_migration_steps"
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_table
|
9
|
+
return if table_exists?
|
10
|
+
|
11
|
+
connection.create_table(table_name) do |t|
|
12
|
+
t.string :current_version
|
13
|
+
t.string :target_version
|
14
|
+
t.integer :step
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module BatchRollback
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
rake_tasks do
|
4
|
+
namespace :batch_rollback do
|
5
|
+
task :pre_migrate do
|
6
|
+
ActiveRecord::SchemaMigration.create_table
|
7
|
+
ENV["BR_CURRENT_VERSION"] = ActiveRecord::SchemaMigration.all_versions.last
|
8
|
+
end
|
9
|
+
|
10
|
+
task :post_migrate do
|
11
|
+
all_versions = ActiveRecord::SchemaMigration.all_versions
|
12
|
+
current_version = ENV.delete("BR_CURRENT_VERSION")
|
13
|
+
target_version = all_versions.last
|
14
|
+
step = all_versions.index(target_version) - (all_versions.index(current_version) || -1)
|
15
|
+
next if step == 0
|
16
|
+
|
17
|
+
MigrationStep.create_table
|
18
|
+
MigrationStep.create!(
|
19
|
+
current_version: current_version,
|
20
|
+
target_version: target_version,
|
21
|
+
step: step,
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
task :pre_rollback do
|
26
|
+
next if ENV.has_key?("STEP")
|
27
|
+
|
28
|
+
current_version = ActiveRecord::SchemaMigration.all_versions.last
|
29
|
+
migration_step = MigrationStep.where(target_version: current_version).last
|
30
|
+
ENV["STEP"] = migration_step.step.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if Rake::Task.task_defined?("db:migrate")
|
35
|
+
Rake::Task["db:migrate"].enhance(["batch_rollback:pre_migrate"]) do
|
36
|
+
Rake::Task["batch_rollback:post_migrate"].invoke
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if Rake::Task.task_defined?("db:rollback")
|
41
|
+
Rake::Task["db:rollback"].enhance(["batch_rollback:pre_rollback"])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: batch_rollback
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naoto Kaneko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.2'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- naoty.k@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- batch_rollback.gemspec
|
40
|
+
- bin/console
|
41
|
+
- bin/setup
|
42
|
+
- lib/batch_rollback.rb
|
43
|
+
- lib/batch_rollback/migration_step.rb
|
44
|
+
- lib/batch_rollback/railtie.rb
|
45
|
+
homepage: https://github.com/naoty/batch_rollback
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.7.6
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: A rubygem to enable db:rollback to rollback all versions previously migrated
|
69
|
+
test_files: []
|