public
Description: Adds basic social networking capabilities to your existing application, including users, blogs, photos, clippings, favorites, and more.
Homepage: http://www.communityengine.org
Clone URL: git://github.com/bborn/communityengine.git
fixing migrations that add initial US metro areas
bborn (author)
Mon Jul 14 06:54:24 -0700 2008
commit  299379c2f16f36c0bbdc3c9383f907da8865a61c
tree    7debbe826014062ab6dddbc19ed02314416ea081
parent  a310550db6d615566b9d4134c0368f2131a9516d
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@ class MetroArea < ActiveRecord::Base
0
   belongs_to :country
0
 
0
   #validates_presence_of :state, :if => Proc.new { |user| user.country.eql?(Country.get(:us)) }
0
- validates_presence_of :country
0
+ validates_presence_of :country_id
0
   validates_presence_of :name
0
 
0
 end
...
3
4
5
 
6
7
8
...
3
4
5
6
7
8
9
0
@@ -3,6 +3,7 @@ class CreateMetroAreas < ActiveRecord::Migration
0
     create_table :metro_areas do |t|
0
       t.column :name, :string
0
       t.column :state_id, :integer
0
+ t.column :country_id, :integer
0
     end
0
     add_column "users", "metro_area_id", :integer
0
   end
...
280
281
282
283
 
284
285
286
...
280
281
282
 
283
284
285
286
0
@@ -280,7 +280,7 @@ class AddMetroAreas < ActiveRecord::Migration
0
 
0
       next if state.nil?
0
       
0
- ma = MetroArea.new(:name => a[0], :state => state)
0
+ ma = MetroArea.new(:name => a[0], :state => state, :country_id => 0)
0
       ma.save
0
     end
0
     if failed.size > 0
...
3
4
5
6
7
8
9
10
11
12
13
...
3
4
5
 
6
7
8
9
 
10
11
0
@@ -3,11 +3,9 @@ class CreateCountries < ActiveRecord::Migration
0
     create_table :countries do |t|
0
       t.column :name, :string
0
     end
0
- add_column :metro_areas, :country_id, :integer
0
   end
0
 
0
   def self.down
0
     drop_table :countries
0
- remove_column :metro_areas, :country_id
0
   end
0
 end
...
1
2
3
4
5
 
6
7
8
9
10
11
 
12
13
...
1
2
 
 
 
3
4
5
6
 
 
 
7
8
9
0
@@ -1,13 +1,9 @@
0
 class AddUsToExistingMetroAreas < ActiveRecord::Migration
0
   def self.up
0
- MetroArea.find(:all).each do |m|
0
- m.update_attribute(:country, Country.get(:us))
0
- end
0
+ MetroArea.update_all(:country_id => Country.get(:us))
0
   end
0
 
0
   def self.down
0
- MetroArea.find(:all).each do |m|
0
- m.update_attribute(:country, nil)
0
- end
0
+ MetroArea.update_all(:country_id => nil)
0
   end
0
 end

Comments

    No one has commented yet.