Sha256: 9554aef4f8c6c743310f58d5b8f74ffeab918756577e3f42c2d46249475e9b75

Contents?: true

Size: 444 Bytes

Versions: 10

Compression:

Stored size: 444 Bytes

Contents

class FixUserlessArticles < ActiveRecord::Migration
  def self.up
    unless $schema_generator
      articles = Article.find(:all)
      STDERR.puts "Fixing articles with empty user_id"
      
      articles.each do |article|
        if article.user.nil?
          STDERR.puts "Fixing article #{article.id} having empty user"
          article.user_id = 1
          article.save!
        end
      end
    end
  end

  def self.down

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
typo-5.5 db/migrate/077_fix_userless_articles.rb
typo-5.4.4 db/migrate/077_fix_userless_articles.rb
typo-5.4.3 db/migrate/077_fix_userless_articles.rb
typo-5.4.2 db/migrate/077_fix_userless_articles.rb
typo-5.4.1 db/migrate/077_fix_userless_articles.rb
typo-5.4 db/migrate/077_fix_userless_articles.rb
typo-5.1.98 db/migrate/077_fix_userless_articles.rb
typo-5.2.98 db/migrate/077_fix_userless_articles.rb
typo-5.2 db/migrate/077_fix_userless_articles.rb
typo-5.3 db/migrate/077_fix_userless_articles.rb