What Changed?
I added
#build_truncate_statements- Update the functionality to filter out engines that cannot be truncated- Added unit test to ensure functionality
- Added
clickhouse/minitest.rbas a helper similar toclickhouse/rspec.rb
Motivation
In our production app we're using database_cleaner to do the truncation and taking advantage of it's except functionality (DatabaseCleaner.strategy = [:truncation, except: %w[widgets]]) to filter out specific tables. I'm hoping to remove our dependency on database_cleaner and allow clickhouse-activerecord to manage the truncation.
The pattern used here follows the ActiveRecord implementation. We currently rely on the abstract implementation for #truncate and #truncate_tables - active_record/connection_adapters/abstract/database_statements.rb.
Postgres and Sqlite use this same pattern to adjust their truncation methods
postgresql/database_statements.rb- Overridesbuild_truncate_statementsto truncate all tables in a single statementsqlite3/database_statements.rb- Overridesbuild_truncate_statementto useDELETE FROMsince SQLite doesn't supportTRUNCATE