Skip to content

Commit 3246ef2

Browse files
robertwahleraeden
authored andcommitted
fix for sqlite not supporting drop table cascade
1 parent a581a1d commit 3246ef2

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/rails_sql_views/connection_adapters/abstract/schema_statements.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def create_mapping_view(old_name, new_name, options = {})
5959
end
6060

6161
def drop_table_with_cascade(table_name, options = {})
62-
execute "DROP TABLE #{quote_table_name(table_name)} CASCADE"
62+
cmd = "DROP TABLE #{quote_table_name(table_name)}"
63+
cmd += " CASCADE" if supports_drop_table_cascade?
64+
execute cmd
6365
end
6466

6567
# Drop a view.

lib/rails_sql_views/connection_adapters/abstract_adapter.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ def self.included(base)
99
def supports_views?
1010
return false
1111
end
12+
13+
# Subclasses should override and return false if they don't support CASCADE
14+
def supports_drop_table_cascade?
15+
return true
16+
end
1217

1318
def disable_referential_integrity_with_views_excluded(&block)
1419
self.class.send(:alias_method, :original_tables_method, :tables)

lib/rails_sql_views/connection_adapters/sqlite_adapter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ module SQLiteAdapter
44
def supports_views?
55
true
66
end
7+
8+
def supports_drop_table_cascade?
9+
return false
10+
end
711

812
def tables(name = nil) #:nodoc:
913
sql = <<-SQL

0 commit comments

Comments
 (0)