Ensure that migrations properly handle data dependencies and sequencing to prevent deployment failures. When migrations depend on specific records existing (like default roles or seed data), create those records within the migration itself rather than relying on seeds or post-deployment processes.

Key considerations:

Example from the discussions:

class PopulateEveryoneRole < ActiveRecord::Migration[7.1]
  disable_ddl_transaction!
  
  class UserRole < ApplicationRecord
    EVERYONE_ROLE_ID = -99
    FLAGS = { invite_users: (1 << 16) }.freeze
  end
  
  def up
    # Ensure the required role exists before other migrations depend on it
    UserRole.create!(id: UserRole::EVERYONE_ROLE_ID, permissions: UserRole::FLAGS[:invite_users])
  end
end

For complex data transformations, consider splitting operations across multiple migrations with proper sequencing, and use disable_ddl_transaction! when necessary for large data operations.