dynamic_migrations 3.6.12 → 3.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/dynamic_migrations/active_record/migrators/foreign_key_constraint.rb +3 -1
- data/lib/dynamic_migrations/postgres/generator/foreign_key_constraint.rb +24 -7
- data/lib/dynamic_migrations/version.rb +1 -1
- data/sig/dynamic_migrations/active_record/migrators/foreign_key_constraint.rbs +1 -1
- 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: 9ecc60f6bad6a321991985b6e7cfd024486ec79caa1b49b143caf3c844d28275
|
4
|
+
data.tar.gz: b16c5bb261de851a877d4b6e6067b2767badf82f895ce25e0816286d11ef83e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 182c7cbc69b0ba406147e7e0d972887ec44d8171e00eb75b92a531702cd4abfaf18ab9c7e319ac7771f25696968582b56cf18fe275652f71f2426d1a1b6e363a
|
7
|
+
data.tar.gz: b0f0de5ca2c65380c25c80fe23c53942a576e4f4c9e7e3984d56dbf67d9afac6e2b16153f1d70012b7f0fb1dfd50b1b13e2cdebcf1c0333ea2cd86f90ded33df
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [3.6.13](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.12...v3.6.13) (2023-09-14)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* providing foreign_schema_name to create foreign key constraint, and only providing non default arguments ([e45d499](https://github.com/craigulliott/dynamic_migrations/commit/e45d4994a9b947f0d626bdd4b0e2a36136412370))
|
9
|
+
|
3
10
|
## [3.6.12](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.11...v3.6.12) (2023-09-13)
|
4
11
|
|
5
12
|
|
@@ -11,7 +11,7 @@ module DynamicMigrations
|
|
11
11
|
# because rails migrations don't support composite (multiple column) foreign keys
|
12
12
|
# column_names and foreign_column_names can be a single column name or
|
13
13
|
# an array of column names
|
14
|
-
def add_foreign_key table_name, column_names,
|
14
|
+
def add_foreign_key table_name, column_names, foreign_table_name, foreign_column_names, name:, foreign_schema: nil, initially_deferred: false, deferrable: false, on_delete: :no_action, on_update: :no_action, comment: nil
|
15
15
|
if initially_deferred == true && deferrable == false
|
16
16
|
raise DeferrableOptionsError, "A constraint can only be initially deferred if it is also deferrable"
|
17
17
|
end
|
@@ -19,6 +19,8 @@ module DynamicMigrations
|
|
19
19
|
# convert single column names into arrays, this simplifies the logic below
|
20
20
|
column_names = column_names.is_a?(Array) ? column_names : [column_names]
|
21
21
|
foreign_column_names = foreign_column_names.is_a?(Array) ? foreign_column_names : [foreign_column_names]
|
22
|
+
# default to the current schema
|
23
|
+
foreign_schema_name = foreign_schema.nil? ? schema_name : foreign_schema
|
22
24
|
|
23
25
|
# allow it to be deferred, and defer it by default
|
24
26
|
deferrable_sql = if initially_deferred
|
@@ -12,13 +12,26 @@ module DynamicMigrations
|
|
12
12
|
f_c_names = foreign_key_constraint.foreign_column_names
|
13
13
|
foreign_column_names = (f_c_names.count == 1) ? ":#{f_c_names.first}" : "[:#{f_c_names.join(", :")}]"
|
14
14
|
|
15
|
-
options = {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
options = {}
|
16
|
+
options[:name] = ":#{foreign_key_constraint.name}"
|
17
|
+
|
18
|
+
# only provide values if they are different from the defaults
|
19
|
+
unless foreign_key_constraint.initially_deferred == false
|
20
|
+
options[:initially_deferred] = foreign_key_constraint.initially_deferred
|
21
|
+
end
|
22
|
+
unless foreign_key_constraint.deferrable == false
|
23
|
+
options[:deferrable] = foreign_key_constraint.deferrable
|
24
|
+
end
|
25
|
+
unless foreign_key_constraint.on_delete == :no_action
|
26
|
+
options[:on_delete] = ":#{foreign_key_constraint.on_delete}"
|
27
|
+
end
|
28
|
+
unless foreign_key_constraint.on_update == :no_action
|
29
|
+
options[:on_update] = ":#{foreign_key_constraint.on_update}"
|
30
|
+
end
|
31
|
+
unless foreign_key_constraint.table.schema.name == foreign_key_constraint.foreign_schema_name
|
32
|
+
options[:foreign_schema] = ":#{foreign_key_constraint.foreign_schema_name}"
|
33
|
+
end
|
34
|
+
|
22
35
|
unless foreign_key_constraint.description.nil?
|
23
36
|
options[:comment] = <<~RUBY
|
24
37
|
<<~COMMENT
|
@@ -27,6 +40,10 @@ module DynamicMigrations
|
|
27
40
|
RUBY
|
28
41
|
end
|
29
42
|
|
43
|
+
if foreign_key_constraint.table.schema != foreign_key_constraint.foreign_table.schema
|
44
|
+
options[:foreign_schema] = foreign_key_constraint.foreign_table.schema.name.to_s
|
45
|
+
end
|
46
|
+
|
30
47
|
options_syntax = options.map { |k, v| "#{k}: #{v}" }.join(", ")
|
31
48
|
|
32
49
|
add_fragment schema: foreign_key_constraint.table.schema,
|
@@ -5,7 +5,7 @@ module DynamicMigrations
|
|
5
5
|
module ActiveRecord
|
6
6
|
module Migrators
|
7
7
|
module ForeignKeyConstraint
|
8
|
-
def add_foreign_key: (Symbol table_name, Array[Symbol] column_names, Symbol
|
8
|
+
def add_foreign_key: (Symbol table_name, Array[Symbol] column_names, Symbol foreign_table_name, Array[Symbol] foreign_column_names, name: Symbol, ?foreign_schema: Symbol?, ?initially_deferred: bool, ?deferrable: bool, ?on_delete: Symbol, ?on_update: Symbol, ?comment: String?) -> void
|
9
9
|
def remove_foreign_key: (Symbol table_name, Symbol name) -> void
|
10
10
|
def set_foreign_key_comment: (Symbol table_name, Symbol foreign_key_name, String comment) -> void
|
11
11
|
def remove_foreign_key_comment: (Symbol table_name, Symbol foreign_key_name) -> void
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Ulliott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|