Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore multi-line table definitions in structure dumps #187

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading