dynamic_migrations 3.6.12 → 3.6.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -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/postgres/generator/trigger.rb +16 -9
- data/lib/dynamic_migrations/version.rb +1 -1
- data/sig/dynamic_migrations/active_record/migrators/foreign_key_constraint.rbs +1 -1
- data/sig/dynamic_migrations/postgres/generator/trigger.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: 2a53664f8e85f6f7570b65b756687db445a71c5e48cdc7f52ab4a394570e9be5
|
4
|
+
data.tar.gz: 49cad85aaff8c311714a5e9c47c16708e8f6c3d7b6f276ce94d5b0dc8703eae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03230e628a4b6b0719d12ffeecc68ba0395c405ae828232331195a319f2bfc394a00ba80f999ba68660392dede3a76d4656b749c991ba940332901c0a93cb771
|
7
|
+
data.tar.gz: 7b169d5836f5c6a53cfab698c3f8af30c397334bea5efb1087de0f9c33c481218955b90311715a75f96c124c9bd6306887713eddd5a218cbe375bedbd6dd5f31
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [3.6.14](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.13...v3.6.14) (2023-09-14)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* allowing templates to return nil and skip adding to migrations ([3d90829](https://github.com/craigulliott/dynamic_migrations/commit/3d9082960403899b4243fde60629d9c83ce1e263))
|
9
|
+
|
10
|
+
## [3.6.13](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.12...v3.6.13) (2023-09-14)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* providing foreign_schema_name to create foreign key constraint, and only providing non default arguments ([e45d499](https://github.com/craigulliott/dynamic_migrations/commit/e45d4994a9b947f0d626bdd4b0e2a36136412370))
|
16
|
+
|
3
17
|
## [3.6.12](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.11...v3.6.12) (2023-09-13)
|
4
18
|
|
5
19
|
|
@@ -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,
|
@@ -33,13 +33,18 @@ module DynamicMigrations
|
|
33
33
|
|
34
34
|
arguments = template_class.new(trigger, code_comment).fragment_arguments
|
35
35
|
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
# if the template class returns nil, then we skip the creation of this migration
|
37
|
+
# this is common for triggers where the template is respinsible for setting up
|
38
|
+
# multiple triggers (a mix of on update/insert and before/after etc.)
|
39
|
+
unless arguments.nil?
|
40
|
+
# we only provide a dependent function if the function has more than one trigger
|
41
|
+
# or is in a different schema, otherwise it is added to the same migration as this
|
42
|
+
# trigger and we don't need to worry about dependencies
|
43
|
+
if trigger.function && (trigger.function.triggers.count > 1 || trigger.table.schema != trigger.function.schema)
|
44
|
+
add_fragment(dependent_function: trigger.function, **arguments)
|
45
|
+
else
|
46
|
+
add_fragment(**arguments)
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
# no template, process this as a default trigger (takes all options)
|
@@ -124,8 +129,9 @@ module DynamicMigrations
|
|
124
129
|
end
|
125
130
|
|
126
131
|
def recreate_trigger original_trigger, updated_trigger
|
132
|
+
fragments = []
|
127
133
|
# remove the original trigger
|
128
|
-
|
134
|
+
fragments << remove_trigger(original_trigger, <<~CODE_COMMENT)
|
129
135
|
Removing original trigger because it has changed (it is recreated below)
|
130
136
|
Changes:
|
131
137
|
#{indent original_trigger.differences_descriptions(updated_trigger).join("\n")}
|
@@ -135,9 +141,10 @@ module DynamicMigrations
|
|
135
141
|
recreation_fragment = add_trigger updated_trigger, <<~CODE_COMMENT
|
136
142
|
Recreating this trigger
|
137
143
|
CODE_COMMENT
|
144
|
+
fragments << recreation_fragment unless recreation_fragment.nil?
|
138
145
|
|
139
146
|
# return the new fragments (the main reason to return them here is for the specs)
|
140
|
-
|
147
|
+
fragments
|
141
148
|
end
|
142
149
|
|
143
150
|
# add a comment to a trigger
|
@@ -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
|
@@ -9,7 +9,7 @@ module DynamicMigrations
|
|
9
9
|
def self.has_template?: (Symbol template_name) -> bool
|
10
10
|
def self.add_template: (Symbol template_name, singleton(TriggerTemplateBase) template_class) -> void
|
11
11
|
|
12
|
-
def add_trigger: (Server::Database::Schema::Table::Trigger trigger, ?String? code_comment) -> Fragment
|
12
|
+
def add_trigger: (Server::Database::Schema::Table::Trigger trigger, ?String? code_comment) -> Fragment?
|
13
13
|
def remove_trigger: (Server::Database::Schema::Table::Trigger trigger, ?String? code_comment) -> Fragment
|
14
14
|
def recreate_trigger: (Server::Database::Schema::Table::Trigger original_trigger, Server::Database::Schema::Table::Trigger updated_trigger) -> Array[Fragment]
|
15
15
|
def set_trigger_comment: (Postgres::Server::Database::Schema::Table::Trigger trigger, ?String? code_comment) -> Fragment
|
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.14
|
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
|