Sha256: 2b0fedceb4a68f2f101da6a3ac08f23bdae2a3fcd4a7d5eca895d541ac3420dc

Contents?: true

Size: 677 Bytes

Versions: 8

Compression:

Stored size: 677 Bytes

Contents

class AddNotNullConstraintsForTimestampColumns < ActiveRecord::Migration[4.2]
  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 %i[created_at updated_at].all? { |column| column_exists?(table, column) }
        %i[created_at updated_at].each do |column|
          change_column table, column, :datetime, constraints
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fat_free_crm-0.15.2 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.16.4 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.15.1 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.16.3 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.16.2 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.16.1 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.16.0 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb
fat_free_crm-0.15.0 db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb