Skip to content

Commit

Permalink
fix schema migration
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Jul 19, 2024
1 parent 29d0079 commit f2dbed0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def with_yaml_fallback(value) # :nodoc:
def request(sql, format = nil, settings = {})
formatted_sql = apply_format(sql, format)
request_params = @connection_config || {}
@connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
@connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, {
'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}",
'Content-Type' => 'application/x-www-form-urlencoded',
})
end

def apply_format(sql, format)
Expand Down
2 changes: 1 addition & 1 deletion lib/clickhouse-activerecord/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ClickhouseActiverecord
VERSION = '1.0.10'
VERSION = '1.0.11'
end
10 changes: 8 additions & 2 deletions lib/core_extensions/active_record/schema_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ def delete_version(version)
connection.insert(im, "#{self.class} Create Rollback Version", primary_key, version)
end

def all_versions
def versions
return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)

final.where(active: 1).order(:version).pluck(:version)
sm = ::Arel::SelectManager.new(arel_table)
sm.final!
sm.project(arel_table[primary_key])
sm.order(arel_table[primary_key].asc)
sm.where([arel_table['active'].eq(1)])

connection.select_values(sm, "#{self.class} Load")
end
end
end
Expand Down

0 comments on commit f2dbed0

Please sign in to comment.