declare_schema 1.2.3.pre.ga.4 → 1.2.3.pre.ga.6

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: 506475213508a2b48038ccb1e8d2b4398b03879d88a7760803ffbc9273463033
4
- data.tar.gz: 6fac90c4db4626a52d98c71ad98c6f8615e8f041473874575f9b3ba2e2123589
3
+ metadata.gz: '0681126cdd17705ec35f41ab9e4dc608fbc961b50614124ace54e17c49675eca'
4
+ data.tar.gz: efa69b2eb51fa5e2a9ec5b22ed04ecdf91679abecfb674646ea7e461974a097e
5
5
  SHA512:
6
- metadata.gz: 9d9eda18aaa034a6b78239e76e2416b1a0f26a4094268b9a9fb1b4f807108a557d7163d7e623568cb3a6bf1bc4d5dee1d84068d7b391e5cc399b81de095aad6e
7
- data.tar.gz: 36c6b8f67da4ece257360b4bded0dc79b08e9e31a3f9a3ba0745016ebd481ad76c13e7f8fb549e1d923c9e557056ceff10b60858bb0fa0743f61131af31f0a08
6
+ metadata.gz: 69d913a279f29f6368ceb224791213d9bc711e27c8a4a598f7feeb720bf753c5b6e5d65e7537655979b9bc6da5ee663c69f8c9dc2a8e2156b5b1e1c7608cc03b
7
+ data.tar.gz: 5f4b21eb05fc804a883f5bef692bf3473e25b8a61e066cf094e363b46be27fede8fc520efebc04a49ccd4e3c56fa7bddfcb5713204c828dba146904423781535
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.6)
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.6"
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
479
-
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
- }
475
+ end.sort
487
476
 
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,17 @@ 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|
523
- if fk_to_add.child_table_name == fk_to_drop.child_table_name &&
524
- fk_to_add.parent_table_name == fk_to_drop.parent_table_name &&
525
- !fk_to_add.foreign_key.nil? &&
526
- 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
- end
531
- }
532
- }
533
-
534
- [renamed_fks_to_drop, renamed_fks_to_add]
511
+ fks_to_drop.each_with_object([[], []]) do |fk_to_drop, (renamed_fks_to_drop, renamed_fks_to_add)|
512
+ if (fk_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}"
514
+ fk_to_add.child_table_name == fk_to_drop.child_table_name &&
515
+ fk_to_add.parent_table_name == fk_to_drop.parent_table_name &&
516
+ fk_to_add.foreign_key == to_rename[fk_to_drop.foreign_key]
517
+ end)
518
+ renamed_fks_to_drop << fk_to_drop
519
+ renamed_fks_to_add << fk_to_add
520
+ end
521
+ end
535
522
  end
536
523
 
537
524
  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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke