Class: MoveLabelsToTitles

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/ecrire/db/migrate/20150305123321_move_labels_to_titles.rb

Defined Under Namespace

Classes: Post, Title

Instance Method Summary collapse

Instance Method Details

#changeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ecrire/db/migrate/20150305123321_move_labels_to_titles.rb', line 9

def change
  rename_table :labels, :titles

  add_column :titles, :slug, :string, index: true
  change_column :titles, :name, :string, unique: true, null: false
  add_reference :titles, :post, index: true

  Post.all.each do |post|
    Title.create do |t|
      t.slug = post.slug
      t.name = post.title
      t.post = post
    end
  end

  remove_column :posts, :title
  remove_column :posts, :slug
end