declare_schema 1.2.2.pre.0 → 1.2.3.pre.ga.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- 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: 64db3ac9b4bea4625bbd2bdc40f9aea3296157c535d3bc773aab680fa33d3e9d
|
4
|
+
data.tar.gz: a5681f63baa97b4cc4409bf9784a0b2c45d58ac8fe251214771ebb269eb649ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e4dd03780302f015725770a734a58d369f9655c7717e64497dbb24ce4602cd379bc7b8db15d89780adb55ec342e485110e8e34fdf0ef522e4925a927433891b
|
7
|
+
data.tar.gz: 61f05f815b21f47fa358950c25b38411dcde90b59b73fbca1a373291e0552dcc1d3c516e1c894c84c5bae5cbe66b2ca80a976ce537c1c42e8b4a2d8d06b3cf56
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
5
5
|
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [1.2.2] -
|
7
|
+
## [1.2.2] - 2023-01-27
|
8
8
|
### Changed
|
9
9
|
- Documented `belongs_to` and `has_and_belongs_to_many` behavior
|
10
10
|
- Documented configurable ignored tables behavior
|
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 == fks_to_drop.child_table_name &&
|
501
|
+
fk_to_add.parent_table_name == fks_to_drop.parent_table_name &&
|
502
|
+
fk_to_add.constraint_name == fks_to_drop.constraint_name &&
|
503
|
+
fk_to_add.foreign_key == to_rename[fks_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.0
|
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
|