dynamic_migrations 3.8.0 → 3.8.2
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/postgres/server/database/connection.rb +16 -4
- data/lib/dynamic_migrations/postgres/server/database/schema/table/validation.rb +7 -1
- data/lib/dynamic_migrations/version.rb +1 -1
- data/sig/dynamic_migrations/postgres/server/database/connection.rbs +1 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/validation.rbs +3 -0
- 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: 2641592d2902b2b4db711882300e45157cf45df12d3f19ceea84ff97e13f6fab
|
4
|
+
data.tar.gz: d6eb83a0f1d0631acc1474d18305e0828688210f7008dbddb460dc1b2cfaf668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48130e442efa9a4e2ab9763fe8e0cb1f35bca56691361e0d3c350813e89c31e1445f59ff76b981e560eb521e8dfb72822ac80c04c738203b62237ccc9690ecc1
|
7
|
+
data.tar.gz: 0a40ea04a41e2f072fe0f8ae9a163a1989c0e8c752b7078491ae5b75bbe18cfc3d3eebd777a61de2b4372297e78c54539d3a449b11a76771c19a86370d5fe588
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [3.8.2](https://github.com/craigulliott/dynamic_migrations/compare/v3.8.1...v3.8.2) (2023-10-06)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* fetch_normalized_check_clause_and_column_names was using column names from the validation instead of the table it belonged to ([5157205](https://github.com/craigulliott/dynamic_migrations/commit/5157205fc52cfbf062d61054bf12c117a5df5b57))
|
9
|
+
|
10
|
+
## [3.8.1](https://github.com/craigulliott/dynamic_migrations/compare/v3.8.0...v3.8.1) (2023-10-06)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* reusing exiting connection when with_connection is called (it was trying to open a new connection and caused an error) ([840a5cd](https://github.com/craigulliott/dynamic_migrations/commit/840a5cda04d6bc49d73160d2bad7271780027c84))
|
16
|
+
|
3
17
|
## [3.8.0](https://github.com/craigulliott/dynamic_migrations/compare/v3.7.0...v3.8.0) (2023-10-04)
|
4
18
|
|
5
19
|
|
@@ -33,19 +33,31 @@ module DynamicMigrations
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def connected?
|
37
|
+
!@connection.nil?
|
38
|
+
end
|
39
|
+
|
36
40
|
# Opens a connection to the database server, and yields the provided block
|
37
41
|
# before automatically closing the connection again. This is useful for
|
38
42
|
# executing one time queries against the database server.
|
39
43
|
def with_connection &block
|
40
|
-
# create a temporary connection to the server
|
41
|
-
|
44
|
+
# create a temporary connection to the server (unless we are already connected)
|
45
|
+
already_connected = connected?
|
46
|
+
unless already_connected
|
47
|
+
connect
|
48
|
+
end
|
49
|
+
|
42
50
|
# perform work with the connection
|
43
51
|
# todo: `yield connection` would have been preferred, but rbs/steep doesnt understand that syntax
|
44
52
|
if block.is_a? Proc
|
45
53
|
result = block.call connection
|
46
54
|
end
|
47
|
-
|
48
|
-
|
55
|
+
|
56
|
+
# close the connection (unless we were already connected)
|
57
|
+
if already_connected
|
58
|
+
disconnect
|
59
|
+
end
|
60
|
+
|
49
61
|
# return whever was returned from within the block
|
50
62
|
result
|
51
63
|
end
|
@@ -14,6 +14,9 @@ module DynamicMigrations
|
|
14
14
|
class ExpectedArrayOfColumnsError < StandardError
|
15
15
|
end
|
16
16
|
|
17
|
+
class ExpectedTableColumnsError < StandardError
|
18
|
+
end
|
19
|
+
|
17
20
|
class DuplicateColumnError < StandardError
|
18
21
|
end
|
19
22
|
|
@@ -122,6 +125,9 @@ module DynamicMigrations
|
|
122
125
|
end
|
123
126
|
|
124
127
|
def fetch_normalized_check_clause_and_column_names
|
128
|
+
if table.columns.empty?
|
129
|
+
raise ExpectedTableColumnsError, "Can not normalize check clause or validation columnns because the table has no columns"
|
130
|
+
end
|
125
131
|
result = table.schema.database.with_connection do |connection|
|
126
132
|
# wrapped in a transaction just in case something here fails, because
|
127
133
|
# we don't want the temporary table to be persisted
|
@@ -130,7 +136,7 @@ module DynamicMigrations
|
|
130
136
|
# create the temp table and add the expected columns and constraint
|
131
137
|
connection.exec(<<~SQL)
|
132
138
|
CREATE TEMP TABLE validation_normalized_check_clause_temp_table (
|
133
|
-
#{columns.map { |column| '"' + column.name.to_s + '" ' + column.temp_table_data_type.to_s }.join(", ")},
|
139
|
+
#{table.columns.map { |column| '"' + column.name.to_s + '" ' + column.temp_table_data_type.to_s }.join(", ")},
|
134
140
|
CONSTRAINT #{name} CHECK (#{check_clause})
|
135
141
|
);
|
136
142
|
SQL
|
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.8.
|
4
|
+
version: 3.8.2
|
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-10-
|
11
|
+
date: 2023-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|