mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
checks PostgreSQL version- when >= 8.2 only use TRUNCATE CASCADE
This commit is contained in:
parent
f6ee1fc0bf
commit
41a3ea7be5
2 changed files with 18 additions and 2 deletions
|
@ -3,6 +3,9 @@
|
||||||
=== New features
|
=== New features
|
||||||
* clean and clean_with methods are now aliased to clean! and clean_with!. (Ben Mabey)
|
* clean and clean_with methods are now aliased to clean! and clean_with!. (Ben Mabey)
|
||||||
|
|
||||||
|
=== Bugfixes
|
||||||
|
* check PostgreSQL version >= 8.2 before using TRUNCATE CASCADE (James B. Byrne)
|
||||||
|
|
||||||
== 0.5.0 2010-02-22 - The CouchPotato Release
|
== 0.5.0 2010-02-22 - The CouchPotato Release
|
||||||
|
|
||||||
=== New features
|
=== New features
|
||||||
|
|
|
@ -26,9 +26,22 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
class PostgreSQLAdapter
|
class PostgreSQLAdapter
|
||||||
def truncate_table(table_name)
|
|
||||||
execute("TRUNCATE TABLE #{quote_table_name(table_name)} CASCADE;")
|
def self.db_version
|
||||||
|
@db_version ||= ActiveRecord::Base.connection.select_values(
|
||||||
|
"SELECT CHARACTER_VALUE
|
||||||
|
FROM INFORMATION_SCHEMA.SQL_IMPLEMENTATION_INFO
|
||||||
|
WHERE IMPLEMENTATION_INFO_NAME = 'DBMS VERSION' ").to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.cascade
|
||||||
|
@cascade ||= db_version >= "08.02" ? "CASCADE" : ""
|
||||||
|
end
|
||||||
|
|
||||||
|
def truncate_table(table_name)
|
||||||
|
execute("TRUNCATE TABLE #{quote_table_name(table_name)} #{self.class.cascade};")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class SQLServerAdapter
|
class SQLServerAdapter
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue