Skip to content

Commit

Permalink
Adding truncate_table to ActiveRecord::ConnectionAdapters::AbstractAd…
Browse files Browse the repository at this point in the history
…apter and using "DELETE FROM". Overriding truncate_table in the MysqlAdapter to use "TRUNCATE TABLE" instead.

I HAVE NOT TESTED THIS ON ANYTHING BUT MYSQL YET.
  • Loading branch information
Brandon Arbini committed Jan 6, 2009
1 parent eddadc2 commit e5bf675
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion init.rb
@@ -1 +1 @@
require File.dirname(__FILE__) + '/lib/bootstrapper.rb'
Dir.glob(File.dirname(__FILE__) + '/lib/**/*.rb').each {|f| require f }
2 changes: 1 addition & 1 deletion lib/bootstrapper.rb
Expand Up @@ -14,7 +14,7 @@ def self.run(key)

def self.truncate_tables(*tables)
tables.each do |table|
sql("delete from #{table}")
ActiveRecord::Base.connection.truncate_table(table)
end
end

Expand Down
15 changes: 15 additions & 0 deletions lib/connection_adapters/abstract_adapter.rb
@@ -0,0 +1,15 @@
module ActiveRecord

module ConnectionAdapters

class AbstractAdapter

def truncate_table(table_name)
execute "DELETE FROM #{table_name}"
end

end

end

end
15 changes: 15 additions & 0 deletions lib/connection_adapters/mysql_adapter.rb
@@ -0,0 +1,15 @@
module ActiveRecord

module ConnectionAdapters

class MysqlAdapter

def truncate_table(table_name)
execute "TRUNCATE TABLE #{table_name}"
end

end

end

end

0 comments on commit e5bf675

Please sign in to comment.