dynamic_migrations 2.0.0 → 2.1.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bbdbe66b5d24e600037fcaf794929bca95cb55b6a2bd45de324934ab1ab22b2
|
4
|
+
data.tar.gz: 06dd757a70e427b753e6f5b3f1bdbf970c749947d13ba7771449f595a2968743
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1f8deb5208188c16ff9b6b0071b9fea82111626336cd73d77e519ce93bb1af4df74090c3e34de49d007d1709f7b7041f95cbfca97dc4676e91e74b19b5ee556
|
7
|
+
data.tar.gz: bfced908cb97de19a678043f6e6fff00faeb11d4dc1ac8b3b15b3e8611f21c121b5ad9a04dae54a8cbf118f9efee9b9462a1b6dcf12904c511d23c15d079ea93
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [2.1.0](https://github.com/craigulliott/dynamic_migrations/compare/v2.0.0...v2.1.0) (2023-07-31)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* apply default column values to column data types ([6911c5f](https://github.com/craigulliott/dynamic_migrations/commit/6911c5f2026b47ef2e9f7bc529f7ff0d8f098700))
|
9
|
+
|
3
10
|
## [2.0.0](https://github.com/craigulliott/dynamic_migrations/compare/v1.1.1...v2.0.0) (2023-07-27)
|
4
11
|
|
5
12
|
|
@@ -9,6 +9,12 @@ module DynamicMigrations
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
class UnexpectedPropertyNameError < StandardError
|
13
|
+
def initialize attribute
|
14
|
+
super "Unexpected property `#{attribute}`"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
class UnexpectedPropertyError < StandardError
|
13
19
|
def initialize data_type, attribute, value
|
14
20
|
super "Unexpected property `#{attribute}` with value `#{value}` for data_type `#{data_type}`"
|
@@ -21,6 +27,18 @@ module DynamicMigrations
|
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
30
|
+
ATTRIBUTE_NAMES = [
|
31
|
+
:character_maximum_length,
|
32
|
+
:character_octet_length,
|
33
|
+
:numeric_precision,
|
34
|
+
:numeric_precision_radix,
|
35
|
+
:numeric_scale,
|
36
|
+
:datetime_precision,
|
37
|
+
:interval_type,
|
38
|
+
:udt_schema,
|
39
|
+
:udt_name
|
40
|
+
].freeze
|
41
|
+
|
24
42
|
DATA_TYPES = {
|
25
43
|
ARRAY: {
|
26
44
|
description: "binary data (“byte array”)",
|
@@ -42,7 +60,12 @@ module DynamicMigrations
|
|
42
60
|
:numeric_precision,
|
43
61
|
:numeric_precision_radix,
|
44
62
|
:numeric_scale
|
45
|
-
]
|
63
|
+
],
|
64
|
+
defaults: {
|
65
|
+
numeric_precision: 64,
|
66
|
+
numeric_precision_radix: 2,
|
67
|
+
numeric_scale: 0
|
68
|
+
}
|
46
69
|
},
|
47
70
|
# skipping this, in my tests it automatically turned into a bigint
|
48
71
|
# bigserial: {
|
@@ -82,7 +105,10 @@ module DynamicMigrations
|
|
82
105
|
args: "[ (n) ]",
|
83
106
|
required: [
|
84
107
|
:character_octet_length
|
85
|
-
]
|
108
|
+
],
|
109
|
+
defaults: {
|
110
|
+
character_octet_length: 1073741824
|
111
|
+
}
|
86
112
|
},
|
87
113
|
cidr: {
|
88
114
|
description: "IPv4 or IPv6 network address"
|
@@ -112,7 +138,12 @@ module DynamicMigrations
|
|
112
138
|
:numeric_precision,
|
113
139
|
:numeric_precision_radix,
|
114
140
|
:numeric_scale
|
115
|
-
]
|
141
|
+
],
|
142
|
+
defaults: {
|
143
|
+
numeric_precision: 32,
|
144
|
+
numeric_precision_radix: 2,
|
145
|
+
numeric_scale: 0
|
146
|
+
}
|
116
147
|
},
|
117
148
|
interval: {
|
118
149
|
description: "time span",
|
@@ -193,7 +224,10 @@ module DynamicMigrations
|
|
193
224
|
description: "variable-length character string",
|
194
225
|
required: [
|
195
226
|
:character_octet_length
|
196
|
-
]
|
227
|
+
],
|
228
|
+
defaults: {
|
229
|
+
character_octet_length: 1073741824
|
230
|
+
}
|
197
231
|
},
|
198
232
|
"time without time zone": {
|
199
233
|
description: "time of day (no time zone)",
|
@@ -238,7 +272,20 @@ module DynamicMigrations
|
|
238
272
|
xml: {
|
239
273
|
description: "XML data"
|
240
274
|
}
|
241
|
-
}
|
275
|
+
}.freeze
|
276
|
+
|
277
|
+
def self.default_for data_type, attribute
|
278
|
+
raise ExpectedSymbolError, data_type unless data_type.is_a? Symbol
|
279
|
+
raise ExpectedSymbolError, attribute unless attribute.is_a? Symbol
|
280
|
+
raise UnsupportedTypeError, data_type unless DATA_TYPES.key? data_type
|
281
|
+
|
282
|
+
unless ATTRIBUTE_NAMES.include? attribute
|
283
|
+
raise UnexpectedPropertyNameError.new attribute
|
284
|
+
end
|
285
|
+
|
286
|
+
defaults = DATA_TYPES[data_type][:defaults]
|
287
|
+
defaults && defaults[attribute] || nil
|
288
|
+
end
|
242
289
|
|
243
290
|
def self.validate_type_exists! data_type
|
244
291
|
raise ExpectedSymbolError, data_type unless data_type.is_a? Symbol
|
@@ -48,6 +48,17 @@ module DynamicMigrations
|
|
48
48
|
@description = description
|
49
49
|
end
|
50
50
|
|
51
|
+
# apply any defaults for this data type
|
52
|
+
character_maximum_length = character_maximum_length.nil? ? DataTypes.default_for(data_type, :character_maximum_length) : character_maximum_length
|
53
|
+
character_octet_length = character_octet_length.nil? ? DataTypes.default_for(data_type, :character_octet_length) : character_octet_length
|
54
|
+
numeric_precision = numeric_precision.nil? ? DataTypes.default_for(data_type, :numeric_precision) : numeric_precision
|
55
|
+
numeric_precision_radix = numeric_precision_radix.nil? ? DataTypes.default_for(data_type, :numeric_precision_radix) : numeric_precision_radix
|
56
|
+
numeric_scale = numeric_scale.nil? ? DataTypes.default_for(data_type, :numeric_scale) : numeric_scale
|
57
|
+
datetime_precision = datetime_precision.nil? ? DataTypes.default_for(data_type, :datetime_precision) : datetime_precision
|
58
|
+
interval_type = interval_type.nil? ? DataTypes.default_for(data_type, :interval_type) : interval_type
|
59
|
+
udt_schema = udt_schema.nil? ? DataTypes.default_for(data_type, :udt_schema) : udt_schema
|
60
|
+
udt_name = udt_name.nil? ? DataTypes.default_for(data_type, :udt_name) : udt_name
|
61
|
+
|
51
62
|
DataTypes.validate_column_properties!(data_type,
|
52
63
|
character_maximum_length: character_maximum_length,
|
53
64
|
character_octet_length: character_octet_length,
|
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: 2.
|
4
|
+
version: 2.1.0
|
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-07-
|
11
|
+
date: 2023-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|