declare_schema 1.4.0.colin.1 → 1.4.0.colin.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe0a594fea50536d529c2d4e42280d9050726e1017524dbaff2b8a77e17c6b41
4
- data.tar.gz: 89199ba5b58b936f93a7bfe0409c403b95da8bd771b425b2c61a6afd8a951f2a
3
+ metadata.gz: 33160a248adef9ac404a1efa4f6446fedabc2ddc49b02f0434ff3e1a91bfa8b2
4
+ data.tar.gz: ff9b214dfb3d31904927c906f244312571967de575ffcdadd4f100558bc3ffe4
5
5
  SHA512:
6
- metadata.gz: ff4858ac26953e22a9dbf37ce5b2391295d05ec5a8401361434987e6e90c7fc01543f2bbb1cebaf91a0ce16dadb8ac5c8600d01130c81f361c3728bcd7c23f9b
7
- data.tar.gz: 1fabf741327417f5beb76ba694de17e0176db5f63e95922a03d195eb4dcff60d71434cd6aeb4e8ff8212bc0b1fc7cc5a8cb400307efeb87a83593887621d366b
6
+ metadata.gz: aae64d3b2dff696f0ac532831df033fd0433e41eca6018c74eb07088ea2d0384e30bdae0c6648087ed15e367094558ec040b05f2869d7d28009f3396c343147a
7
+ data.tar.gz: 776c0b887fcbb9566b9b3347e8359c5ddd7b40020816ce18494ad6897eee5bc9b0e827167ae9ba759b3dcec4cd3244ea62c9a79e1f351e266a319339ca2534d7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.4.0.colin.1)
4
+ declare_schema (1.4.0.colin.2)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -51,9 +51,9 @@ module DeclareSchema
51
51
  module ClassMethods
52
52
  def index(fields, **options)
53
53
  # make index idempotent
54
- index_fields_s = Array.wrap(fields).map(&:to_s)
55
- unless index_definitions.any? { |index_spec| index_spec.fields == index_fields_s }
56
- index_definitions << ::DeclareSchema::Model::IndexDefinition.new(self, fields, **options)
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, limit: 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
- @limit = limit.presence
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[:limit] = @limit if @limit
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,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.4.0.colin.1"
4
+ VERSION = "1.4.0.colin.2"
5
5
  end
@@ -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, unique: i.unique, where: i.where, name: i.name)
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, unique: i.unique, where: i.where, name: i.name)
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 limit: nil' do
50
- let(:limit) { nil }
51
- subject { described_class.new(table_name, column_names, name: name, unique: unique, limit: limit) }
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 limit: 2' do
59
- let(:limit) { 2 }
60
- subject { described_class.new(table_name, column_names, name: name, unique: unique, limit: limit) }
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}, limit: #{limit}\n")
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 limit: hash' do
68
- let(:limit) { { last_name: 10, first_name: 1 } }
69
- subject { described_class.new(table_name, column_names, name: name, unique: unique, limit: limit) }
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}, limit: { last_name: 10, first_name: 1 }\n")
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.1
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-12 00:00:00.000000000 Z
11
+ date: 2024-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails