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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0681126cdd17705ec35f41ab9e4dc608fbc961b50614124ace54e17c49675eca'
|
4
|
+
data.tar.gz: efa69b2eb51fa5e2a9ec5b22ed04ecdf91679abecfb674646ea7e461974a097e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69d913a279f29f6368ceb224791213d9bc711e27c8a4a598f7feeb720bf753c5b6e5d65e7537655979b9bc6da5ee663c69f8c9dc2a8e2156b5b1e1c7608cc03b
|
7
|
+
data.tar.gz: 5f4b21eb05fc804a883f5bef692bf3473e25b8a61e066cf094e363b46be27fede8fc520efebc04a49ccd4e3c56fa7bddfcb5713204c828dba146904423781535
|
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
|
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
|
-
|
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
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
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)
|