Rails migration check exist table and column
In Rails migration we can check column or table is exist or not
If column or table exist then we can skip migration otherwise run migration
Check column_exists?
We can checks to see if a column exists in a given table.
column_exists?(table_name, column_name, type = nil, options = {})
example:
column_exists?(:suppliers, :name, :string)
http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/column_exists%3F
Check table_exists?
We can checks to see if the table table_name exists on the database.
table_exists?(table_name)
Example:
table_exists?(:developers)
http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/table_exists%3F