Method: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#drop_table
- Defined in:
- lib/active_record/postgresql_extensions/tables.rb
#drop_table(*args) ⇒ Object
Drops a table. This method is expanded beyond the standard ActiveRecord drop_table method to allow for a couple of PostgreSQL-specific options:
-
:if_exists- adds an IF EXISTS clause to the query. In absence of this option, an exception will be raised if you try to drop a table that doesn’t exist. -
:cascade- adds a CASCADE clause to the query. This will cause references to this table like foreign keys to be dropped as well. See the PostgreSQL documentation for details.
You can still access the original method via original_drop_table.
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/active_record/postgresql_extensions/tables.rb', line 148 def drop_table(*args) = args. args.flatten! sql = 'DROP TABLE ' sql << 'IF EXISTS ' if [:if_exists] sql << Array.wrap(args).collect { |t| quote_table_name(t) }.join(', ') sql << ' CASCADE' if [:cascade] execute("#{sql};") end |