declare_schema 1.4.0.colin.1 → 1.4.0.colin.2
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/Gemfile.lock +1 -1
- data/lib/declare_schema/model.rb +6 -6
- data/lib/declare_schema/schema_change/index_add.rb +3 -3
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +2 -2
- data/spec/lib/declare_schema/schema_change/index_add_spec.rb +11 -11
- 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: 33160a248adef9ac404a1efa4f6446fedabc2ddc49b02f0434ff3e1a91bfa8b2
         | 
| 4 | 
            +
              data.tar.gz: ff9b214dfb3d31904927c906f244312571967de575ffcdadd4f100558bc3ffe4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: aae64d3b2dff696f0ac532831df033fd0433e41eca6018c74eb07088ea2d0384e30bdae0c6648087ed15e367094558ec040b05f2869d7d28009f3396c343147a
         | 
| 7 | 
            +
              data.tar.gz: 776c0b887fcbb9566b9b3347e8359c5ddd7b40020816ce18494ad6897eee5bc9b0e827167ae9ba759b3dcec4cd3244ea62c9a79e1f351e266a319339ca2534d7
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/declare_schema/model.rb
    CHANGED
    
    | @@ -51,9 +51,9 @@ module DeclareSchema | |
| 51 51 | 
             
                module ClassMethods
         | 
| 52 52 | 
             
                  def index(fields, **options)
         | 
| 53 53 | 
             
                    # make index idempotent
         | 
| 54 | 
            -
                     | 
| 55 | 
            -
                    unless index_definitions.any? { |index_spec| index_spec. | 
| 56 | 
            -
                      index_definitions <<  | 
| 54 | 
            +
                    index = ::DeclareSchema::Model::IndexDefinition.new(self, fields, **options)
         | 
| 55 | 
            +
                    unless index_definitions.any? { |index_spec| index_spec.equivalent?(index) }
         | 
| 56 | 
            +
                      index_definitions << index
         | 
| 57 57 | 
             
                    end
         | 
| 58 58 | 
             
                  end
         | 
| 59 59 |  | 
| @@ -122,7 +122,7 @@ module DeclareSchema | |
| 122 122 | 
             
                      index_options = {}
         | 
| 123 123 | 
             
                      case index_value
         | 
| 124 124 | 
             
                      when String
         | 
| 125 | 
            -
                        Kernel.warn("belongs_to index: 'name' is deprecated; use index: { name: 'name' } instead")
         | 
| 125 | 
            +
                        Kernel.warn("belongs_to index: 'name' is deprecated; use index: { name: 'name' } instead (in #{self.class.name})")
         | 
| 126 126 | 
             
                        index_options[:name] = index_value
         | 
| 127 127 | 
             
                      # when false -- impossible since we checked that above
         | 
| 128 128 | 
             
                      when true
         | 
| @@ -134,7 +134,7 @@ module DeclareSchema | |
| 134 134 | 
             
                      end
         | 
| 135 135 |  | 
| 136 136 | 
             
                      if options.has_key?(:unique)
         | 
| 137 | 
            -
                        Kernel.warn("belongs_to unique: true|false is deprecated; use index: { unique: true|false } instead")
         | 
| 137 | 
            +
                        Kernel.warn("belongs_to unique: true|false is deprecated; use index: { unique: true|false } instead (in #{self.class.name})")
         | 
| 138 138 | 
             
                        index_options[:unique] = options.delete(:unique)
         | 
| 139 139 | 
             
                      end
         | 
| 140 140 |  | 
| @@ -305,7 +305,7 @@ module DeclareSchema | |
| 305 305 | 
             
                    if (to_name = options.delete(:index))
         | 
| 306 306 | 
             
                      index_opts =
         | 
| 307 307 | 
             
                        {
         | 
| 308 | 
            -
                          unique: args.include?(:unique) || options.delete(:unique)
         | 
| 308 | 
            +
                          unique: args.include?(:unique) || !!options.delete(:unique)
         | 
| 309 309 | 
             
                        }
         | 
| 310 310 | 
             
                      # support index: true declaration
         | 
| 311 311 | 
             
                      index_opts[:name] = to_name unless to_name == true
         | 
| @@ -5,13 +5,13 @@ require_relative 'base' | |
| 5 5 | 
             
            module DeclareSchema
         | 
| 6 6 | 
             
              module SchemaChange
         | 
| 7 7 | 
             
                class IndexAdd < Base
         | 
| 8 | 
            -
                  def initialize(table_name, column_names, name:, unique:, where: nil,  | 
| 8 | 
            +
                  def initialize(table_name, column_names, name:, unique:, where: nil, length: nil)
         | 
| 9 9 | 
             
                    @table_name = table_name
         | 
| 10 10 | 
             
                    @column_names = column_names
         | 
| 11 11 | 
             
                    @name = name
         | 
| 12 12 | 
             
                    @unique = unique
         | 
| 13 13 | 
             
                    @where = where.presence
         | 
| 14 | 
            -
                    @ | 
| 14 | 
            +
                    @length = length
         | 
| 15 15 | 
             
                  end
         | 
| 16 16 |  | 
| 17 17 | 
             
                  def up_command
         | 
| @@ -20,7 +20,7 @@ module DeclareSchema | |
| 20 20 | 
             
                    }
         | 
| 21 21 | 
             
                    options[:unique] = true if @unique
         | 
| 22 22 | 
             
                    options[:where] = @where if @where
         | 
| 23 | 
            -
                    options[: | 
| 23 | 
            +
                    options[:length] = @length if @length
         | 
| 24 24 |  | 
| 25 25 | 
             
                    "add_index #{[@table_name.to_sym.inspect,
         | 
| 26 26 | 
             
                                  @column_names.map(&:to_sym).inspect,
         | 
| @@ -457,11 +457,11 @@ module Generators | |
| 457 457 | 
             
                      renamed_indexes_to_drop, renamed_indexes_to_add = index_changes_due_to_column_renames(indexes_to_drop, indexes_to_add, to_rename)
         | 
| 458 458 |  | 
| 459 459 | 
             
                      drop_indexes = (indexes_to_drop - renamed_indexes_to_drop).map do |i|
         | 
| 460 | 
            -
                        ::DeclareSchema::SchemaChange::IndexRemove.new(new_table_name, i.columns,  | 
| 460 | 
            +
                        ::DeclareSchema::SchemaChange::IndexRemove.new(new_table_name, i.columns, **i.options)
         | 
| 461 461 | 
             
                      end
         | 
| 462 462 |  | 
| 463 463 | 
             
                      add_indexes = (indexes_to_add - renamed_indexes_to_add).map do |i|
         | 
| 464 | 
            -
                        ::DeclareSchema::SchemaChange::IndexAdd.new(new_table_name, i.columns,  | 
| 464 | 
            +
                        ::DeclareSchema::SchemaChange::IndexAdd.new(new_table_name, i.columns, **i.options)
         | 
| 465 465 | 
             
                      end
         | 
| 466 466 |  | 
| 467 467 | 
             
                      # the order is important here - adding a :unique, for instance needs to remove then add
         | 
| @@ -46,30 +46,30 @@ RSpec.describe DeclareSchema::SchemaChange::IndexAdd do | |
| 46 46 | 
             
                    end
         | 
| 47 47 | 
             
                  end
         | 
| 48 48 |  | 
| 49 | 
            -
                  context 'with  | 
| 50 | 
            -
                    let(: | 
| 51 | 
            -
                    subject { described_class.new(table_name, column_names, name: name, unique: unique,  | 
| 49 | 
            +
                  context 'with length: nil' do
         | 
| 50 | 
            +
                    let(:length) { nil }
         | 
| 51 | 
            +
                    subject { described_class.new(table_name, column_names, name: name, unique: unique, length: length) }
         | 
| 52 52 |  | 
| 53 53 | 
             
                    it 'responds with command' do
         | 
| 54 54 | 
             
                      expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect}\n")
         | 
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 |  | 
| 58 | 
            -
                  context 'with  | 
| 59 | 
            -
                    let(: | 
| 60 | 
            -
                    subject { described_class.new(table_name, column_names, name: name, unique: unique,  | 
| 58 | 
            +
                  context 'with length: 2' do
         | 
| 59 | 
            +
                    let(:length) { 2 }
         | 
| 60 | 
            +
                    subject { described_class.new(table_name, column_names, name: name, unique: unique, length: length) }
         | 
| 61 61 |  | 
| 62 62 | 
             
                    it 'responds with command' do
         | 
| 63 | 
            -
                      expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect},  | 
| 63 | 
            +
                      expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect}, length: #{length}\n")
         | 
| 64 64 | 
             
                    end
         | 
| 65 65 | 
             
                  end
         | 
| 66 66 |  | 
| 67 | 
            -
                  context 'with  | 
| 68 | 
            -
                    let(: | 
| 69 | 
            -
                    subject { described_class.new(table_name, column_names, name: name, unique: unique,  | 
| 67 | 
            +
                  context 'with length: hash' do
         | 
| 68 | 
            +
                    let(:length) { { last_name: 10, first_name: 1 } }
         | 
| 69 | 
            +
                    subject { described_class.new(table_name, column_names, name: name, unique: unique, length: length) }
         | 
| 70 70 |  | 
| 71 71 | 
             
                    it 'responds with command' do
         | 
| 72 | 
            -
                      expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect},  | 
| 72 | 
            +
                      expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect}, length: { last_name: 10, first_name: 1 }\n")
         | 
| 73 73 | 
             
                    end
         | 
| 74 74 | 
             
                  end
         | 
| 75 75 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: declare_schema
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.4.0.colin. | 
| 4 | 
            +
              version: 1.4.0.colin.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Invoca Development adapted from hobo_fields by Tom Locke
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-01- | 
| 11 | 
            +
            date: 2024-01-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |