dynamic_migrations 2.1.0 → 3.0.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 +23 -0
- data/lib/dynamic_migrations/active_record/migrators/column.rb +21 -0
- data/lib/dynamic_migrations/active_record/migrators/foreign_key_constraint.rb +112 -0
- data/lib/dynamic_migrations/active_record/migrators/function.rb +108 -0
- data/lib/dynamic_migrations/active_record/migrators/index.rb +27 -0
- data/lib/dynamic_migrations/active_record/migrators/schema.rb +21 -0
- data/lib/dynamic_migrations/active_record/migrators/table.rb +21 -0
- data/lib/dynamic_migrations/active_record/migrators/trigger.rb +109 -0
- data/lib/dynamic_migrations/active_record/migrators/unique_constraint.rb +63 -0
- data/lib/dynamic_migrations/active_record/migrators/validation.rb +67 -0
- data/lib/dynamic_migrations/active_record/migrators.rb +64 -0
- data/lib/dynamic_migrations/name_helper.rb +13 -0
- data/lib/dynamic_migrations/postgres/generator/column.rb +92 -0
- data/lib/dynamic_migrations/postgres/generator/foreign_key_constraint.rb +84 -0
- data/lib/dynamic_migrations/postgres/generator/fragment.rb +30 -0
- data/lib/dynamic_migrations/postgres/generator/function.rb +77 -0
- data/lib/dynamic_migrations/postgres/generator/index.rb +101 -0
- data/lib/dynamic_migrations/postgres/generator/primary_key.rb +55 -0
- data/lib/dynamic_migrations/postgres/generator/schema.rb +19 -0
- data/lib/dynamic_migrations/postgres/generator/schema_migrations/section.rb +37 -0
- data/lib/dynamic_migrations/postgres/generator/schema_migrations.rb +92 -0
- data/lib/dynamic_migrations/postgres/generator/table.rb +122 -0
- data/lib/dynamic_migrations/postgres/generator/trigger.rb +101 -0
- data/lib/dynamic_migrations/postgres/generator/unique_constraint.rb +79 -0
- data/lib/dynamic_migrations/postgres/generator/validation.rb +87 -0
- data/lib/dynamic_migrations/postgres/generator.rb +359 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/functions.rb +68 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/columns.rb +72 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/foreign_key_constraints.rb +73 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/indexes.rb +73 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/primary_key.rb +49 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/triggers.rb +73 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/unique_constraints.rb +73 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/validations.rb +73 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables.rb +80 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas.rb +48 -0
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations.rb +59 -0
- data/lib/dynamic_migrations/postgres/server/database/differences.rb +76 -16
- data/lib/dynamic_migrations/postgres/server/database/keys_and_unique_constraints_loader.rb +35 -9
- data/lib/dynamic_migrations/postgres/server/database/loaded_schemas_builder.rb +50 -26
- data/lib/dynamic_migrations/postgres/server/database/schema/function.rb +69 -0
- data/lib/dynamic_migrations/postgres/server/database/schema/functions.rb +63 -0
- data/lib/dynamic_migrations/postgres/server/database/schema/table/column.rb +6 -44
- data/lib/dynamic_migrations/postgres/server/database/schema/table/columns.rb +1 -1
- data/lib/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraint.rb +40 -5
- data/lib/dynamic_migrations/postgres/server/database/schema/table/index.rb +23 -9
- data/lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb +21 -6
- data/lib/dynamic_migrations/postgres/server/database/schema/table/trigger.rb +151 -0
- data/lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb +66 -0
- data/lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb +19 -9
- data/lib/dynamic_migrations/postgres/server/database/schema/table/validation.rb +20 -1
- data/lib/dynamic_migrations/postgres/server/database/schema/table.rb +15 -5
- data/lib/dynamic_migrations/postgres/server/database/schema/tables.rb +63 -0
- data/lib/dynamic_migrations/postgres/server/database/schema.rb +3 -49
- data/lib/dynamic_migrations/postgres/server/database/source.rb +21 -0
- data/lib/dynamic_migrations/postgres/server/database/structure_loader.rb +22 -112
- data/lib/dynamic_migrations/postgres/server/database/triggers_and_functions_loader.rb +131 -0
- data/lib/dynamic_migrations/postgres/server/database/validations_loader.rb +10 -4
- data/lib/dynamic_migrations/postgres/server/database.rb +2 -1
- data/lib/dynamic_migrations/postgres/server.rb +6 -0
- data/lib/dynamic_migrations/postgres.rb +1 -1
- data/lib/dynamic_migrations/version.rb +1 -1
- data/lib/dynamic_migrations.rb +47 -4
- metadata +44 -3
- data/lib/dynamic_migrations/postgres/data_types.rb +0 -320
@@ -1,320 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DynamicMigrations
|
4
|
-
module Postgres
|
5
|
-
module DataTypes
|
6
|
-
class MissingRequiredAttributeError < StandardError
|
7
|
-
def initialize data_type, attribute
|
8
|
-
super "Missing required attribute `#{attribute}` for data_type `#{data_type}`"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class UnexpectedPropertyNameError < StandardError
|
13
|
-
def initialize attribute
|
14
|
-
super "Unexpected property `#{attribute}`"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class UnexpectedPropertyError < StandardError
|
19
|
-
def initialize data_type, attribute, value
|
20
|
-
super "Unexpected property `#{attribute}` with value `#{value}` for data_type `#{data_type}`"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class UnsupportedTypeError < StandardError
|
25
|
-
def initialize data_type
|
26
|
-
super "Unsupported type `#{data_type}`"
|
27
|
-
end
|
28
|
-
end
|
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
|
-
|
42
|
-
DATA_TYPES = {
|
43
|
-
ARRAY: {
|
44
|
-
description: "binary data (“byte array”)",
|
45
|
-
required: [
|
46
|
-
:udt_schema,
|
47
|
-
:udt_name
|
48
|
-
]
|
49
|
-
},
|
50
|
-
"USER-DEFINED": {
|
51
|
-
description: "binary data (“byte array”)",
|
52
|
-
required: [
|
53
|
-
:udt_schema,
|
54
|
-
:udt_name
|
55
|
-
]
|
56
|
-
},
|
57
|
-
bigint: {
|
58
|
-
description: "signed eight-byte integer",
|
59
|
-
required: [
|
60
|
-
:numeric_precision,
|
61
|
-
:numeric_precision_radix,
|
62
|
-
:numeric_scale
|
63
|
-
],
|
64
|
-
defaults: {
|
65
|
-
numeric_precision: 64,
|
66
|
-
numeric_precision_radix: 2,
|
67
|
-
numeric_scale: 0
|
68
|
-
}
|
69
|
-
},
|
70
|
-
# skipping this, in my tests it automatically turned into a bigint
|
71
|
-
# bigserial: {
|
72
|
-
# description: "autoincrementing eight-byte integer"
|
73
|
-
# },
|
74
|
-
bit: {
|
75
|
-
description: "fixed-length bit string",
|
76
|
-
args: "[ (n) ]",
|
77
|
-
required: [
|
78
|
-
:character_maximum_length
|
79
|
-
]
|
80
|
-
},
|
81
|
-
"bit varying": {
|
82
|
-
description: "variable-length bit string",
|
83
|
-
args: "[ (n) ]"
|
84
|
-
},
|
85
|
-
boolean: {
|
86
|
-
description: "logical Boolean (true/false)",
|
87
|
-
required: []
|
88
|
-
},
|
89
|
-
box: {
|
90
|
-
description: "rectangular box on a plane"
|
91
|
-
},
|
92
|
-
bytea: {
|
93
|
-
description: "binary data (“byte array”)"
|
94
|
-
},
|
95
|
-
character: {
|
96
|
-
description: "fixed-length character string",
|
97
|
-
args: "[ (n) ]",
|
98
|
-
required: [
|
99
|
-
:character_maximum_length,
|
100
|
-
:character_octet_length
|
101
|
-
]
|
102
|
-
},
|
103
|
-
"character varying": {
|
104
|
-
description: "variable-length character string",
|
105
|
-
args: "[ (n) ]",
|
106
|
-
required: [
|
107
|
-
:character_octet_length
|
108
|
-
],
|
109
|
-
defaults: {
|
110
|
-
character_octet_length: 1073741824
|
111
|
-
}
|
112
|
-
},
|
113
|
-
cidr: {
|
114
|
-
description: "IPv4 or IPv6 network address"
|
115
|
-
},
|
116
|
-
circle: {
|
117
|
-
description: "circle on a plane"
|
118
|
-
},
|
119
|
-
date: {
|
120
|
-
description: "calendar date (year, month, day)",
|
121
|
-
required: [
|
122
|
-
:datetime_precision
|
123
|
-
]
|
124
|
-
},
|
125
|
-
"double precision": {
|
126
|
-
description: "double precision floating-point number (8 bytes)",
|
127
|
-
required: [
|
128
|
-
:numeric_precision,
|
129
|
-
:numeric_precision_radix
|
130
|
-
]
|
131
|
-
},
|
132
|
-
inet: {
|
133
|
-
description: "IPv4 or IPv6 host address"
|
134
|
-
},
|
135
|
-
integer: {
|
136
|
-
description: "signed four-byte integer",
|
137
|
-
required: [
|
138
|
-
:numeric_precision,
|
139
|
-
:numeric_precision_radix,
|
140
|
-
:numeric_scale
|
141
|
-
],
|
142
|
-
defaults: {
|
143
|
-
numeric_precision: 32,
|
144
|
-
numeric_precision_radix: 2,
|
145
|
-
numeric_scale: 0
|
146
|
-
}
|
147
|
-
},
|
148
|
-
interval: {
|
149
|
-
description: "time span",
|
150
|
-
args: "[ fields ] [ (p) ]",
|
151
|
-
required: [
|
152
|
-
:datetime_precision
|
153
|
-
]
|
154
|
-
},
|
155
|
-
json: {
|
156
|
-
description: "textual JSON data"
|
157
|
-
},
|
158
|
-
jsonb: {
|
159
|
-
description: "binary JSON data, decomposed"
|
160
|
-
},
|
161
|
-
line: {
|
162
|
-
description: "infinite line on a plane"
|
163
|
-
},
|
164
|
-
lseg: {
|
165
|
-
description: "line segment on a plane"
|
166
|
-
},
|
167
|
-
macaddr: {
|
168
|
-
description: "MAC (Media Access Control) address"
|
169
|
-
},
|
170
|
-
macaddr8: {
|
171
|
-
description: "MAC (Media Access Control) address (EUI-64 format)"
|
172
|
-
},
|
173
|
-
money: {
|
174
|
-
description: "currency amount"
|
175
|
-
},
|
176
|
-
numeric: {
|
177
|
-
description: "exact numeric of selectable precision",
|
178
|
-
args: "[ (p, s) ]",
|
179
|
-
required: [
|
180
|
-
:numeric_precision_radix
|
181
|
-
],
|
182
|
-
optional: [
|
183
|
-
:numeric_precision,
|
184
|
-
:numeric_scale
|
185
|
-
]
|
186
|
-
},
|
187
|
-
path: {
|
188
|
-
description: "geometric path on a plane"
|
189
|
-
},
|
190
|
-
pg_lsn: {
|
191
|
-
description: "PostgreSQL Log Sequence Number"
|
192
|
-
},
|
193
|
-
pg_snapshot: {
|
194
|
-
description: "user-level transaction ID snapshot"
|
195
|
-
},
|
196
|
-
point: {
|
197
|
-
description: "geometric point on a plane"
|
198
|
-
},
|
199
|
-
polygon: {
|
200
|
-
description: "closed geometric path on a plane"
|
201
|
-
},
|
202
|
-
real: {
|
203
|
-
description: "single precision floating-point number (4 bytes)",
|
204
|
-
required: [
|
205
|
-
:numeric_precision,
|
206
|
-
:numeric_precision_radix
|
207
|
-
]
|
208
|
-
},
|
209
|
-
smallint: {
|
210
|
-
description: "signed two-byte",
|
211
|
-
required: [
|
212
|
-
:numeric_precision,
|
213
|
-
:numeric_precision_radix,
|
214
|
-
:numeric_scale
|
215
|
-
]
|
216
|
-
},
|
217
|
-
smallserial: {
|
218
|
-
description: "autoincrementing two-byte"
|
219
|
-
},
|
220
|
-
serial: {
|
221
|
-
description: "autoincrementing four-byte"
|
222
|
-
},
|
223
|
-
text: {
|
224
|
-
description: "variable-length character string",
|
225
|
-
required: [
|
226
|
-
:character_octet_length
|
227
|
-
],
|
228
|
-
defaults: {
|
229
|
-
character_octet_length: 1073741824
|
230
|
-
}
|
231
|
-
},
|
232
|
-
"time without time zone": {
|
233
|
-
description: "time of day (no time zone)",
|
234
|
-
args: "[ (p) ]",
|
235
|
-
required: [
|
236
|
-
:datetime_precision
|
237
|
-
]
|
238
|
-
},
|
239
|
-
"time with time zone": {
|
240
|
-
description: "time of day, including time zone",
|
241
|
-
args: "[ (p) ]",
|
242
|
-
required: [
|
243
|
-
:datetime_precision
|
244
|
-
]
|
245
|
-
},
|
246
|
-
"timestamp without time zone": {
|
247
|
-
description: "date and time (no time zone)",
|
248
|
-
args: "[ (p) ]",
|
249
|
-
required: [
|
250
|
-
:datetime_precision
|
251
|
-
]
|
252
|
-
},
|
253
|
-
"timestamp with time zone": {
|
254
|
-
description: "date and time, including time zone",
|
255
|
-
args: "[ (p) ]",
|
256
|
-
required: [
|
257
|
-
:datetime_precision
|
258
|
-
]
|
259
|
-
},
|
260
|
-
tsquery: {
|
261
|
-
description: "text search query"
|
262
|
-
},
|
263
|
-
tsvector: {
|
264
|
-
description: "text search document"
|
265
|
-
},
|
266
|
-
txid_snapshot: {
|
267
|
-
description: "user-level transaction ID snapshot (deprecated; see pg_snapshot)"
|
268
|
-
},
|
269
|
-
uuid: {
|
270
|
-
description: "universally unique identifier"
|
271
|
-
},
|
272
|
-
xml: {
|
273
|
-
description: "XML data"
|
274
|
-
}
|
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
|
289
|
-
|
290
|
-
def self.validate_type_exists! data_type
|
291
|
-
raise ExpectedSymbolError, data_type unless data_type.is_a? Symbol
|
292
|
-
raise UnsupportedTypeError, data_type unless DATA_TYPES.key? data_type
|
293
|
-
true
|
294
|
-
end
|
295
|
-
|
296
|
-
def self.validate_column_properties! data_type, **column_options
|
297
|
-
validate_type_exists! data_type
|
298
|
-
|
299
|
-
required_attributes = DATA_TYPES[data_type][:required] || []
|
300
|
-
optional_attributes = DATA_TYPES[data_type][:optional] || []
|
301
|
-
possible_attributes = required_attributes + optional_attributes
|
302
|
-
|
303
|
-
# assert all required attributes are present
|
304
|
-
required_attributes.each do |attribute|
|
305
|
-
unless column_options.key?(attribute) && !column_options[attribute].nil?
|
306
|
-
raise MissingRequiredAttributeError.new data_type, attribute
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
# assert no unexpected attributes are present
|
311
|
-
column_options.each do |key, value|
|
312
|
-
unless value.nil? || possible_attributes.include?(key)
|
313
|
-
raise UnexpectedPropertyError.new data_type, key, value
|
314
|
-
end
|
315
|
-
end
|
316
|
-
true
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|