migration_tools 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,37 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- migration_tools (0.1.7)
4
+ migration_tools (0.2.1)
5
5
  activerecord
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.2.6)
11
- activesupport (= 3.2.6)
10
+ activemodel (3.2.11)
11
+ activesupport (= 3.2.11)
12
12
  builder (~> 3.0.0)
13
- activerecord (3.2.6)
14
- activemodel (= 3.2.6)
15
- activesupport (= 3.2.6)
13
+ activerecord (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
16
  arel (~> 3.0.2)
17
17
  tzinfo (~> 0.3.29)
18
- activesupport (3.2.6)
18
+ activesupport (3.2.11)
19
19
  i18n (~> 0.6)
20
20
  multi_json (~> 1.0)
21
21
  appraisal (0.4.1)
22
22
  bundler
23
23
  rake
24
24
  arel (3.0.2)
25
- builder (3.0.0)
26
- i18n (0.6.0)
25
+ builder (3.0.4)
26
+ i18n (0.6.1)
27
27
  metaclass (0.0.1)
28
28
  mocha (0.11.4)
29
29
  metaclass (~> 0.0.1)
30
- multi_json (1.3.6)
30
+ multi_json (1.5.0)
31
31
  rake (0.9.2.2)
32
32
  sqlite3 (1.3.6)
33
33
  test-unit (2.5.1)
34
- tzinfo (0.3.33)
34
+ tzinfo (0.3.35)
35
35
 
36
36
  PLATFORMS
37
37
  ruby
@@ -1,22 +1,24 @@
1
- = migration_tools
1
+ # Migration Tools [![Build Status](https://secure.travis-ci.org/morten/migration_tools.png)](http://travis-ci.org/morten/migration_tools)
2
2
 
3
3
  Rake tasks for grouping migrations.
4
4
 
5
- == Groups
5
+ ## Groups
6
6
 
7
- The migration tools allow you to specify a group in your migrations. This is used to allow you to run your migrations in groups, as opposed to all at once. This is useful if you want to run a certain group of migrations before a deploy, another group during deploy and a third group after deploy.
7
+ The migration tools allow you to specify a group in your migrations. This is used to allow you to run your migrations in groups, as opposed to all at once. This is useful if you want to run a certain group of migrations before a deploy, another group during deploy and a third group after deploy.
8
8
 
9
9
  We use this technique to be able to QA new production code in an isolated environment that runs against the production database. It also reduces the number of moving parts come deploy time, which is helpful when you're doing zero downtime deploys.
10
10
 
11
11
  You specify which group a migration belongs to inside the migration, like so:
12
12
 
13
+ ```ruby
13
14
  class CreateHello < ActiveRecord::Migration
14
15
  group :before
15
-
16
+
16
17
  def self.up
17
18
  ...
18
19
  end
19
20
  end
21
+ ```
20
22
 
21
23
  The names of the possible groups are predefined to avoid turning this solution in to a generic hammer from hell. You can use the following groups: before, during, after, change. We define these as:
22
24
 
@@ -29,40 +31,26 @@ The names of the possible groups are predefined to avoid turning this solution i
29
31
  *change* this is a special group that you run whenever you want to change DB data which you'd otherwise do in script/console
30
32
 
31
33
 
32
- == Commands
34
+ ## Commands
33
35
 
34
36
  The list commands
35
37
 
38
+ ```
36
39
  $ rake db:migrate:list - shows pending migrations by group
37
40
  $ rake db:migrate:list:before - shows pending migrations for the before group
38
41
  $ rake db:migrate:list:during - shows pending migrations for the during group
39
42
  $ rake db:migrate:list:after - shows pending migrations for the after group
40
43
  $ rake db:migrate:list:change - shows pending migrations for the change group
44
+ ```
41
45
 
42
46
  The group commands
43
47
 
48
+ ```
44
49
  $ GROUP=before rake db:migrate:group - runs the migrations in the specified group
45
50
  $ rake db:migrate:group:before - runs pending migrations for the before group
46
51
  $ rake db:migrate:group:during - runs pending migrations for the during group
47
52
  $ rake db:migrate:group:after - runs pending migrations for the after group
48
53
  $ rake db:migrate:group:change - runs pending migrations for the change group
49
-
50
- Note that rake db:migrate is entirely unaffected by this.
51
-
52
- == Contributing to migration_tools
53
-
54
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
55
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
56
- * Fork the project
57
- * Start a feature/bugfix branch
58
- * Commit and push until you are happy with your contribution
59
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
60
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
61
-
62
- {<img src="https://secure.travis-ci.org/morten/migration_tools.png" />}[http://travis-ci.org/morten/migration_tools]
63
-
64
- == Copyright
65
-
66
- Copyright (c) 2010 Morten Primdahl. See MIT-LICENSE.txt for
67
- further details.
54
+ ```
55
+ Note that rake db:migrate is entirely unaffected by this.
68
56
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: /Users/mgrosser/code/tools/migration_tools
2
+ remote: /Users/primdahl/Git/migration_tools
3
3
  specs:
4
- migration_tools (0.1.7)
4
+ migration_tools (0.2.1)
5
5
  activerecord
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: /Users/mgrosser/code/tools/migration_tools
2
+ remote: /Users/primdahl/Git/migration_tools
3
3
  specs:
4
- migration_tools (0.1.7)
4
+ migration_tools (0.2.1)
5
5
  activerecord
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: /Users/mgrosser/code/tools/migration_tools
2
+ remote: /Users/primdahl/Git/migration_tools
3
3
  specs:
4
- migration_tools (0.1.7)
4
+ migration_tools (0.2.1)
5
5
  activerecord
6
6
 
7
7
  GEM
@@ -17,6 +17,12 @@ module MigrationTools
17
17
  @group
18
18
  end
19
19
 
20
+ def group=(group)
21
+ @group = nil
22
+ @pending_migrations = nil
23
+ ENV['GROUP'] = group
24
+ end
25
+
20
26
  def migrator
21
27
  @migrator ||= ActiveRecord::Migrator.new(:up, 'db/migrate')
22
28
  end
@@ -77,13 +83,28 @@ module MigrationTools
77
83
  MigrationTools::MIGRATION_GROUPS.each do |migration_group|
78
84
  desc "#{ns == :list ? 'Lists' : 'Executes' } the migrations for group #{migration_group}"
79
85
  task migration_group => :environment do
80
- ENV['GROUP'] = migration_group.to_s
86
+ self.group = migration_group.to_s
81
87
  Rake::Task["db:migrate:#{ns}"].invoke
88
+ Rake::Task["db:migrate:#{ns}"].reenable
82
89
  end
83
90
  end
84
91
  end
85
92
  end
86
93
  end
94
+
95
+ namespace :abort_if_pending_migrations do
96
+ MigrationTools::MIGRATION_GROUPS.each do |migration_group|
97
+ desc "Raises an error if there are pending #{migration_group} migrations"
98
+ task migration_group do
99
+ self.group = migration_group.to_s
100
+ Rake::Task["db:migrate:list"].invoke
101
+ Rake::Task["db:migrate:list"].reenable
102
+ if pending_migrations.any?
103
+ abort "Run \"rake db:migrate\" to update your database then try again."
104
+ end
105
+ end
106
+ end
107
+ end
87
108
  end
88
109
  end
89
110
 
@@ -1,4 +1,4 @@
1
- Gem::Specification.new "migration_tools", "0.2.1" do |s|
1
+ Gem::Specification.new "migration_tools", "0.3.0" do |s|
2
2
  s.description = "Rake tasks for Rails that add groups to migrations"
3
3
  s.summary = "Encourage migrations that do not require downtime"
4
4
  s.homepage = "http://github.com/morten/migration_tools"
@@ -32,6 +32,14 @@ class TestMigrationTools < Test::Unit::TestCase
32
32
  Rake::Task.define_task("environment")
33
33
  Rake::Task.define_task("db:schema:dump")
34
34
  @task = MigrationTools::Tasks.new
35
+
36
+ def @task.abort(msg = nil)
37
+ @aborted = true
38
+ end
39
+
40
+ def @task.aborted?
41
+ @aborted || false
42
+ end
35
43
  end
36
44
 
37
45
  def migrations
@@ -130,6 +138,20 @@ class TestMigrationTools < Test::Unit::TestCase
130
138
  Rake::Task["db:migrate:list"].invoke
131
139
  end
132
140
 
141
+ def test_abort_if_pending_migrations_with_group_without_migrations
142
+ @task.stubs(:notify)
143
+ ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => proxies))
144
+ Rake::Task["db:abort_if_pending_migrations:after"].invoke
145
+ assert !@task.aborted?, "aborted where it shouldn't"
146
+ end
147
+
148
+ def test_abort_if_pending_migrations_with_group_with_migrations
149
+ @task.stubs(:notify)
150
+ ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => proxies))
151
+ Rake::Task["db:abort_if_pending_migrations:before"].invoke
152
+ assert @task.aborted?, "did not abort"
153
+ end
154
+
133
155
  def test_migrate_group_with_group_without_pending
134
156
  ENV['GROUP'] = 'before'
135
157
  ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => []))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-10 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -39,7 +39,7 @@ files:
39
39
  - Gemfile
40
40
  - Gemfile.lock
41
41
  - MIT-LICENSE.txt
42
- - README.rdoc
42
+ - README.md
43
43
  - Rakefile
44
44
  - gemfiles/rails-2.3.gemfile
45
45
  - gemfiles/rails-2.3.gemfile.lock
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 1.8.24
77
+ rubygems_version: 1.8.23
78
78
  signing_key:
79
79
  specification_version: 3
80
80
  summary: Encourage migrations that do not require downtime