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