Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Created June 6, 2024 23:13
Show Gist options
  • Save YumaInaura/815b2e36a19c8e247b06ebe458d7cac1 to your computer and use it in GitHub Desktop.
Save YumaInaura/815b2e36a19c8e247b06ebe458d7cac1 to your computer and use it in GitHub Desktop.
Rails - Check before delete column migration, column value exist or not

Example

def up
  if Example.where.not(foo_column: nil).exists?
    raise 'Example.foo_column has some value'
  end

  remove_column  :examples, :foo_column
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment