Sha256: e80e0ae514a2e031d883406e932015bf34270dd66855ceffdc2a7f9e14700c25

Contents?: true

Size: 492 Bytes

Versions: 20

Compression:

Stored size: 492 Bytes

Contents

class AddArticleUserId < ActiveRecord::Migration
  class BareArticle < ActiveRecord::Base
    include BareMigration
  end

  class BareUser < ActiveRecord::Base
    include BareMigration
  end

  def self.up
    STDERR.puts "Linking article authors to users"
    modify_tables_and_update(:add_column, BareArticle, :user_id, :integer) do |art|
      art.user_id = (BareUser.find_by_name(art.author).id rescue nil)
    end
  end

  def self.down
    remove_column :articles, :user_id
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
typo-3.99.0 db/migrate/003_add_article_user_id.rb
typo-3.99.3 db/migrate/003_add_article_user_id.rb
typo-3.99.1 db/migrate/003_add_article_user_id.rb
typo-3.99.2 db/migrate/003_add_article_user_id.rb
typo-4.0.0 db/migrate/003_add_article_user_id.rb
typo-4.0.2 db/migrate/003_add_article_user_id.rb
typo-4.0.1 db/migrate/003_add_article_user_id.rb
typo-3.99.4 db/migrate/003_add_article_user_id.rb
typo-4.1.1 db/migrate/003_add_article_user_id.rb
typo-4.0.3 db/migrate/003_add_article_user_id.rb
typo-5.0.2 db/migrate/003_add_article_user_id.rb
typo-5.0.1 db/migrate/003_add_article_user_id.rb
typo-4.1 db/migrate/003_add_article_user_id.rb
typo-5.0.3.98.1 db/migrate/003_add_article_user_id.rb
typo-5.0.3.98 db/migrate/003_add_article_user_id.rb
typo-5.0 db/migrate/003_add_article_user_id.rb
typo-5.1.1 db/migrate/003_add_article_user_id.rb
typo-5.1.2 db/migrate/003_add_article_user_id.rb
typo-5.1.3 db/migrate/003_add_article_user_id.rb
typo-5.1 db/migrate/003_add_article_user_id.rb