Sha256: 8afa23fc068bbd4da56a62d9cd35b383cd47e0f5e3a09f519620b11bdf0ddbf6

Contents?: true

Size: 854 Bytes

Versions: 51

Compression:

Stored size: 854 Bytes

Contents

# frozen_string_literal: true

require_relative 'base'

module DeclareSchema
  module SchemaChange
    class IndexAdd < Base
      def initialize(table_name, column_names, name:, unique:, where: nil)
        @table_name = table_name
        @column_names = column_names
        @name = name
        @unique = unique
        @where = where.presence
      end

      def up_command
        options = {
          name: @name.to_sym,
        }
        options[:unique] = true if @unique
        options[:where] = @where if @where

        "add_index #{[@table_name.to_sym.inspect,
                      @column_names.map(&:to_sym).inspect,
                      *self.class.format_options(options)].join(', ')}"
      end

      def down_command
        "remove_index #{@table_name.to_sym.inspect}, name: #{@name.to_sym.inspect}"
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
declare_schema-1.3.6 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.6.colin.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.5 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.5.colin.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.4 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.4.colin.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.3 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.3.colin.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.2 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.2.rp.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.1.colin.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.0 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.3.0.colin.1 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.2.3 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.2.3.pre.ga.11 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.2.3.pre.ga.10 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.2.3.pre.ga.9 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.2.3.pre.ga.8 lib/declare_schema/schema_change/index_add.rb
declare_schema-1.2.3.pre.ga.7 lib/declare_schema/schema_change/index_add.rb