reversibility_checker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7d36081ec7bc7c4abb8a6ea04a967fa1e6dadf9a00f65f36b9d88edb41bb38cf
4
+ data.tar.gz: 3afc569c9ef0064593a0acd3183a5e087be5d59f3cb298df8a1c64416c93d6f3
5
+ SHA512:
6
+ metadata.gz: 8113b44ad3f4f22265781c3f3e97c89100858bdd66d3868a27f2338157a34426cb7288fa1801f584c71f846cf4c12895c9762e89e304f1c0095b7b0d68cfdea6
7
+ data.tar.gz: 2a1c04ada6b3349d18f55cc3a1849bfbeb1d1dac9a6a0431115fbcc0fb45bb9988ebd821d3170ae975a63711800c33c491a9a10aeb0c32cdaca94f9b9f7af30e
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in reversibility_checker.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,129 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reversibility_checker (0.1.0)
5
+ diffy
6
+ rails (~> 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.2.1)
12
+ actionpack (= 5.2.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailer (5.2.1)
16
+ actionpack (= 5.2.1)
17
+ actionview (= 5.2.1)
18
+ activejob (= 5.2.1)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.2.1)
22
+ actionview (= 5.2.1)
23
+ activesupport (= 5.2.1)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.2.1)
29
+ activesupport (= 5.2.1)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.2.1)
35
+ activesupport (= 5.2.1)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.2.1)
38
+ activesupport (= 5.2.1)
39
+ activerecord (5.2.1)
40
+ activemodel (= 5.2.1)
41
+ activesupport (= 5.2.1)
42
+ arel (>= 9.0)
43
+ activestorage (5.2.1)
44
+ actionpack (= 5.2.1)
45
+ activerecord (= 5.2.1)
46
+ marcel (~> 0.3.1)
47
+ activesupport (5.2.1)
48
+ concurrent-ruby (~> 1.0, >= 1.0.2)
49
+ i18n (>= 0.7, < 2)
50
+ minitest (~> 5.1)
51
+ tzinfo (~> 1.1)
52
+ arel (9.0.0)
53
+ builder (3.2.3)
54
+ concurrent-ruby (1.0.5)
55
+ crass (1.0.4)
56
+ diffy (3.2.1)
57
+ erubi (1.7.1)
58
+ globalid (0.4.1)
59
+ activesupport (>= 4.2.0)
60
+ i18n (1.1.1)
61
+ concurrent-ruby (~> 1.0)
62
+ loofah (2.2.2)
63
+ crass (~> 1.0.2)
64
+ nokogiri (>= 1.5.9)
65
+ mail (2.7.1)
66
+ mini_mime (>= 0.1.1)
67
+ marcel (0.3.3)
68
+ mimemagic (~> 0.3.2)
69
+ method_source (0.9.0)
70
+ mimemagic (0.3.2)
71
+ mini_mime (1.0.1)
72
+ mini_portile2 (2.3.0)
73
+ minitest (5.11.3)
74
+ nio4r (2.3.1)
75
+ nokogiri (1.8.5)
76
+ mini_portile2 (~> 2.3.0)
77
+ rack (2.0.5)
78
+ rack-test (1.1.0)
79
+ rack (>= 1.0, < 3)
80
+ rails (5.2.1)
81
+ actioncable (= 5.2.1)
82
+ actionmailer (= 5.2.1)
83
+ actionpack (= 5.2.1)
84
+ actionview (= 5.2.1)
85
+ activejob (= 5.2.1)
86
+ activemodel (= 5.2.1)
87
+ activerecord (= 5.2.1)
88
+ activestorage (= 5.2.1)
89
+ activesupport (= 5.2.1)
90
+ bundler (>= 1.3.0)
91
+ railties (= 5.2.1)
92
+ sprockets-rails (>= 2.0.0)
93
+ rails-dom-testing (2.0.3)
94
+ activesupport (>= 4.2.0)
95
+ nokogiri (>= 1.6)
96
+ rails-html-sanitizer (1.0.4)
97
+ loofah (~> 2.2, >= 2.2.2)
98
+ railties (5.2.1)
99
+ actionpack (= 5.2.1)
100
+ activesupport (= 5.2.1)
101
+ method_source
102
+ rake (>= 0.8.7)
103
+ thor (>= 0.19.0, < 2.0)
104
+ rake (10.5.0)
105
+ sprockets (3.7.2)
106
+ concurrent-ruby (~> 1.0)
107
+ rack (> 1, < 3)
108
+ sprockets-rails (3.2.1)
109
+ actionpack (>= 4.0)
110
+ activesupport (>= 4.0)
111
+ sprockets (>= 3.0.0)
112
+ thor (0.20.0)
113
+ thread_safe (0.3.6)
114
+ tzinfo (1.2.5)
115
+ thread_safe (~> 0.1)
116
+ websocket-driver (0.7.0)
117
+ websocket-extensions (>= 0.1.0)
118
+ websocket-extensions (0.1.3)
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ bundler (~> 1.16)
125
+ rake (~> 10.0)
126
+ reversibility_checker!
127
+
128
+ BUNDLED WITH
129
+ 1.16.6
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
@@ -0,0 +1,17 @@
1
+ # reversibility_checker
2
+
3
+ ## Install
4
+
5
+ ```rb
6
+ group :development do
7
+ gem "reversibility_checker"
8
+ end
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ $ rails db:migrate:check_reversibility
15
+ ```
16
+
17
+ This task check diffs between a current schema and a schema which migrated and rollbacked. If there are diffs, it will print the diffs and exit with exit status `1`.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ require "rails"
2
+
3
+ module ReversibilityChecker
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load "reversibility_checker/railties/reversible.rake"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ require "active_record"
2
+ require "diffy"
3
+ require "stringio"
4
+
5
+ namespace :db do
6
+ namespace :migrate do
7
+ desc "Check the reversibility of migration files"
8
+ task check_reversibility: :load_config do
9
+ require "active_record/schema_dumper"
10
+
11
+ config = ActiveRecord::Base.configurations.fetch(Rails.env)
12
+ migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
13
+
14
+ ActiveRecord::Base.establish_connection(config)
15
+ current_version = ActiveRecord::Migrator.current_version
16
+ ActiveRecord::Base.remove_connection
17
+
18
+ # Use a temporary database
19
+ config["database"] += "_tmp"
20
+
21
+ # Suppress messages from db tasks
22
+ $stdout = Tempfile.new
23
+
24
+ ActiveRecord::Tasks::DatabaseTasks.create(config)
25
+ at_exit { ActiveRecord::Tasks::DatabaseTasks.drop(config) }
26
+
27
+ ActiveRecord::Base.establish_connection(config)
28
+ ActiveRecord::Base.connection.migration_context.up(current_version)
29
+
30
+ # Take a snapshot of the temporary schema
31
+ current_buffer = StringIO.new
32
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, current_buffer)
33
+
34
+ # Migrate a temporary schema upto latest and rollback to current version
35
+ ActiveRecord::Base.connection.migration_context.up
36
+ ActiveRecord::Base.connection.migration_context.down(current_version)
37
+
38
+ # Take a snapshot again
39
+ rollbacked_buffer = StringIO.new
40
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, rollbacked_buffer)
41
+
42
+ # Compare two snapshots
43
+ diff = Diffy::Diff.new(current_buffer.string, rollbacked_buffer.string)
44
+
45
+ if diff.count > 0
46
+ Object::STDOUT.puts diff.to_s(:color)
47
+ exit 1
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module ReversibilityChecker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "reversibility_checker/railtie"
2
+ require "reversibility_checker/version"
@@ -0,0 +1,40 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "reversibility_checker/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "reversibility_checker"
7
+ spec.version = ReversibilityChecker::VERSION
8
+ spec.authors = ["Naoto Kaneko"]
9
+ spec.email = ["naoty.k@gmail.com"]
10
+
11
+ spec.summary = %q{A rubygem to check the reversibility of migration files}
12
+ spec.description = %q{A rubygem to check the reversibility of migration files}
13
+ spec.homepage = "https://github.com/naoty/reversibility_checker"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/naoty/reversibility_checker"
23
+ spec.metadata["changelog_uri"] = "https://github.com/naoty/reversibility_checker/CHANGELOG.md"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_dependency "rails", "~> 5.2"
37
+ spec.add_dependency "diffy"
38
+ spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reversibility_checker
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-10-17 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
+ - !ruby/object:Gem::Dependency
28
+ name: diffy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: A rubygem to check the reversibility of migration files
70
+ email:
71
+ - naoty.k@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/reversibility_checker.rb
83
+ - lib/reversibility_checker/railtie.rb
84
+ - lib/reversibility_checker/railties/reversible.rake
85
+ - lib/reversibility_checker/version.rb
86
+ - reversibility_checker.gemspec
87
+ homepage: https://github.com/naoty/reversibility_checker
88
+ licenses:
89
+ - MIT
90
+ metadata:
91
+ allowed_push_host: https://rubygems.org
92
+ homepage_uri: https://github.com/naoty/reversibility_checker
93
+ source_code_uri: https://github.com/naoty/reversibility_checker
94
+ changelog_uri: https://github.com/naoty/reversibility_checker/CHANGELOG.md
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: A rubygem to check the reversibility of migration files
115
+ test_files: []