Class: CreateSites

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/templates/create_sites.rb

Constant Summary collapse

TABLES =
%w(posts pages features).freeze

Class Method Summary collapse

Class Method Details

.downObject



26
27
28
29
30
31
32
33
34
# File 'lib/generators/templates/create_sites.rb', line 26

def self.down

  drop_table :sites

  TABLES.each do |tbl|
    remove_column tbl, :site_id
  end

end

.upObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/templates/create_sites.rb', line 5

def self.up
  create_table :sites, :force => true do |t|
    t.string :name
    t.string :lang
    t.timestamps
  end
  add_index :sites, :name, :unique => true

  TABLES.each do |tbl|
    add_column tbl, :site_id, :integer
    add_index tbl, :site_id
  end

  # Migrate existing posts to new site
  s = Atreides::Site.find_by_name('www') || Atreides::Site.create(:name => 'www')
  TABLES.each do |tbl|
    "Atreides::#{tbl.classify}".constantize.update_all({:site_id => s.id}, {:site_id => nil})
  end

end