Merge pull request #52 from greg-barnett/database_cleaner

---

The first commit works, for versions of postgresql up to 9.*

The second should work for any and all future versions of postgresql, as long as the implementation of postgresql_version in ActiveRecord doesnt change...
This commit is contained in:
Ben Mabey 2011-03-16 21:51:01 -06:00
commit fb01b5fb67

View file

@ -60,18 +60,15 @@ module ActiveRecord
class PostgreSQLAdapter < AbstractAdapter class PostgreSQLAdapter < AbstractAdapter
def db_version def db_version
@db_version ||= select_values( @db_version ||= postgresql_version
"SELECT CHARACTER_VALUE
FROM INFORMATION_SCHEMA.SQL_IMPLEMENTATION_INFO
WHERE IMPLEMENTATION_INFO_NAME = 'DBMS VERSION' ").join.to_s
end end
def cascade def cascade
@cascade ||= db_version >= "08.02" ? "CASCADE" : "" @cascade ||= db_version >= 80200 ? 'CASCADE' : ''
end end
def restart_identity def restart_identity
@restart_identity ||= db_version >= "08.04" ? "RESTART IDENTITY" : "" @restart_identity ||= db_version >= 80400 ? 'RESTART IDENTITY' : ''
end end
def truncate_table(table_name) def truncate_table(table_name)