apartment 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.5.1
2
+ * June 21, 2011
3
+
4
+ - Fixed db migrate up/down/rollback
5
+ - added db:redo
6
+
1
7
  # 0.5.0
2
8
  * June 20, 2011
3
9
 
@@ -1,3 +1,3 @@
1
1
  module Apartment
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- namespace :apartment do
1
+ apartment_namespace = namespace :apartment do
2
2
 
3
3
  desc "Migrate all multi-tenant databases"
4
4
  task :migrate => :environment do
@@ -10,6 +10,8 @@ namespace :apartment do
10
10
  desc "Rolls the schema back to the previous version (specify steps w/ STEP=n) across all multi-tenant dbs."
11
11
  task :rollback => :environment do
12
12
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
13
+ ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_path, step)
14
+
13
15
  Apartment.database_names.each{ |db| Apartment::Migrator.rollback db, step }
14
16
  end
15
17
 
@@ -20,6 +22,7 @@ namespace :apartment do
20
22
  version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
21
23
  raise 'VERSION is required' unless version
22
24
 
25
+ ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_path, version)
23
26
  Apartment.database_names.each{ |db| Apartment::Migrator.run :up, db, version }
24
27
  end
25
28
 
@@ -28,9 +31,21 @@ namespace :apartment do
28
31
  version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
29
32
  raise 'VERSION is required' unless version
30
33
 
34
+ ActiveRecord::Migrator.run(:down, ActiveRecord::Migrator.migrations_path, version)
31
35
  Apartment.database_names.each{ |db| Apartment::Migrator.run :down, db, version }
32
36
  end
33
37
 
38
+ desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
39
+ task :redo => :environment do
40
+ if ENV['VERSION']
41
+ apartment_namespace['migrate:down'].invoke
42
+ apartment_namespace['migrate:up'].invoke
43
+ else
44
+ apartment_namespace['rollback'].invoke
45
+ apartment_namespace['migrate'].invoke
46
+ end
47
+ end
48
+
34
49
  end
35
50
 
36
51
  end
@@ -30,7 +30,8 @@ describe "apartment rake tasks" do
30
30
  ActiveRecord::Migrator.stub(:migrate) # don't care about this
31
31
  end
32
32
 
33
- it "should migrate all multi-tenant dbs" do
33
+ it "should migrate public and all multi-tenant dbs" do
34
+ ActiveRecord::Migrator.should_receive(:migrate).once
34
35
  Apartment::Migrator.should_receive(:migrate).exactly(db_count).times
35
36
  @rake['apartment:migrate'].invoke
36
37
  end
@@ -57,6 +58,7 @@ describe "apartment rake tasks" do
57
58
  end
58
59
 
59
60
  it "migrates up to a specific version" do
61
+ ActiveRecord::Migrator.should_receive(:run).with(:up, anything, version.to_i).once
60
62
  Apartment::Migrator.should_receive(:run).with(:up, anything, version.to_i).exactly(db_count).times
61
63
  @rake['apartment:migrate:up'].invoke
62
64
  end
@@ -84,6 +86,7 @@ describe "apartment rake tasks" do
84
86
  end
85
87
 
86
88
  it "migrates up to a specific version" do
89
+ ActiveRecord::Migrator.should_receive(:run).with(:down, anything, version.to_i).once
87
90
  Apartment::Migrator.should_receive(:run).with(:down, anything, version.to_i).exactly(db_count).times
88
91
  @rake['apartment:migrate:down'].invoke
89
92
  end
@@ -95,6 +98,7 @@ describe "apartment rake tasks" do
95
98
  let(:step){ '3' }
96
99
 
97
100
  it "should rollback dbs" do
101
+ ActiveRecord::Migrator.should_receive(:rollback).once
98
102
  Apartment::Migrator.should_receive(:rollback).exactly(db_count).times
99
103
  @rake['apartment:rollback'].invoke
100
104
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: apartment
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Brunner
@@ -16,7 +16,6 @@ default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
19
- prerelease: false
20
19
  requirement: &id001 !ruby/object:Gem::Requirement
21
20
  none: false
22
21
  requirements:
@@ -24,10 +23,10 @@ dependencies:
24
23
  - !ruby/object:Gem::Version
25
24
  version: 3.0.8
26
25
  type: :runtime
26
+ prerelease: false
27
27
  version_requirements: *id001
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: sqlite3
30
- prerelease: false
31
30
  requirement: &id002 !ruby/object:Gem::Requirement
32
31
  none: false
33
32
  requirements:
@@ -35,10 +34,10 @@ dependencies:
35
34
  - !ruby/object:Gem::Version
36
35
  version: "0"
37
36
  type: :development
37
+ prerelease: false
38
38
  version_requirements: *id002
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rspec
41
- prerelease: false
42
41
  requirement: &id003 !ruby/object:Gem::Requirement
43
42
  none: false
44
43
  requirements:
@@ -46,10 +45,10 @@ dependencies:
46
45
  - !ruby/object:Gem::Version
47
46
  version: 2.6.0
48
47
  type: :development
48
+ prerelease: false
49
49
  version_requirements: *id003
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec-rails
52
- prerelease: false
53
52
  requirement: &id004 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
@@ -57,10 +56,10 @@ dependencies:
57
56
  - !ruby/object:Gem::Version
58
57
  version: 2.6.1
59
58
  type: :development
59
+ prerelease: false
60
60
  version_requirements: *id004
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: capybara
63
- prerelease: false
64
63
  requirement: &id005 !ruby/object:Gem::Requirement
65
64
  none: false
66
65
  requirements:
@@ -68,10 +67,10 @@ dependencies:
68
67
  - !ruby/object:Gem::Version
69
68
  version: 1.0.0
70
69
  type: :development
70
+ prerelease: false
71
71
  version_requirements: *id005
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: pg
74
- prerelease: false
75
74
  requirement: &id006 !ruby/object:Gem::Requirement
76
75
  none: false
77
76
  requirements:
@@ -79,10 +78,10 @@ dependencies:
79
78
  - !ruby/object:Gem::Version
80
79
  version: 0.11.0
81
80
  type: :development
81
+ prerelease: false
82
82
  version_requirements: *id006
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: silent-postgres
85
- prerelease: false
86
85
  requirement: &id007 !ruby/object:Gem::Requirement
87
86
  none: false
88
87
  requirements:
@@ -90,6 +89,7 @@ dependencies:
90
89
  - !ruby/object:Gem::Version
91
90
  version: 0.0.8
92
91
  type: :development
92
+ prerelease: false
93
93
  version_requirements: *id007
94
94
  description: Apartment allows Rails applications to deal with database multitenancy
95
95
  email:
@@ -185,12 +185,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="
187
187
  - !ruby/object:Gem::Version
188
+ hash: 2503870912539283995
189
+ segments:
190
+ - 0
188
191
  version: "0"
189
192
  required_rubygems_version: !ruby/object:Gem::Requirement
190
193
  none: false
191
194
  requirements:
192
195
  - - ">="
193
196
  - !ruby/object:Gem::Version
197
+ hash: 2503870912539283995
198
+ segments:
199
+ - 0
194
200
  version: "0"
195
201
  requirements: []
196
202