diff options
Diffstat (limited to 'spec/support/database/click_house/hooks.rb')
-rw-r--r-- | spec/support/database/click_house/hooks.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/spec/support/database/click_house/hooks.rb b/spec/support/database/click_house/hooks.rb index 27abd19dc3f..b970d3daf84 100644 --- a/spec/support/database/click_house/hooks.rb +++ b/spec/support/database/click_house/hooks.rb @@ -4,7 +4,13 @@ class ClickHouseTestRunner def truncate_tables ClickHouse::Client.configuration.databases.each_key do |db| - tables_for(db).each do |table| + # Select tables with at least one row + query = tables_for(db).map do |table| + "(SELECT '#{table}' AS table FROM #{table} LIMIT 1)" + end.join(' UNION ALL ') + + tables_with_data = ClickHouse::Client.select(query, db).pluck('table') + tables_with_data.each do |table| ClickHouse::Client.execute("TRUNCATE TABLE #{table}", db) end end |