Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add CASCADE to DROP TABLE when option :force is set #56

Closed
wants to merge 1 commit into from

2 participants

@jaylevitt

This is my attempt at fixing issue #53, where DROP TABLE needs a CASCADE due to the foreign key constraint. It seems to work - rake db:setup now succeeds instead of erring out that "other objects depend on it" - but it's my first time monkeying about with ActiveRecord, so I'd appreciate if you took a peek before merging.

@matthuhiggins

The "options = {}" part of drop_table is removed in Rails master, so I took your code and made it always add cascade without considering the options.

Thanks!

@matthuhiggins

See a88d49a

@jaylevitt

Cool! I wasn't sure if it would be OK to do the CASCADE when force wasn't set (though I can't think of why it should do cause any problems), so I was just being conservative. You actually know SQL, which gives you a leg up on these things ☺ Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 2, 2011
  1. @jaylevitt
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/foreigner/connection_adapters/sql2003.rb
View
10 lib/foreigner/connection_adapters/sql2003.rb
@@ -39,6 +39,16 @@ def remove_foreign_key_sql(table, options)
"DROP CONSTRAINT #{quote_column_name(foreign_key_name)}"
end
+
+ def drop_table(table_name, options = {})
+ sql = "DROP TABLE #{quote_table_name(table_name)}"
+ if options[:force]
+ execute "#{sql} CASCADE"
+ else
+ execute sql
+ end
+ end
+
private
def foreign_key_name(table, column, options = {})
Something went wrong with that request. Please try again.