declare_schema 1.4.0.colin.6 → 1.4.0.colin.7

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: 1bdf7e72cc4b08040aaaa9036e520edf7c2be76a0a2466fc08215c8d222ec966
4
- data.tar.gz: 63a8e595acec695a3a88ead0daeb46e871353645747ec2c03e6175d7d7c35161
3
+ metadata.gz: 0f8226540260a887af839da5afcb4641217c03ac5a6eb2d7a00da2806188f1ce
4
+ data.tar.gz: 7eeb464b5bfc9b1fbf88446696ede88b8ea582060658421cf2772e62a6205797
5
5
  SHA512:
6
- metadata.gz: eca71720644bbf4783dc90bab55604b154f2feb6ab5e05c72822675c9dc2993368041074f2f3a719188298577820e460ec44815a3b7a3ee19b46f00f5448e19d
7
- data.tar.gz: 35851323ffd8cd93b0f634d03f3164a83087cee588a45da74f4499e5ebd1d48dcea50fb21dfe42eb2ed807ce3cf307a40de79b4f5a8fbb99c0017268d20932d6
6
+ metadata.gz: 2294e94f2165ec156807fbf9ba98dea10f191bfda1b4c630f5444ab08ee7f80323e86a9af80e968e20e579e21ba24ddef520312a7f0a146d850b6f8927aa50aa
7
+ data.tar.gz: 2742ce98af1fb6ef8eb4ba1fa40563a635abb584cc1860efd373a474c6dce9fc1a27b630141f94ea6a23f36602d8381b08d6a33b13b6fd3d352b40df85f37daf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.4.0.colin.6)
4
+ declare_schema (1.4.0.colin.7)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -57,11 +57,8 @@ module DeclareSchema
57
57
  index(fields.flatten, unique: true, name: ::DeclareSchema::Model::IndexDefinition::PRIMARY_KEY_NAME)
58
58
  end
59
59
 
60
- def constraint(fkey, **options)
61
- fkey_s = fkey.to_s
62
- unless constraint_specs.any? { |constraint_spec| constraint_spec.foreign_key == fkey_s }
63
- constraint_specs << DeclareSchema::Model::ForeignKeyDefinition.new(self, fkey, **options)
64
- end
60
+ def constraint(foreign_key, **options)
61
+ constraint_specs << DeclareSchema::Model::ForeignKeyDefinition.new(self, foreign_key.to_s, **options)
65
62
  end
66
63
 
67
64
  # tell the migration generator to ignore the named index. Useful for existing indexes, or for indexes
@@ -152,9 +149,9 @@ module DeclareSchema
152
149
 
153
150
  super
154
151
 
155
- refl = reflections[name.to_s] or raise "Couldn't find reflection #{name} in #{reflections.keys}"
156
- fkey = refl.foreign_key or raise "Couldn't find foreign_key for #{name} in #{refl.inspect}"
157
- fkey_id_column_options = column_options.dup
152
+ reflection = reflections[name.to_s] or raise "Couldn't find reflection #{name} in #{reflections.keys}"
153
+ foreign_key = reflection.foreign_key or raise "Couldn't find foreign_key for #{name} in #{reflection.inspect}"
154
+ foreign_key_id_column_options = column_options.dup
158
155
 
159
156
  # Note: the foreign key limit: should match the primary key limit:. (If there is a foreign key constraint,
160
157
  # those limits _must_ match.) We'd like to call _infer_fk_limit and get the limit right from the PK.
@@ -165,31 +162,31 @@ module DeclareSchema
165
162
  # The one downside of this approach is that application code that asks the field_spec for the declared
166
163
  # foreign key limit: will always get 8 back even if this is a grandfathered foreign key that points to
167
164
  # a limit: 4 primary key. It seems unlikely that any application code would do this.
168
- fkey_id_column_options[:pre_migration] = ->(field_spec) do
169
- if (inferred_limit = _infer_fk_limit(fkey, refl))
165
+ foreign_key_id_column_options[:pre_migration] = ->(field_spec) do
166
+ if (inferred_limit = _infer_fk_limit(foreign_key, reflection))
170
167
  field_spec.sql_options[:limit] = inferred_limit
171
168
  end
172
169
  end
173
170
 
174
- declare_field(fkey.to_sym, :bigint, **fkey_id_column_options)
171
+ declare_field(foreign_key.to_sym, :bigint, **foreign_key_id_column_options)
175
172
 
176
- if refl.options[:polymorphic]
173
+ if reflection.options[:polymorphic]
177
174
  foreign_type = options[:foreign_type] || "#{name}_type"
178
175
  _declare_polymorphic_type_field(foreign_type, column_options)
179
- index([foreign_type, fkey], **index_options) if index_options
176
+ index([foreign_type, foreign_key], **index_options) if index_options
180
177
  else
181
- index(fkey, **index_options) if index_options
182
- constraint(fkey, **fk_options) if fk_options[:constraint_name] != false
178
+ index(foreign_key, **index_options) if index_options
179
+ constraint(foreign_key, **fk_options) if fk_options[:constraint_name] != false
183
180
  end
184
181
  end
185
182
 
186
- def _infer_fk_limit(fkey, refl)
187
- if refl.options[:polymorphic]
188
- if (fkey_column = columns_hash[fkey.to_s]) && fkey_column.type == :integer
189
- fkey_column.limit
183
+ def _infer_fk_limit(foreign_key, reflection)
184
+ if reflection.options[:polymorphic]
185
+ if (foreign_key_column = columns_hash[foreign_key.to_s]) && foreign_key_column.type == :integer
186
+ foreign_key_column.limit
190
187
  end
191
188
  else
192
- klass = refl.klass or raise "Couldn't find belongs_to klass for #{name} in #{refl.inspect}"
189
+ klass = reflection.klass or raise "Couldn't find belongs_to klass for #{name} in #{reflection.inspect}"
193
190
  if (pk_id_type = klass._table_options&.[](:id))
194
191
  if pk_id_type == :integer
195
192
  4
@@ -320,11 +317,11 @@ module DeclareSchema
320
317
  end
321
318
 
322
319
  attr_types[name] ||
323
- if (refl = reflections[name.to_s])
324
- if refl.macro.in?([:has_one, :belongs_to]) && !refl.options[:polymorphic]
325
- refl.klass
320
+ if (reflection = reflections[name.to_s])
321
+ if reflection.macro.in?([:has_one, :belongs_to]) && !reflection.options[:polymorphic]
322
+ reflection.klass
326
323
  else
327
- refl
324
+ reflection
328
325
  end
329
326
  end ||
330
327
  if (col = _column(name.to_s))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.4.0.colin.6"
4
+ VERSION = "1.4.0.colin.7"
5
5
  end
@@ -426,7 +426,7 @@ module Generators
426
426
 
427
427
  new_table_name = model.table_name
428
428
  existing_indexes = ::DeclareSchema::Model::IndexDefinition.for_model(model, old_table_name)
429
- model_indexes_with_equivalents = model.index_definitions_with_primary_key
429
+ model_indexes_with_equivalents = model.index_definitions_with_primary_key.to_a
430
430
  model_indexes = model_indexes_with_equivalents.map do |i|
431
431
  if i.explicit_name.nil?
432
432
  if (existing = existing_indexes.find { |e| i != e && e.equivalent?(i) })
@@ -486,7 +486,7 @@ module Generators
486
486
  ::DeclareSchema.default_generate_foreign_keys or return []
487
487
 
488
488
  existing_fks = ::DeclareSchema::Model::ForeignKeyDefinition.for_model(model, old_table_name)
489
- model_fks = model.constraint_specs
489
+ model_fks = model.constraint_specs.to_a
490
490
 
491
491
  fks_to_drop = existing_fks - model_fks
492
492
  fks_to_add = model_fks - existing_fks
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: declare_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.colin.6
4
+ version: 1.4.0.colin.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke