declare_schema 1.2.3.pre.ga.4 → 1.2.3.pre.ga.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 506475213508a2b48038ccb1e8d2b4398b03879d88a7760803ffbc9273463033
4
- data.tar.gz: 6fac90c4db4626a52d98c71ad98c6f8615e8f041473874575f9b3ba2e2123589
3
+ metadata.gz: aacc7a857e82fc857a7694a7c32afe7b9bee2a8949dd455f6506eac066658353
4
+ data.tar.gz: 513a4171b54d053b3e9cc58111256010040634e287cf2d7f1a33b278cad92548
5
5
  SHA512:
6
- metadata.gz: 9d9eda18aaa034a6b78239e76e2416b1a0f26a4094268b9a9fb1b4f807108a557d7163d7e623568cb3a6bf1bc4d5dee1d84068d7b391e5cc399b81de095aad6e
7
- data.tar.gz: 36c6b8f67da4ece257360b4bded0dc79b08e9e31a3f9a3ba0745016ebd481ad76c13e7f8fb549e1d923c9e557056ceff10b60858bb0fa0743f61131af31f0a08
6
+ metadata.gz: b5075ebac4ebd80def763e46df74d506e3c2df43d4c0601e35fe335be7c3db8faf5b280fd4417dc54ff2f6608162de5ba69082af4353df6f3d7b0ff449b20486
7
+ data.tar.gz: 48534ddd177e9061390b26db9142842968cf28f2637f1cc7d091e28205ace5d55c0ddb0669c7b31b370d4d27d18e83ecc09d0c4b8451f79c4230ef0667c89d4f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.2.3.pre.ga.4)
4
+ declare_schema (1.2.3.pre.ga.5)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -12,7 +12,7 @@ module DeclareSchema
12
12
 
13
13
  def initialize(model, foreign_key, **options)
14
14
  @model = model
15
- @foreign_key = foreign_key.to_s.presence
15
+ @foreign_key = foreign_key.to_s.presence or raise ArgumentError "Foreign key cannot be empty: #{foreign_key.inspect}"
16
16
  @options = options
17
17
 
18
18
  @child_table_name = model.table_name # unless a table rename, which would happen when a class is renamed??
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.2.3.pre.ga.4"
4
+ VERSION = "1.2.3.pre.ga.5"
5
5
  end
@@ -469,23 +469,16 @@ module Generators
469
469
  end
470
470
 
471
471
  def index_changes_due_to_column_renames(indexes_to_drop, indexes_to_add, to_rename)
472
- renamed_indexes_to_drop = []
473
- renamed_indexes_to_add = []
474
-
475
- indexes_to_drop.each { |index_to_drop|
472
+ indexes_to_drop.each_with_object([], []) do |index_to_drop, (renamed_indexes_to_drop, renamed_indexes_to_add)|
476
473
  renamed_columns = index_to_drop.columns.map do |column|
477
474
  to_rename.fetch(column, column)
478
- end
475
+ end.sort
479
476
 
480
- indexes_to_add.each { |index_to_add|
481
- if Set.new(renamed_columns) == Set.new(index_to_add.columns)
482
- renamed_indexes_to_drop.append(index_to_drop)
483
- renamed_indexes_to_add.append(index_to_add)
484
- end
485
- }
486
- }
487
-
488
- [renamed_indexes_to_drop, renamed_indexes_to_add]
477
+ if (index_to_add = indexes_to_add.find { |index_to_add| renamed_columns == index_to_add.columns.sort })
478
+ renamed_indexes_to_drop << index_to_drop
479
+ renamed_indexes_to_add << index_to_add
480
+ end
481
+ end
489
482
  end
490
483
 
491
484
  def change_foreign_key_constraints(model, old_table_name, to_rename)
@@ -515,23 +508,18 @@ module Generators
515
508
  end
516
509
 
517
510
  def foreign_key_changes_due_to_column_renames(fks_to_drop, fks_to_add, to_rename)
518
- renamed_fks_to_drop = []
519
- renamed_fks_to_add = []
520
-
521
- fks_to_drop.each { |fk_to_drop|
522
- fks_to_add.each { |fk_to_add|
511
+ fks_to_drop.each_with_object([], []) do |fk_to_drop, (renamed_fks_to_drop, renamed_fks_to_add)|
512
+ if (fks_to_add = fks_to_add.find do |fk_to_add|
513
+ fk_to_add.foreign_key.nil? and raise "Foreign key is not allowed to be nil for #{fk_to_add.inspect}"
523
514
  if fk_to_add.child_table_name == fk_to_drop.child_table_name &&
524
515
  fk_to_add.parent_table_name == fk_to_drop.parent_table_name &&
525
- !fk_to_add.foreign_key.nil? &&
526
516
  fk_to_add.foreign_key == to_rename[fk_to_drop.foreign_key]
527
-
528
- renamed_fks_to_drop.append(fk_to_drop)
529
- renamed_fks_to_add.append(fk_to_add)
530
517
  end
531
- }
532
- }
533
-
534
- [renamed_fks_to_drop, renamed_fks_to_add]
518
+ end)
519
+ renamed_fks_to_drop << fk_to_drop
520
+ renamed_fks_to_add << fks_to_add
521
+ end
522
+ end
535
523
  end
536
524
 
537
525
  def fk_field_options(model, field_name)
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.2.3.pre.ga.4
4
+ version: 1.2.3.pre.ga.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke