Sha256: 1084b52960aeb1e2e72a7c52fd48ed1637e4fea444b44f2e9c78619f59249434

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require 'active_record/connection_adapters/mysql/schema_creation'

module Ridgepole
  module Ext
    module AbstractMysqlAdapter
      module SchemaCreation
        def visit_PartitionOptions(o)
          sqls = o.partition_definitions.map { |partition_definition| accept partition_definition }
          function = case o.type
                     when :list
                       "LIST COLUMNS(#{o.columns.map { |column| quote_column_name(column) }.join(',')})"
                     when :range
                       "RANGE COLUMNS(#{o.columns.map { |column| quote_column_name(column) }.join(',')})"
                     else
                       raise NotImplementedError
                     end
          "ALTER TABLE #{quote_table_name(o.table)} PARTITION BY #{function} (#{sqls.join(',')})"
        end

        def visit_PartitionDefinition(o)
          if o.values.key?(:in)
            "PARTITION #{o.name} VALUES IN (#{o.values[:in].map do |value|
              value.is_a?(Array) ? "(#{value.map(&:inspect).join(',')})" : value.inspect
            end.join(',')})"
          elsif o.values.key?(:to)
            "PARTITION #{o.name} VALUES LESS THAN (#{o.values[:to].map(&:inspect).join(',')})"
          else
            raise NotImplementedError
          end
        end
      end
    end
  end
end

module ActiveRecord
  module ConnectionAdapters
    module MySQL
      class SchemaCreation
        prepend Ridgepole::Ext::AbstractMysqlAdapter::SchemaCreation
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ridgepole-1.0.7 lib/ridgepole/ext/abstract_mysql_adapter/schema_creation.rb
ridgepole-1.0.6 lib/ridgepole/ext/abstract_mysql_adapter/schema_creation.rb
ridgepole-1.0.5 lib/ridgepole/ext/abstract_mysql_adapter/schema_creation.rb
ridgepole-1.0.4 lib/ridgepole/ext/abstract_mysql_adapter/schema_creation.rb
ridgepole-1.0.3 lib/ridgepole/ext/abstract_mysql_adapter/schema_creation.rb
ridgepole-1.0.2 lib/ridgepole/ext/abstract_mysql_adapter/schema_creation.rb
ridgepole-1.0.2.beta lib/ridgepole/ext/abstract_mysql_adapter/schema_creation.rb