public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
yaroslav (author)
Sun May 11 04:06:30 -0700 2008
commit  33a730791242bb12b2bcd8cfab0a59e2b750b725
tree    1d883f402575865a5d3bf8ea2cbf9a920812966a
parent  bc58c2c800ee1bb8e33b4054e8565ce7e19ee8fa
mephisto / db / migrate / 022_host_based_sites.rb
100644 30 lines (25 sloc) 0.88 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class HostBasedSites < ActiveRecord::Migration
  class Content < ActiveRecord::Base; end
  class Section < ActiveRecord::Base; end
  class ContentDraft < ActiveRecord::Base; end
  class ContentVersion < ActiveRecord::Base; end
  class Attachment < ActiveRecord::Base; end
  
  @@models = [Content, Section, ContentDraft, ContentVersion, Attachment].inject({}) { |hash, model| hash.merge model => model.table_name.to_sym }
  cattr_accessor :models
  
  def self.up
    Site.transaction do
      add_column :sites, :host, :string
      site = Site.find(:first).id
    
      models.each do |model, table|
        add_column table, :site_id, :integer
        model.update_all "site_id = #{site.id}"
      end
    end
  end
 
  def self.down
    Site.transaction do
      remove_column :sites, :host
      models.each { |model, table| remove_column table, :site_id }
    end
  end
end