Skip to content

Commit

Permalink
Do not squish table definitions in schema dump.
Browse files Browse the repository at this point in the history
Refactoring commit (535ca30) that altered :structure_dump to use :show_create_table made table definitions in structure.sql single-line. This restores line breaks in structure.sql.
  • Loading branch information
leboshi committed Dec 10, 2024
1 parent 496f04b commit a7ad1cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/active_record/connection_adapters/clickhouse_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/clickhouse-activerecord/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7ad1cf

Please sign in to comment.