From a7ad1cf141a5c26910928ed3d8f962f4dee2b516 Mon Sep 17 00:00:00 2001 From: Ryan Kerr Date: Mon, 9 Dec 2024 19:00:42 -0500 Subject: [PATCH] Do not squish table definitions in schema dump. Refactoring commit (535ca30d) that altered :structure_dump to use :show_create_table made table definitions in structure.sql single-line. This restores line breaks in structure.sql. --- lib/active_record/connection_adapters/clickhouse_adapter.rb | 6 ++++-- lib/clickhouse-activerecord/tasks.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/active_record/connection_adapters/clickhouse_adapter.rb b/lib/active_record/connection_adapters/clickhouse_adapter.rb index fb73993..d59f646 100644 --- a/lib/active_record/connection_adapters/clickhouse_adapter.rb +++ b/lib/active_record/connection_adapters/clickhouse_adapter.rb @@ -300,9 +300,11 @@ def create_schema_dumper(options) # :nodoc: end # @param [String] table + # @option [Boolean] single_line # @return [String] - def show_create_table(table) - do_system_execute("SHOW CREATE TABLE `#{table}`")['data'].try(:first).try(:first).gsub(/[\n\s]+/m, ' ').gsub("#{@config[:database]}.", "") + def show_create_table(table, single_line: true) + sql = do_system_execute("SHOW CREATE TABLE `#{table}`")['data'].try(:first).try(:first) + single_line ? sql.squish : sql end # Create a new ClickHouse database. diff --git a/lib/clickhouse-activerecord/tasks.rb b/lib/clickhouse-activerecord/tasks.rb index 7440a17..a4a8a85 100644 --- a/lib/clickhouse-activerecord/tasks.rb +++ b/lib/clickhouse-activerecord/tasks.rb @@ -40,7 +40,7 @@ def structure_dump(*args) # get all tables tables = connection.execute("SHOW TABLES FROM #{@configuration.database} WHERE name NOT LIKE '.inner_id.%'")['data'].flatten.map do |table| next if %w[schema_migrations ar_internal_metadata].include?(table) - connection.show_create_table(table).gsub("#{@configuration.database}.", '') + connection.show_create_table(table, single_line: false).gsub("#{@configuration.database}.", '') end.compact # sort view to last