apartment 0.6.0 → 0.7.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.
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.7.0
2
+ * June 22, 2011
3
+
4
+ - Added apartment:seed rake task for seeding all dbs
5
+
1
6
  # 0.6.0
2
7
  * June 21, 2011
3
8
 
@@ -55,6 +55,11 @@ module Apartment
55
55
 
56
56
  connect_to_new(database)
57
57
  end
58
+
59
+ def seed_data
60
+ load_or_abort("#{Rails.root}/db/seeds.rb")
61
+ end
62
+ alias_method :seed, :seed_data
58
63
 
59
64
  protected
60
65
 
@@ -70,10 +75,6 @@ module Apartment
70
75
  load_or_abort("#{Rails.root}/db/schema.rb")
71
76
  end
72
77
 
73
- def seed_data
74
- load_or_abort("#{Rails.root}/db/seeds.rb")
75
- end
76
-
77
78
  # Return a new config that is multi-tenanted
78
79
  def multi_tenantify(database)
79
80
  @config.clone.tap do |config|
@@ -3,7 +3,7 @@ require 'active_support/core_ext/string/inflections' # for `constantize`
3
3
  module Apartment
4
4
  module Database
5
5
 
6
- MULTI_TENANT_METHODS = [:create, :switch, :reset, :connect_and_reset, :process]
6
+ MULTI_TENANT_METHODS = [:create, :switch, :reset, :connect_and_reset, :process, :seed]
7
7
 
8
8
  class << self
9
9
 
@@ -1,3 +1,3 @@
1
1
  module Apartment
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -4,15 +4,34 @@ apartment_namespace = namespace :apartment do
4
4
  task :migrate => :environment do
5
5
  ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_path)
6
6
 
7
- Apartment.database_names.each{ |db| Apartment::Migrator.migrate db }
7
+ Apartment.database_names.each do |db|
8
+ # Note sure I should use puts here, but Rails.logger doesn't work, how do I log in migrations?
9
+ puts("Migrating #{db} database")
10
+ Apartment::Migrator.migrate db
11
+ end
8
12
  end
9
13
 
14
+ desc "Seed all multi-tenant databases"
15
+ task :seed => :environment do
16
+ Apartment::Database.seed
17
+
18
+ Apartment.database_names.each do |db|
19
+ puts("Seeding #{db} database")
20
+ Apartment::Database.process(db) do
21
+ Apartment::Database.seed
22
+ end
23
+ end
24
+ end
25
+
10
26
  desc "Rolls the schema back to the previous version (specify steps w/ STEP=n) across all multi-tenant dbs."
11
27
  task :rollback => :environment do
12
28
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
13
29
  ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_path, step)
14
30
 
15
- Apartment.database_names.each{ |db| Apartment::Migrator.rollback db, step }
31
+ Apartment.database_names.each do |db|
32
+ puts("Rolling back #{db} database")
33
+ Apartment::Migrator.rollback db, step
34
+ end
16
35
  end
17
36
 
18
37
  namespace :migrate do
@@ -21,18 +40,24 @@ apartment_namespace = namespace :apartment do
21
40
  task :up => :environment do
22
41
  version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
23
42
  raise 'VERSION is required' unless version
24
-
25
43
  ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_path, version)
26
- Apartment.database_names.each{ |db| Apartment::Migrator.run :up, db, version }
44
+
45
+ Apartment.database_names.each do |db|
46
+ puts("Migrating #{db} database up")
47
+ Apartment::Migrator.run :up, db, version
48
+ end
27
49
  end
28
50
 
29
51
  desc 'Runs the "down" for a given migration VERSION across all multi-tenant dbs.'
30
52
  task :down => :environment do
31
53
  version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
32
54
  raise 'VERSION is required' unless version
33
-
34
55
  ActiveRecord::Migrator.run(:down, ActiveRecord::Migrator.migrations_path, version)
35
- Apartment.database_names.each{ |db| Apartment::Migrator.run :down, db, version }
56
+
57
+ Apartment.database_names.each do |db|
58
+ puts("Migrating #{db} database down")
59
+ Apartment::Migrator.run :down, db, version
60
+ end
36
61
  end
37
62
 
38
63
  desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
@@ -40,7 +40,6 @@ describe "apartment rake tasks" do
40
40
  end
41
41
 
42
42
  describe "#migrate" do
43
-
44
43
  it "should migrate all databases" do
45
44
  Apartment::Migrator.should_receive(:migrate).exactly(@db_names.length).times
46
45
 
@@ -58,5 +57,13 @@ describe "apartment rake tasks" do
58
57
  end
59
58
  end
60
59
 
60
+ describe "apartment:seed" do
61
+ it "should seed all databases" do
62
+ Apartment::Database.should_receive(:seed).exactly(@db_names.length + 1).times # +1 for the public db
63
+
64
+ @rake['apartment:seed'].invoke
65
+ end
66
+ end
67
+
61
68
  end
62
69
  end
@@ -104,11 +104,13 @@ describe "apartment rake tasks" do
104
104
  end
105
105
 
106
106
  it "should rollback dbs STEP amt" do
107
+ ActiveRecord::Migrator.should_receive(:rollback).once
107
108
  Apartment::Migrator.should_receive(:rollback).with(anything, step.to_i).exactly(db_count).times
108
109
  ENV['STEP'] = step
109
110
  @rake['apartment:rollback'].invoke
110
111
  end
111
112
  end
113
+
112
114
  end
113
115
 
114
116
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: apartment
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.0
5
+ version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Brunner
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="
187
187
  - !ruby/object:Gem::Version
188
- hash: 4521352595890258295
188
+ hash: 1175145384606930711
189
189
  segments:
190
190
  - 0
191
191
  version: "0"
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  requirements:
195
195
  - - ">="
196
196
  - !ruby/object:Gem::Version
197
- hash: 4521352595890258295
197
+ hash: 1175145384606930711
198
198
  segments:
199
199
  - 0
200
200
  version: "0"