Sha256: d6c68e60333c8f0021d80d3fe94d98eae78a5ed4d6133b6cb46b593cce7f4cef

Contents?: true

Size: 674 Bytes

Versions: 7

Compression:

Stored size: 674 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

7 entries across 7 versions & 2 rubygems

Version Path
fat_free_crm-0.14.2 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.14.1 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.15.0.beta.2 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.15.0.beta db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.14.0 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
reduced_fat_crm-0.15.0.beta db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
reduced_fat_crm-0.14.0 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb