migration_investigation 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/README.md +16 -4
- data/lib/migration_investigation.rb +8 -5
- data/lib/migration_investigation/version.rb +1 -1
- data/migration_investigation.gemspec +6 -6
- data/spec/migration_investigation_spec.rb +40 -15
- data/spec/spec_helper.rb +3 -6
- metadata +18 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91513fab4ee07b15ace6022637aac1c4a6b0d63c
|
4
|
+
data.tar.gz: 678ac5207077c480991cbf8434c782dad0723d51
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e932ec123891349b920a8bd9b6d0f7c54eea89e0fd5bc39900635bb7beda5bac25f0bede1f84524e00bed31e51c38f446b60c740ad77f0c706c3f2b4822cc2f
|
7
|
+
data.tar.gz: ab1cc4ed15336aae4d5ef5a5409f5f873690db37e5e9b6467272867d691c8da11889ff8786099eae9ca639779c9280dc159445faacb4e5624caa40553d932d5f
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# MigrationInvestigation
|
2
2
|
|
3
|
-
|
3
|
+
This gem will check to see if you need to run migrations without loading your environment.
|
4
|
+
It assumes that you are using [auto_tagger](https://github.com/zilkey/auto_tagger) to tag the SHA
|
5
|
+
that has been deployed.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
gem
|
11
|
+
gem "migration_investigation"
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
@@ -18,12 +20,22 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
The gem is very simple:
|
24
|
+
|
25
|
+
$ MigrationInvestigation.pending_migrations? "staging", "abc123"
|
26
|
+
|
27
|
+
Where `staging` is the name of the tag, and `abc123` is the SHA you're about to deploy.
|
28
|
+
You can also pass nil for the SHA you're about to deploy and it will assume you're deloying `HEAD`.
|
29
|
+
|
30
|
+
If you'd also like to check additional files or directories, say seed data, you can pass in a third
|
31
|
+
parameter:
|
32
|
+
|
33
|
+
$ MigrationInvestigation.pending_migrations? "staging", "abc123", additional_paths: ["db/seed.rb", "app/foo.txt"]
|
22
34
|
|
23
35
|
## Contributing
|
24
36
|
|
25
37
|
1. Fork it
|
26
38
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am
|
39
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
28
40
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
41
|
5. Create new Pull Request
|
@@ -2,20 +2,23 @@ require "migration_investigation/version"
|
|
2
2
|
|
3
3
|
module MigrationInvestigation
|
4
4
|
class << self
|
5
|
-
def pending_migrations?
|
5
|
+
def pending_migrations?(stage, new_sha, options={})
|
6
|
+
interesting_paths = options.fetch(:additional_paths, [])
|
7
|
+
interesting_paths = [interesting_paths] unless interesting_paths.is_a?(Array)
|
8
|
+
interesting_paths << "db/migrate/"
|
6
9
|
old_sha = get_latest_sha stage
|
7
|
-
change_count = get_change_count old_sha, new_sha
|
10
|
+
change_count = get_change_count old_sha, new_sha, interesting_paths
|
8
11
|
change_count != 0
|
9
12
|
end
|
10
13
|
|
11
14
|
private
|
12
15
|
|
13
|
-
def get_latest_sha
|
16
|
+
def get_latest_sha(stage)
|
14
17
|
AutoTagger::Base.new({}).refs_for_stage(stage).last.sha
|
15
18
|
end
|
16
19
|
|
17
|
-
def get_change_count
|
18
|
-
changes = `git diff --name-only #{old_sha} #{new_sha}
|
20
|
+
def get_change_count(old_sha, new_sha, interesting_paths)
|
21
|
+
changes = `git diff --name-only #{old_sha} #{new_sha} #{interesting_paths.join(" ")} | wc -l`
|
19
22
|
changes.to_i
|
20
23
|
end
|
21
24
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "migration_investigation/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "migration_investigation"
|
8
8
|
gem.version = MigrationInvestigation::VERSION
|
9
9
|
gem.authors = ["Brent Wheeldon"]
|
10
10
|
gem.email = ["brent.wheeldon@gmail.com"]
|
11
|
-
gem.description = %q{Checks whether migrations need to be run, without loading your environment}
|
12
|
-
gem.summary = %q{Checks whether migrations
|
11
|
+
gem.description = %q{Checks whether migrations, or other operations, need to be run, without loading your environment}
|
12
|
+
gem.summary = %q{Checks whether migrations, or other parts of your repo, have any changes.}
|
13
13
|
gem.homepage = "https://github.com/BrentWheeldon/migration_investigation"
|
14
14
|
gem.license = "MIT"
|
15
15
|
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_dependency
|
22
|
-
gem.add_development_dependency
|
21
|
+
gem.add_dependency "auto_tagger", "~> 0"
|
22
|
+
gem.add_development_dependency "rspec", "~> 3"
|
23
23
|
end
|
@@ -1,34 +1,59 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe MigrationInvestigation do
|
4
4
|
describe ".pending_migrations?" do
|
5
|
-
subject { MigrationInvestigation.pending_migrations? stage, new_sha }
|
6
|
-
|
7
5
|
let(:stage) { "stage" }
|
8
6
|
let(:new_sha) { "abc123" }
|
9
7
|
|
10
8
|
let(:refs) { [ref1, ref2] }
|
11
|
-
let(:ref1) {
|
12
|
-
let(:ref2) {
|
9
|
+
let(:ref1) { double(:ref1) }
|
10
|
+
let(:ref2) { double(:ref2, sha: old_sha) }
|
13
11
|
let(:old_sha) { "cba321" }
|
14
12
|
|
15
13
|
before do
|
16
|
-
auto_tagger =
|
17
|
-
AutoTagger::Base.
|
18
|
-
auto_tagger.
|
19
|
-
MigrationInvestigation.stub(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ | wc -l") { git_diff }
|
14
|
+
auto_tagger = double(:auto_tagger)
|
15
|
+
allow(AutoTagger::Base).to receive(:new).with({}).and_return(auto_tagger)
|
16
|
+
allow(auto_tagger).to receive(:refs_for_stage).with(stage).and_return(refs)
|
20
17
|
end
|
21
18
|
|
22
|
-
context "when
|
23
|
-
|
19
|
+
context "when no additional paths are passed in" do
|
20
|
+
subject { MigrationInvestigation.pending_migrations? stage, new_sha }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ | wc -l").and_return(git_diff)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when there are migrations changed between the last tag for the given change, and the new SHA" do
|
27
|
+
let(:git_diff) { " 3\n" }
|
28
|
+
|
29
|
+
it { is_expected.to be_truthy }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when there are no migrations changes between the last tag for the given change, and the new SHA" do
|
33
|
+
let(:git_diff) { " 0\n" }
|
24
34
|
|
25
|
-
|
35
|
+
it { is_expected.to be_falsy }
|
36
|
+
end
|
26
37
|
end
|
27
38
|
|
28
|
-
context "when
|
29
|
-
|
39
|
+
context "when additional paths are passed in" do
|
40
|
+
subject { MigrationInvestigation.pending_migrations? stage, new_sha, additional_paths: ["app/foo.rb"] }
|
41
|
+
|
42
|
+
before do
|
43
|
+
allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} app/foo.rb db/migrate/ | wc -l").and_return(git_diff)
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when there are changes between the last tag for the given change, and the new SHA" do
|
47
|
+
let(:git_diff) { " 3\n" }
|
48
|
+
|
49
|
+
it { is_expected.to be_truthy }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when there are no changes between the last tag for the given change, and the new SHA" do
|
53
|
+
let(:git_diff) { " 0\n" }
|
30
54
|
|
31
|
-
|
55
|
+
it { is_expected.to be_falsy }
|
56
|
+
end
|
32
57
|
end
|
33
58
|
end
|
34
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "migration_investigation"
|
2
|
+
require "auto_tagger"
|
3
3
|
|
4
4
|
RSpec.configure do |config|
|
5
|
-
config.
|
6
|
-
config.run_all_when_everything_filtered = true
|
7
|
-
config.filter_run :focus
|
8
|
-
config.order = 'random'
|
5
|
+
config.order = "random"
|
9
6
|
end
|
metadata
CHANGED
@@ -1,57 +1,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migration_investigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brent Wheeldon
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: auto_tagger
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '3'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
46
|
-
description: Checks whether migrations need to be run, without
|
40
|
+
version: '3'
|
41
|
+
description: Checks whether migrations, or other operations, need to be run, without
|
42
|
+
loading your environment
|
47
43
|
email:
|
48
44
|
- brent.wheeldon@gmail.com
|
49
45
|
executables: []
|
50
46
|
extensions: []
|
51
47
|
extra_rdoc_files: []
|
52
48
|
files:
|
53
|
-
- .gitignore
|
54
|
-
- .rspec
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
55
51
|
- Gemfile
|
56
52
|
- LICENSE.txt
|
57
53
|
- README.md
|
@@ -64,28 +60,27 @@ files:
|
|
64
60
|
homepage: https://github.com/BrentWheeldon/migration_investigation
|
65
61
|
licenses:
|
66
62
|
- MIT
|
63
|
+
metadata: {}
|
67
64
|
post_install_message:
|
68
65
|
rdoc_options: []
|
69
66
|
require_paths:
|
70
67
|
- lib
|
71
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
69
|
requirements:
|
74
|
-
- -
|
70
|
+
- - ">="
|
75
71
|
- !ruby/object:Gem::Version
|
76
72
|
version: '0'
|
77
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
74
|
requirements:
|
80
|
-
- -
|
75
|
+
- - ">="
|
81
76
|
- !ruby/object:Gem::Version
|
82
77
|
version: '0'
|
83
78
|
requirements: []
|
84
79
|
rubyforge_project:
|
85
|
-
rubygems_version:
|
80
|
+
rubygems_version: 2.4.6
|
86
81
|
signing_key:
|
87
|
-
specification_version:
|
88
|
-
summary: Checks whether migrations
|
82
|
+
specification_version: 4
|
83
|
+
summary: Checks whether migrations, or other parts of your repo, have any changes.
|
89
84
|
test_files:
|
90
85
|
- spec/migration_investigation_spec.rb
|
91
86
|
- spec/spec_helper.rb
|