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
31
32
33
34
35
36
37
38
39
|
# File 'lib/generators/templates/create_content_parts.rb', line 2
def self.up
create_table :content_parts, :force => true do |t|
t.text :body, :default => ""
t.references :contentable, :polymorphic => true
t.string :display_type
t.string :content_type
t.integer :display_order, :default => 0
t.timestamps
end
add_column :videos, :content_part_id, :integer
Atreides::Post.where("post_type = 'post' AND body is not null").all.each do |p|
p.parts.create(:content_type => 'text', :body => p.body)
end
Atreides::Post.where("post_type = 'photos'").all.each do |p|
photos = Atreides::Photo.where({:photoable_id => p.id, :photoable_type => 'Atreides::Post'}).all
p.parts.create(:content_type => 'photos', :photos => photos)
p.parts.create(:content_type => 'text', :body => p.body) if p.body?
end
Atreides::Post.where("post_type = 'videos'").all.each do |p|
videos = Atreides::Video.where({:post_id => p.id}).all
p.parts.create(:content_type => 'videos', :videos => p.videos)
p.parts.create(:content_type => 'text', :body => p.body) if p.body?
end
remove_column :videos, :post_id
remove_column :posts, :body
remove_column :posts, :post_type
end
|