migration_investigation 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/migration_investigation/version.rb +1 -1
- data/lib/migration_investigation.rb +14 -9
- data/spec/migration_investigation_spec.rb +40 -30
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 698aa3dfb32aa648d5a042ce6f82180fa661658e
|
4
|
+
data.tar.gz: be6eb8f95205d6268a85f7ea3079d392ba421b68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46bbd693ef9b2729cba74692597475368dd399c31e8a84380f1b7aaf2375a2cd998a032b314afec08c1d568dec2efb12582ca64e5aa770191f87b98118421f26
|
7
|
+
data.tar.gz: d9ad4ea08aaf11ab13f864a90b70aa26de8600122559fa512b73ae4b95dbf28df995b5a219f87821254d7958d5a2c7929e25a39df512428bb641640282539f48
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
The gem is very simple:
|
24
24
|
|
25
|
-
|
25
|
+
$ MigrationInvestigation.pending_migrations? "staging", "abc123"
|
26
26
|
|
27
27
|
Where `staging` is the name of the tag, and `abc123` is the SHA you're about to deploy.
|
28
28
|
You can also pass nil for the SHA you're about to deploy and it will assume you're deloying `HEAD`.
|
@@ -30,7 +30,7 @@ You can also pass nil for the SHA you're about to deploy and it will assume you'
|
|
30
30
|
If you'd also like to check additional files or directories, say seed data, you can pass in a third
|
31
31
|
parameter:
|
32
32
|
|
33
|
-
|
33
|
+
$ MigrationInvestigation.pending_migrations? "staging", "abc123", additional_paths: ["db/seed.rb", "app/foo.txt"]
|
34
34
|
|
35
35
|
## Contributing
|
36
36
|
|
@@ -3,23 +3,28 @@ require "migration_investigation/version"
|
|
3
3
|
module MigrationInvestigation
|
4
4
|
class << self
|
5
5
|
def pending_migrations?(stage, new_sha, options={})
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
old_sha
|
10
|
-
change_count = get_change_count old_sha, new_sha, interesting_paths
|
11
|
-
change_count != 0
|
6
|
+
old_sha = latest_stage_sha stage
|
7
|
+
return true if old_sha.nil?
|
8
|
+
|
9
|
+
change_count(old_sha, new_sha, build_interesting_paths(options)) != 0
|
12
10
|
end
|
13
11
|
|
14
12
|
private
|
15
13
|
|
16
|
-
def
|
17
|
-
AutoTagger::Base.new({}).refs_for_stage(stage).last
|
14
|
+
def latest_stage_sha(stage)
|
15
|
+
latest_tag = AutoTagger::Base.new({}).refs_for_stage(stage).last
|
16
|
+
latest_tag.sha if latest_tag
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
19
|
+
def change_count(old_sha, new_sha, interesting_paths)
|
21
20
|
changes = `git diff --name-only #{old_sha} #{new_sha} #{interesting_paths.join(" ")} | wc -l`
|
22
21
|
changes.to_i
|
23
22
|
end
|
23
|
+
|
24
|
+
def build_interesting_paths(options)
|
25
|
+
interesting_paths = ["db/migrate/"]
|
26
|
+
interesting_paths << options.fetch(:additional_paths, [])
|
27
|
+
interesting_paths.flatten
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
@@ -5,55 +5,65 @@ describe MigrationInvestigation do
|
|
5
5
|
let(:stage) { "stage" }
|
6
6
|
let(:new_sha) { "abc123" }
|
7
7
|
|
8
|
-
let(:refs) { [ref1, ref2] }
|
9
|
-
let(:ref1) { double(:ref1) }
|
10
|
-
let(:ref2) { double(:ref2, sha: old_sha) }
|
11
|
-
let(:old_sha) { "cba321" }
|
12
|
-
|
13
8
|
before do
|
14
9
|
auto_tagger = double(:auto_tagger)
|
15
10
|
allow(AutoTagger::Base).to receive(:new).with({}).and_return(auto_tagger)
|
16
11
|
allow(auto_tagger).to receive(:refs_for_stage).with(stage).and_return(refs)
|
17
12
|
end
|
18
13
|
|
19
|
-
context "when
|
20
|
-
|
14
|
+
context "when there are refs for the given stage" do
|
15
|
+
let(:refs) { [ref1, ref2] }
|
16
|
+
let(:ref1) { double(:ref1) }
|
17
|
+
let(:ref2) { double(:ref2, sha: old_sha) }
|
18
|
+
let(:old_sha) { "cba321" }
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
20
|
+
context "when no additional paths are passed in" do
|
21
|
+
subject { MigrationInvestigation.pending_migrations? stage, new_sha }
|
25
22
|
|
26
|
-
|
27
|
-
|
23
|
+
before do
|
24
|
+
allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ | wc -l").and_return(git_diff)
|
25
|
+
end
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
context "when there are migrations changed between the last tag for the given change, and the new SHA" do
|
28
|
+
let(:git_diff) { " 3\n" }
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
it { is_expected.to be_truthy }
|
31
|
+
end
|
34
32
|
|
35
|
-
|
33
|
+
context "when there are no migrations changes between the last tag for the given change, and the new SHA" do
|
34
|
+
let(:git_diff) { " 0\n" }
|
35
|
+
|
36
|
+
it { is_expected.to be_falsy }
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
context "when additional paths are passed in" do
|
41
|
+
subject { MigrationInvestigation.pending_migrations? stage, new_sha, additional_paths: ["app/foo.rb"] }
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
before do
|
44
|
+
allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ app/foo.rb | wc -l").and_return(git_diff)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
context "when there are changes between the last tag for the given change, and the new SHA" do
|
48
|
+
let(:git_diff) { " 3\n" }
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
it { is_expected.to be_truthy }
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
context "when there are no changes between the last tag for the given change, and the new SHA" do
|
54
|
+
let(:git_diff) { " 0\n" }
|
54
55
|
|
55
|
-
|
56
|
+
it { is_expected.to be_falsy }
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
60
|
+
|
61
|
+
context "when there are no refs for the given stage" do
|
62
|
+
subject { MigrationInvestigation.pending_migrations? stage, new_sha }
|
63
|
+
|
64
|
+
let(:refs) { [] }
|
65
|
+
|
66
|
+
it { is_expected.to be_truthy }
|
67
|
+
end
|
58
68
|
end
|
59
69
|
end
|