Sha256: a7d7af865ea8cb232569059d1e5f91d6d6e3a6c3ed0ce9d4bf642f363856b5ac

Contents?: true

Size: 676 Bytes

Versions: 12

Compression:

Stored size: 676 Bytes

Contents

class AddNotNullConstraintsForTimestampColumns < ActiveRecord::Migration
  def up
    set_timestamp_constraints :null => false unless $FFCRM_NEW_DATABASE
  end

  def down
    set_timestamp_constraints {} unless $FFCRM_NEW_DATABASE
  end

  private
  def set_timestamp_constraints(constraints)
    ActiveRecord::Base.connection.tables.each do |table|
      # If table has both timestamp columns, set not null constraints on both columns.
      if [:created_at, :updated_at].all? { |column| column_exists?(table, column) }
        [:created_at, :updated_at].each do |column|
          change_column table, column, :datetime, constraints
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fat_free_crm-0.13.6 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.13.5 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.13.4 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.13.3 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.13.2 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.12.3 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.12.2 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.13.1 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.12.1 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.13.0 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.12.0 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.11.4 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb