checks PostgreSQL version- when >= 8.2 only use TRUNCATE CASCADE

This commit is contained in:
James B. Byrne 2010-03-21 11:15:46 -06:00 committed by Ben Mabey
parent f6ee1fc0bf
commit 41a3ea7be5
2 changed files with 18 additions and 2 deletions

View file

@ -3,6 +3,9 @@
=== New features
* 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
=== New features

View file

@ -26,9 +26,22 @@ module ActiveRecord
end
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
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
class SQLServerAdapter