Check if a table exists in Rails

Viewed 68546

I have a rake task that won't work unless a table exists. I'm working with more than 20 engineers on a website so I want to make sure they have migrated the table before they can do a rake task which will populate that respective table.

Does AR have a method such as Table.exists? How can I make sure they have migrated the table successfully?

5 Answers

The proper way to do this is Model.table_exists?

class Dog < ApplicationRecord
  # something
end

do_something if Dog.table_exists?
Related