declare_schema 1.2.3.pre.ga.4 → 1.2.3.pre.ga.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aacc7a857e82fc857a7694a7c32afe7b9bee2a8949dd455f6506eac066658353
|
4
|
+
data.tar.gz: 513a4171b54d053b3e9cc58111256010040634e287cf2d7f1a33b278cad92548
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5075ebac4ebd80def763e46df74d506e3c2df43d4c0601e35fe335be7c3db8faf5b280fd4417dc54ff2f6608162de5ba69082af4353df6f3d7b0ff449b20486
|
7
|
+
data.tar.gz: 48534ddd177e9061390b26db9142842968cf28f2637f1cc7d091e28205ace5d55c0ddb0669c7b31b370d4d27d18e83ecc09d0c4b8451f79c4230ef0667c89d4f
|
data/Gemfile.lock
CHANGED
@@ -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??
|
@@ -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
|
-
|
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.
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
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
|
-
|
519
|
-
|
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
|
-
|
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)
|