Sha256: 521c9e9b281b37bd58be818838172b7ff6e597233c747a3fd6bcdb36cd40a59d

Contents?: true

Size: 660 Bytes

Versions: 35

Compression:

Stored size: 660 Bytes

Contents

class ActiveRecord::Migration
  def self.change_column_null(table_name, column_name, column_type, null, default = nil) #:nodoc: 
    unless null || default.nil? 
      execute("UPDATE #{table_name} SET #{column_name}=#{quote(default)} WHERE #{column_name} IS NULL") 
    end
    if ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
      execute("ALTER TABLE #{table_name} ALTER #{column_name} #{null ? 'DROP' : 'SET'} NOT NULL") 
    elsif ActiveRecord::Base.connection.adapter_name.downcase == "mysql"
      execute("ALTER TABLE #{table_name} MODIFY COLUMN #{column_name} #{column_type} #{null ? 'NULL' : 'NOT NULL'}")
    end
  end
  
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
backlog-0.12.0 lib/change_column_null_migration_fix.rb
backlog-0.11.0 lib/change_column_null_migration_fix.rb
backlog-0.12.1 lib/change_column_null_migration_fix.rb
backlog-0.12.2 lib/change_column_null_migration_fix.rb
backlog-0.12.4 lib/change_column_null_migration_fix.rb
backlog-0.12.3 lib/change_column_null_migration_fix.rb
backlog-0.13.1 lib/change_column_null_migration_fix.rb
backlog-0.14.0 lib/change_column_null_migration_fix.rb
backlog-0.13.0 lib/change_column_null_migration_fix.rb
backlog-0.14.3 lib/change_column_null_migration_fix.rb
backlog-0.14.2 lib/change_column_null_migration_fix.rb
backlog-0.14.1 lib/change_column_null_migration_fix.rb
backlog-0.14.4 lib/change_column_null_migration_fix.rb
backlog-0.15.0 lib/change_column_null_migration_fix.rb
backlog-0.15.1 lib/change_column_null_migration_fix.rb
backlog-0.16.0 lib/change_column_null_migration_fix.rb
backlog-0.17.0 lib/change_column_null_migration_fix.rb
backlog-0.17.1 lib/change_column_null_migration_fix.rb
backlog-0.17.2 lib/change_column_null_migration_fix.rb
backlog-0.17.3 lib/change_column_null_migration_fix.rb