guard-migrate 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.rdoc +2 -2
- data/lib/guard/migrate.rb +21 -15
- data/lib/guard/migrate/migration.rb +27 -0
- data/lib/guard/migrate/version.rb +1 -1
- data/spec/guard/migrate_spec.rb +43 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/support/migration_factory.rb +77 -0
- metadata +12 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7d5e05d595a1d5a18a611c7b9c1a04f3f4ded17
|
4
|
+
data.tar.gz: fc3bdde15e2540bf963accf03b1712917fc162f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c43f0dd14b4785264fae876157ae970fce76a000e9e7780a83d83821f66a87dda40917210b68be13ca8371b29c66812c495ac927c0cfced46e5ba53f9f9305c0
|
7
|
+
data.tar.gz: 80e14d5b39058868178d2a83761d99ed91c15e16f2ab7c83d1b6875532e6513046f2519593347b30292fafe98a83f709ace71007d96d6744ee4db8d46b9eaab2
|
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
= Guard::Migrate
|
3
|
-
|
3
|
+
{<img src="https://badge.fury.io/rb/guard-migrate.png" alt="Gem Version" />}[http://badge.fury.io/rb/guard-migrate]
|
4
4
|
{<img src="https://secure.travis-ci.org/glanotte/guard-migrate.png" />}[http://travis-ci.org/glanotte/guard-migrate]
|
5
5
|
|
6
6
|
Migrate guard allows you to keep you migrations up to date while developing without needing to rerun them every time. I developed it because when I am first working out a project, the schema can change several times and this saves me several downs/ups/resets.
|
@@ -52,6 +52,6 @@ Available options:
|
|
52
52
|
{Geoff Lanotte}[https://github.com/glanotte]
|
53
53
|
== Copyright
|
54
54
|
|
55
|
-
Copyright (c)
|
55
|
+
Copyright (c) 2013 Geoff Lanotte. See LICENSE.txt for
|
56
56
|
further details.
|
57
57
|
|
data/lib/guard/migrate.rb
CHANGED
@@ -4,6 +4,7 @@ require 'guard/guard'
|
|
4
4
|
module Guard
|
5
5
|
class Migrate < Guard
|
6
6
|
autoload :Notify, 'guard/migrate/notify'
|
7
|
+
autoload :Migration, 'guard/migrate/migration'
|
7
8
|
attr_reader :seed, :rails_env
|
8
9
|
|
9
10
|
def initialize(watchers=[], options={})
|
@@ -65,20 +66,21 @@ module Guard
|
|
65
66
|
# Called on file(s) modifications
|
66
67
|
def run_on_changes(paths)
|
67
68
|
if paths.any?{|path| path.match(%r{^db/migrate/(\d+).+\.rb})}
|
68
|
-
|
69
|
+
migrations = paths.map {|path| Migration.new(path)}
|
70
|
+
migrate(migrations)
|
69
71
|
elsif paths.any?{|path| path.match(%r{^db/seeds\.rb$})}
|
70
72
|
seed_only
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
|
-
def migrate(
|
75
|
-
return if !reset? &&
|
76
|
+
def migrate(migrations = [])
|
77
|
+
return if !reset? && migrations.empty?
|
76
78
|
if reset?
|
77
79
|
UI.info "Running #{rake_string}"
|
78
80
|
result = system(rake_string)
|
79
81
|
result &&= "reset"
|
80
82
|
else
|
81
|
-
result = run_all_migrations(
|
83
|
+
result = run_all_migrations(migrations)
|
82
84
|
end
|
83
85
|
|
84
86
|
Notify.new(result).notify
|
@@ -91,14 +93,14 @@ module Guard
|
|
91
93
|
Notify.new(result).notify
|
92
94
|
end
|
93
95
|
|
94
|
-
def run_redo?(
|
95
|
-
!reset? &&
|
96
|
+
def run_redo?(version)
|
97
|
+
!reset? && version && !version.empty?
|
96
98
|
end
|
97
99
|
|
98
|
-
def rake_string(
|
100
|
+
def rake_string(version = nil)
|
99
101
|
[
|
100
102
|
rake_command,
|
101
|
-
migrate_string(
|
103
|
+
migrate_string(version),
|
102
104
|
seed_string,
|
103
105
|
clone_string,
|
104
106
|
rails_env_string
|
@@ -116,12 +118,16 @@ module Guard
|
|
116
118
|
|
117
119
|
private
|
118
120
|
|
119
|
-
def run_all_migrations(
|
121
|
+
def run_all_migrations(migrations)
|
120
122
|
result = nil
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
123
|
+
migrations.each do |migration|
|
124
|
+
if migration.valid?
|
125
|
+
UI.info "Running #{rake_string(migration.version)}"
|
126
|
+
result = system rake_string(migration.version)
|
127
|
+
break unless result
|
128
|
+
else
|
129
|
+
UI.info "Skip empty migration - #{migration.version}"
|
130
|
+
end
|
125
131
|
end
|
126
132
|
|
127
133
|
result
|
@@ -146,10 +152,10 @@ module Guard
|
|
146
152
|
"db:seed" if @seed
|
147
153
|
end
|
148
154
|
|
149
|
-
def migrate_string(
|
155
|
+
def migrate_string(version)
|
150
156
|
string = "db:migrate"
|
151
157
|
string += ":reset" if reset?
|
152
|
-
string += ":redo VERSION=#{
|
158
|
+
string += ":redo VERSION=#{version}" if run_redo?(version)
|
153
159
|
string
|
154
160
|
end
|
155
161
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Guard
|
2
|
+
class Migrate
|
3
|
+
class Migration
|
4
|
+
|
5
|
+
attr_accessor :path
|
6
|
+
|
7
|
+
def initialize(_path)
|
8
|
+
@path = _path
|
9
|
+
end
|
10
|
+
|
11
|
+
def version
|
12
|
+
path.scan(%r{^db/migrate/(\d+).+\.rb}).flatten.first
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid?
|
16
|
+
file = File.open(path, 'r')
|
17
|
+
content = file.read.gsub(/\s+/, '')
|
18
|
+
!content.empty? && content.match(/def(up|down|change)end/).nil?
|
19
|
+
rescue Errno::ENOENT
|
20
|
+
false
|
21
|
+
ensure
|
22
|
+
begin; file.close; rescue; end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/guard/migrate_spec.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
describe Guard::Migrate do
|
4
5
|
let(:options){ {}}
|
5
6
|
let(:paths){{}}
|
6
7
|
|
7
8
|
subject{ Guard::Migrate.new(paths, options) }
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
FileUtils.mkdir_p('db/migrate')
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
FileUtils.rm_rf('db')
|
16
|
+
end
|
8
17
|
|
9
18
|
describe "options" do
|
10
19
|
context "bundler" do
|
@@ -156,7 +165,7 @@ describe Guard::Migrate do
|
|
156
165
|
|
157
166
|
context "run on change should fixup the path to only the version" do
|
158
167
|
##I don't like this test much - consider refactoring
|
159
|
-
let(:paths){ ['
|
168
|
+
let(:paths){ [create_valid_up_and_down_migration('1234_i_like_cheese').path] }
|
160
169
|
it "should run the rake command" do
|
161
170
|
subject.should_receive(:system).with(subject.rake_string('1234'))
|
162
171
|
subject.run_on_changes paths
|
@@ -164,11 +173,43 @@ describe Guard::Migrate do
|
|
164
173
|
end
|
165
174
|
|
166
175
|
context "run on change when set to reset should only run migrations one time" do
|
167
|
-
let(:paths){ ['
|
176
|
+
let(:paths){ [create_valid_up_and_down_migration('1234_i_like_cheese').path, create_valid_change_migration('1235_i_like_cheese').path] }
|
168
177
|
let(:options){ {:reset => true, :test_clone => true} }
|
169
178
|
it "should run the rake command" do
|
170
179
|
subject.should_receive(:system).with(subject.rake_string('1234'))
|
171
180
|
subject.run_on_changes paths
|
172
181
|
end
|
173
182
|
end
|
183
|
+
|
184
|
+
context "valid/invalid migrations" do
|
185
|
+
|
186
|
+
it "should keep valid up/down migrations" do
|
187
|
+
migration = create_valid_up_and_down_migration('1234_i_like_cheese')
|
188
|
+
|
189
|
+
subject.should_receive(:system).with(subject.rake_string('1234'))
|
190
|
+
subject.run_on_changes [migration.path]
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should keep valid change migrations" do
|
194
|
+
migration = create_valid_change_migration('1234_i_like_cheese')
|
195
|
+
|
196
|
+
subject.should_receive(:system).with(subject.rake_string('1234'))
|
197
|
+
subject.run_on_changes [migration.path]
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should remove empty up/down migrations" do
|
201
|
+
migration = create_invalid_up_and_down_migration('1234_i_like_cheese')
|
202
|
+
|
203
|
+
subject.should_not_receive(:system).with(subject.rake_string('1234'))
|
204
|
+
subject.run_on_changes [migration.path]
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should remove empty change migrations" do
|
208
|
+
migration = create_invalid_change_migration('1234_i_like_cheese')
|
209
|
+
|
210
|
+
subject.should_not_receive(:system).with(subject.rake_string('1234'))
|
211
|
+
subject.run_on_changes [migration.path]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
174
215
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
module MigrationFactory
|
2
|
+
|
3
|
+
def create_valid_up_and_down_migration(name)
|
4
|
+
create_migration(name, valid_up_and_down_migration)
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_valid_change_migration(name)
|
8
|
+
create_migration(name, valid_change_migration)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_invalid_up_and_down_migration(name)
|
12
|
+
create_migration(name, invalid_up_and_down_migration)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_invalid_change_migration(name)
|
16
|
+
create_migration(name, invalid_change_migration)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def create_migration(name, content)
|
22
|
+
migration = File.new("db/migrate/#{name}.rb", 'w')
|
23
|
+
migration.write(content)
|
24
|
+
migration.close
|
25
|
+
migration
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_up_and_down_migration
|
29
|
+
<<-EOS
|
30
|
+
class ILikeCheese < ActiveRecord::Migration
|
31
|
+
def up
|
32
|
+
add_column :my_table, :my_column, :string
|
33
|
+
end
|
34
|
+
|
35
|
+
def down
|
36
|
+
remove_column :my_table, :my_column
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
43
|
+
def valid_change_migration
|
44
|
+
<<-EOS
|
45
|
+
class ILikeCheese < ActiveRecord::Migration
|
46
|
+
def change
|
47
|
+
add_column :my_table, :my_column, :string
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
EOS
|
52
|
+
end
|
53
|
+
|
54
|
+
def invalid_up_and_down_migration
|
55
|
+
<<-EOS
|
56
|
+
class ILikeCheese < ActiveRecord::Migration
|
57
|
+
def up
|
58
|
+
end
|
59
|
+
|
60
|
+
def down
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
EOS
|
65
|
+
end
|
66
|
+
|
67
|
+
def invalid_change_migration
|
68
|
+
<<-EOS
|
69
|
+
class ILikeCheese < ActiveRecord::Migration
|
70
|
+
def change
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
EOS
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Geoff Lanotte
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: guard
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.3.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: 1.3.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
|
@@ -38,7 +34,6 @@ dependencies:
|
|
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
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: guard-rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -66,6 +59,7 @@ executables: []
|
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
61
|
files:
|
62
|
+
- lib/guard/migrate/migration.rb
|
69
63
|
- lib/guard/migrate/notify.rb
|
70
64
|
- lib/guard/migrate/templates/Guardfile
|
71
65
|
- lib/guard/migrate/version.rb
|
@@ -76,8 +70,10 @@ files:
|
|
76
70
|
- spec/guard/migrate/template_spec.rb
|
77
71
|
- spec/guard/migrate_spec.rb
|
78
72
|
- spec/spec_helper.rb
|
73
|
+
- spec/support/migration_factory.rb
|
79
74
|
homepage: http://rubygems.org/gems/guard-migrate
|
80
75
|
licenses: []
|
76
|
+
metadata: {}
|
81
77
|
post_install_message:
|
82
78
|
rdoc_options:
|
83
79
|
- --charset=UTF-8
|
@@ -86,25 +82,24 @@ rdoc_options:
|
|
86
82
|
require_paths:
|
87
83
|
- lib
|
88
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
85
|
requirements:
|
91
|
-
- -
|
86
|
+
- - '>='
|
92
87
|
- !ruby/object:Gem::Version
|
93
88
|
version: '0'
|
94
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
90
|
requirements:
|
97
|
-
- -
|
91
|
+
- - '>='
|
98
92
|
- !ruby/object:Gem::Version
|
99
93
|
version: 1.3.6
|
100
94
|
requirements: []
|
101
95
|
rubyforge_project: guard-migrate
|
102
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.0.3
|
103
97
|
signing_key:
|
104
|
-
specification_version:
|
98
|
+
specification_version: 4
|
105
99
|
summary: Guard gem for rails migrations
|
106
100
|
test_files:
|
107
101
|
- spec/guard/migrate/notifier_spec.rb
|
108
102
|
- spec/guard/migrate/template_spec.rb
|
109
103
|
- spec/guard/migrate_spec.rb
|
110
104
|
- spec/spec_helper.rb
|
105
|
+
- spec/support/migration_factory.rb
|