cirandas.net

ref: master

db/migrate/20100809044243_dont_accept_null_to_environment_theme.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class DontAcceptNullToEnvironmentTheme < ActiveRecord::Migration
  def self.up
    Environment.where(theme: nil).find_each do |environment|
      environment.update_attribute(:theme, 'default')
    end

    change_column :environments, :theme, :string, :default => 'default', :null => false
  end

  def self.down
    change_column :environments, :theme, :string, :default => nil, :null => true

    Environment.where(theme: 'default').find_each do |environment|
      environment.update_attribute(:theme, nil)
    end
  end
end