clickhouse-activerecord 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/clickhouse/schema_definitions.rb +6 -0
- data/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +4 -1
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +5 -1
- data/lib/clickhouse-activerecord/schema_dumper.rb +2 -1
- data/lib/clickhouse-activerecord/version.rb +1 -1
- data/lib/core_extensions/active_record/schema_migration.rb +8 -2
- data/lib/tasks/clickhouse.rake +2 -4
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 48c4995d403717ca5d9b4d8bdadbedd4bae8d42cf7dad7f37768d12922ebb032
         | 
| 4 | 
            +
              data.tar.gz: 01cc522bc62fc1015e66b9239b11bf0e5cf4fa9bc998375e0021130737cacaf3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8ee641fb865778a883b93d56a834ab4c842e3f0531a60c3e6a10278a558b9eddc14a101a2dd96688c983090d5dabfb1d3040f78ff09946facc7f7709cbd81dec
         | 
| 7 | 
            +
              data.tar.gz: 147bcb2f4c7af96e9d68532de7f0c16f4fda78ac31c63735d12f7f7e04597869d827c7fd58cf72e8adc9750395d12442d6becbcc2d9e534e9819e6eef839f20a
         | 
| @@ -93,6 +93,12 @@ module ActiveRecord | |
| 93 93 |  | 
| 94 94 | 
             
                      args.each { |name| column(name, kind, **options.except(:limit)) }
         | 
| 95 95 | 
             
                    end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                    private
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                    def valid_column_definition_options
         | 
| 100 | 
            +
                      super + [:array, :low_cardinality, :fixed_string, :value, :type]
         | 
| 101 | 
            +
                    end
         | 
| 96 102 | 
             
                  end
         | 
| 97 103 |  | 
| 98 104 | 
             
                  class IndexDefinition
         | 
| @@ -143,7 +143,10 @@ module ActiveRecord | |
| 143 143 | 
             
                    def request(sql, format = nil, settings = {})
         | 
| 144 144 | 
             
                      formatted_sql = apply_format(sql, format)
         | 
| 145 145 | 
             
                      request_params = @connection_config || {}
         | 
| 146 | 
            -
                      @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql,  | 
| 146 | 
            +
                      @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, {
         | 
| 147 | 
            +
                        'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}",
         | 
| 148 | 
            +
                        'Content-Type' => 'application/x-www-form-urlencoded',
         | 
| 149 | 
            +
                      })
         | 
| 147 150 | 
             
                    end
         | 
| 148 151 |  | 
| 149 152 | 
             
                    def apply_format(sql, format)
         | 
| @@ -293,7 +293,11 @@ module ActiveRecord | |
| 293 293 | 
             
                    options = apply_replica(table_name, options)
         | 
| 294 294 | 
             
                    td = create_table_definition(apply_cluster(table_name), **options)
         | 
| 295 295 | 
             
                    block.call td if block_given?
         | 
| 296 | 
            -
                     | 
| 296 | 
            +
                    # support old migration version: in 5.0 options id: :integer, but 7.1 options empty
         | 
| 297 | 
            +
                    # todo remove auto add id column in future
         | 
| 298 | 
            +
                    if (!options.key?(:id) || options[:id].present? && options[:id] != false) && td[:id].blank? && options[:as].blank?
         | 
| 299 | 
            +
                      td.column(:id, options[:id] || :integer, null: false)
         | 
| 300 | 
            +
                    end
         | 
| 297 301 |  | 
| 298 302 | 
             
                    if options[:force]
         | 
| 299 303 | 
             
                      drop_table(table_name, options.merge(if_exists: true))
         | 
| @@ -104,7 +104,8 @@ HEADER | |
| 104 104 | 
             
                          raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
         | 
| 105 105 | 
             
                          next if column.name == pk
         | 
| 106 106 | 
             
                          type, colspec = column_spec(column)
         | 
| 107 | 
            -
                           | 
| 107 | 
            +
                          name = column.name =~ (/\./) ? "\"`#{column.name}`\"" : column.name.inspect
         | 
| 108 | 
            +
                          tbl.print "    t.#{type} #{name}"
         | 
| 108 109 | 
             
                          tbl.print ", #{format_colspec(colspec)}" if colspec.present?
         | 
| 109 110 | 
             
                          tbl.puts
         | 
| 110 111 | 
             
                        end
         | 
| @@ -36,10 +36,16 @@ module CoreExtensions | |
| 36 36 | 
             
                    connection.insert(im, "#{self.class} Create Rollback Version", primary_key, version)
         | 
| 37 37 | 
             
                  end
         | 
| 38 38 |  | 
| 39 | 
            -
                  def  | 
| 39 | 
            +
                  def versions
         | 
| 40 40 | 
             
                    return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
         | 
| 41 41 |  | 
| 42 | 
            -
                     | 
| 42 | 
            +
                    sm = ::Arel::SelectManager.new(arel_table)
         | 
| 43 | 
            +
                    sm.final!
         | 
| 44 | 
            +
                    sm.project(arel_table[primary_key])
         | 
| 45 | 
            +
                    sm.order(arel_table[primary_key].asc)
         | 
| 46 | 
            +
                    sm.where([arel_table['active'].eq(1)])
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    connection.select_values(sm, "#{self.class} Load")
         | 
| 43 49 | 
             
                  end
         | 
| 44 50 | 
             
                end
         | 
| 45 51 | 
             
              end
         | 
    
        data/lib/tasks/clickhouse.rake
    CHANGED
    
    | @@ -37,6 +37,8 @@ namespace :clickhouse do | |
| 37 37 | 
             
              end
         | 
| 38 38 |  | 
| 39 39 | 
             
              namespace :structure do
         | 
| 40 | 
            +
                config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
         | 
| 41 | 
            +
             | 
| 40 42 | 
             
                desc 'Load database structure'
         | 
| 41 43 | 
             
                task load: ['db:check_protected_environments'] do
         | 
| 42 44 | 
             
                  ClickhouseActiverecord::Tasks.new(config).structure_load(Rails.root.join('db/clickhouse_structure.sql'))
         | 
| @@ -85,8 +87,4 @@ namespace :clickhouse do | |
| 85 87 | 
             
                  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
         | 
| 86 88 | 
             
                end
         | 
| 87 89 | 
             
              end
         | 
| 88 | 
            -
             | 
| 89 | 
            -
              def config
         | 
| 90 | 
            -
                ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
         | 
| 91 | 
            -
              end
         | 
| 92 90 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: clickhouse-activerecord
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.11
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sergey Odintsov
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024- | 
| 11 | 
            +
            date: 2024-07-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |