declare_schema 1.2.2 → 1.2.3.pre.ga.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +44 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9557ec596238900fa3a3149ab9c38dfc420af5e0410f8f2fbaa3fb41a009104
|
4
|
+
data.tar.gz: 292bc6f481dff79424a50e6a405ab8ff7f64f205a46f1aef83748139ba3ed8a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9ab8ca57e5782d3658dea77d8623a41d3b5d4fa89782822deca899b0ee39c98b68cf2e07317ad6bcd7f75b027a3491f64dadbb259f6f7c3b64511de7bb65938
|
7
|
+
data.tar.gz: 1f3b7a0ce7ad48027f9a59c47f2125dcd25f5f1d6ae2ea92ca3ccee4e48a1bf1f06ebfb628ab0c05d67bdea3630fb4a65c0dca5fcf4999dfa49ceddacb2d8aaf
|
data/Gemfile.lock
CHANGED
@@ -407,7 +407,7 @@ module Generators
|
|
407
407
|
fk_changes = if ActiveRecord::Base.connection.class.name.match?(/SQLite3Adapter/)
|
408
408
|
[]
|
409
409
|
else
|
410
|
-
change_foreign_key_constraints(model, current_table_name)
|
410
|
+
change_foreign_key_constraints(model, current_table_name, to_rename)
|
411
411
|
end
|
412
412
|
table_options_changes = if ActiveRecord::Base.connection.class.name.match?(/mysql/i)
|
413
413
|
change_table_options(model, current_table_name)
|
@@ -451,11 +451,30 @@ module Generators
|
|
451
451
|
end
|
452
452
|
end
|
453
453
|
|
454
|
-
|
454
|
+
indexes_to_drop = existing_indexes_without_primary_key - model_indexes_without_primary_key
|
455
|
+
indexes_to_add = model_indexes_without_primary_key - existing_indexes_without_primary_key
|
456
|
+
|
457
|
+
renamed_indexes_to_drop = []
|
458
|
+
renamed_indexes_to_add = []
|
459
|
+
|
460
|
+
indexes_to_drop.each { |index_to_drop|
|
461
|
+
renamed_columns = index_to_drop.columns.map do |column|
|
462
|
+
to_rename[column]
|
463
|
+
end
|
464
|
+
|
465
|
+
indexes_to_add.each { |index_to_add|
|
466
|
+
if renamed_columns == index_to_add.columns
|
467
|
+
renamed_indexes_to_drop.append(index_to_drop)
|
468
|
+
renamed_indexes_to_add.append(index_to_add)
|
469
|
+
end
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
drop_indexes = (indexes_to_drop - renamed_indexes_to_drop).map do |i|
|
455
474
|
::DeclareSchema::SchemaChange::IndexRemove.new(new_table_name, i.columns, unique: i.unique, where: i.where, name: i.name)
|
456
475
|
end
|
457
476
|
|
458
|
-
add_indexes = (
|
477
|
+
add_indexes = (indexes_to_add - renamed_indexes_to_add).map do |i|
|
459
478
|
::DeclareSchema::SchemaChange::IndexAdd.new(new_table_name, i.columns, unique: i.unique, where: i.where, name: i.name)
|
460
479
|
end
|
461
480
|
|
@@ -463,19 +482,38 @@ module Generators
|
|
463
482
|
[Array(change_primary_key) + drop_indexes + add_indexes]
|
464
483
|
end
|
465
484
|
|
466
|
-
def change_foreign_key_constraints(model, old_table_name)
|
485
|
+
def change_foreign_key_constraints(model, old_table_name, to_rename)
|
467
486
|
ActiveRecord::Base.connection.class.name.match?(/SQLite3Adapter/) and raise ArgumentError, 'SQLite does not support foreign keys'
|
468
487
|
::DeclareSchema.default_generate_foreign_keys or return []
|
469
488
|
|
470
489
|
existing_fks = ::DeclareSchema::Model::ForeignKeyDefinition.for_model(model, old_table_name)
|
471
490
|
model_fks = model.constraint_specs
|
472
491
|
|
473
|
-
|
492
|
+
fks_to_drop = existing_fks - model_fks
|
493
|
+
fks_to_add = model_fks - existing_fks
|
494
|
+
|
495
|
+
renamed_fks_to_drop = []
|
496
|
+
renamed_fks_to_add = []
|
497
|
+
|
498
|
+
fks_to_drop.each { |fk_to_drop|
|
499
|
+
fks_to_add.each { |fk_to_add|
|
500
|
+
if fk_to_add.child_table_name == fk_to_drop.child_table_name &&
|
501
|
+
fk_to_add.parent_table_name == fk_to_drop.parent_table_name &&
|
502
|
+
fk_to_add.constraint_name == fk_to_drop.constraint_name &&
|
503
|
+
fk_to_add.foreign_key == to_rename[fk_to_drop.foreign_key]
|
504
|
+
|
505
|
+
renamed_fks_to_drop.append(fk_to_drop)
|
506
|
+
renamed_fks_to_add.append(fk_to_add)
|
507
|
+
end
|
508
|
+
}
|
509
|
+
}
|
510
|
+
|
511
|
+
drop_fks = (fks_to_drop - renamed_fks_to_drop).map do |fk|
|
474
512
|
::DeclareSchema::SchemaChange::ForeignKeyRemove.new(fk.child_table_name, fk.parent_table_name,
|
475
513
|
column_name: fk.foreign_key_name, name: fk.constraint_name)
|
476
514
|
end
|
477
515
|
|
478
|
-
add_fks = (
|
516
|
+
add_fks = (fks_to_add - renamed_fks_to_add).map do |fk|
|
479
517
|
# next if fk.parent.constantize.abstract_class || fk.parent == fk.model.class_name
|
480
518
|
::DeclareSchema::SchemaChange::ForeignKeyAdd.new(fk.child_table_name, fk.parent_table_name,
|
481
519
|
column_name: fk.foreign_key_name, name: fk.constraint_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: declare_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3.pre.ga.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development adapted from hobo_fields by Tom Locke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|