dynamic_migrations 1.1.1 → 2.0.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/dynamic_migrations/postgres/server/database/connection.rb +2 -2
- data/lib/dynamic_migrations/postgres/server/database/differences.rb +21 -21
- data/lib/dynamic_migrations/postgres/server/database/schema/table/column.rb +4 -4
- data/lib/dynamic_migrations/postgres/server/database/schema/table/columns.rb +13 -13
- data/lib/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraint.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraints.rb +13 -13
- data/lib/dynamic_migrations/postgres/server/database/schema/table/index.rb +9 -9
- data/lib/dynamic_migrations/postgres/server/database/schema/table/indexes.rb +13 -13
- data/lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb +8 -8
- data/lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb +8 -8
- data/lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraints.rb +13 -13
- data/lib/dynamic_migrations/postgres/server/database/schema/table/validation.rb +8 -8
- data/lib/dynamic_migrations/postgres/server/database/schema/table/validations.rb +13 -13
- data/lib/dynamic_migrations/postgres/server/database/schema/table.rb +6 -6
- data/lib/dynamic_migrations/postgres/server/database/schema.rb +4 -4
- data/lib/dynamic_migrations/postgres/server/database.rb +4 -4
- data/lib/dynamic_migrations/postgres/server.rb +7 -7
- data/lib/dynamic_migrations/version.rb +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: d576c2761325b577a0e175e24a59833dc595212900f953ee494d71d4a635beef
|
4
|
+
data.tar.gz: 47911ce666cdd465a8f57a54263155c92ba8d37339cf7bf3c2a6a3fcde549e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a05c58150c20cdf1a19f14e2d931e7a48e4220531cc5f1f25d9cf0740554fe01a3b3db7e2ea7e12d4d06732c0fa472fdd6652cf27fffdad8a82039f73163eeb
|
7
|
+
data.tar.gz: 0ae100cf8c850cde3de93c4fd86df3487c1b4f7b7f25de65d9fab6b0dfde020bf4d4f09b802c37c92fe5d26fb0b6b73d12d641cb6f6c0fb3567e8e97f047ce87
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [2.0.0](https://github.com/craigulliott/dynamic_migrations/compare/v1.1.1...v2.0.0) (2023-07-27)
|
4
|
+
|
5
|
+
|
6
|
+
### ⚠ BREAKING CHANGES
|
7
|
+
|
8
|
+
* changing all name related methods from %object%_name to just name (i.e. `table.table_name` is now just `table.name`)
|
9
|
+
|
10
|
+
### Features
|
11
|
+
|
12
|
+
* changing all name related methods from %object%_name to just name (i.e. `table.table_name` is now just `table.name`) ([77f18ae](https://github.com/craigulliott/dynamic_migrations/commit/77f18ae168c2449fa437fa7692ff9339931f9076))
|
13
|
+
|
3
14
|
## [1.1.1](https://github.com/craigulliott/dynamic_migrations/compare/v1.1.0...v1.1.1) (2023-07-17)
|
4
15
|
|
5
16
|
|
@@ -15,9 +15,9 @@ module DynamicMigrations
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def connect
|
18
|
-
raise MissingDatabaseNameError unless
|
18
|
+
raise MissingDatabaseNameError unless name
|
19
19
|
raise AlreadyConnectedError if @connection
|
20
|
-
@connection = Postgres::Connections.create_connection server.host, server.port, server.username, server.password,
|
20
|
+
@connection = Postgres::Connections.create_connection server.host, server.port, server.username, server.password, name
|
21
21
|
end
|
22
22
|
|
23
23
|
def connection
|
@@ -107,7 +107,7 @@ module DynamicMigrations
|
|
107
107
|
matches: (comparison_table && comparison_table.description == table.description) || false
|
108
108
|
},
|
109
109
|
primary_key: compare_record(primary_key, comparison_primary_key, [
|
110
|
-
:
|
110
|
+
:name,
|
111
111
|
:index_type
|
112
112
|
]),
|
113
113
|
columns: compare_columns(table.columns_hash, comparison_columns),
|
@@ -159,9 +159,9 @@ module DynamicMigrations
|
|
159
159
|
def self.compare_unique_constraints unique_constraints, comparison_unique_constraints
|
160
160
|
result = {}
|
161
161
|
# the base unique_constraints
|
162
|
-
unique_constraints.each do |
|
162
|
+
unique_constraints.each do |name, unique_constraint|
|
163
163
|
# compare this unique_constraint to the equivilent in the comparison list
|
164
|
-
result[
|
164
|
+
result[name] = compare_record unique_constraint, comparison_unique_constraints[name], [
|
165
165
|
:column_names,
|
166
166
|
:index_type,
|
167
167
|
:deferrable,
|
@@ -169,9 +169,9 @@ module DynamicMigrations
|
|
169
169
|
]
|
170
170
|
end
|
171
171
|
# look for any unique_constraints in the comparison list which were not in the base list
|
172
|
-
comparison_unique_constraints.each do |
|
173
|
-
unless result.key?
|
174
|
-
result[
|
172
|
+
comparison_unique_constraints.each do |name, unique_constraint|
|
173
|
+
unless result.key? name
|
174
|
+
result[name] = {
|
175
175
|
exists: false
|
176
176
|
}
|
177
177
|
end
|
@@ -185,9 +185,9 @@ module DynamicMigrations
|
|
185
185
|
def self.compare_indexes indexes, comparison_indexes
|
186
186
|
result = {}
|
187
187
|
# the base indexes
|
188
|
-
indexes.each do |
|
188
|
+
indexes.each do |name, index|
|
189
189
|
# compare this index to the equivilent in the comparison list
|
190
|
-
result[
|
190
|
+
result[name] = compare_record index, comparison_indexes[name], [
|
191
191
|
:column_names,
|
192
192
|
:unique,
|
193
193
|
:where,
|
@@ -199,9 +199,9 @@ module DynamicMigrations
|
|
199
199
|
]
|
200
200
|
end
|
201
201
|
# look for any indexes in the comparison list which were not in the base list
|
202
|
-
comparison_indexes.each do |
|
203
|
-
unless result.key?
|
204
|
-
result[
|
202
|
+
comparison_indexes.each do |name, index|
|
203
|
+
unless result.key? name
|
204
|
+
result[name] = {
|
205
205
|
exists: false
|
206
206
|
}
|
207
207
|
end
|
@@ -215,9 +215,9 @@ module DynamicMigrations
|
|
215
215
|
def self.compare_validations validations, comparison_validations
|
216
216
|
result = {}
|
217
217
|
# the base validations
|
218
|
-
validations.each do |
|
218
|
+
validations.each do |name, validation|
|
219
219
|
# compare this validation to the equivilent in the comparison list
|
220
|
-
result[
|
220
|
+
result[name] = compare_record validation, comparison_validations[name], [
|
221
221
|
:check_clause,
|
222
222
|
:column_names,
|
223
223
|
:deferrable,
|
@@ -225,9 +225,9 @@ module DynamicMigrations
|
|
225
225
|
]
|
226
226
|
end
|
227
227
|
# look for any validations in the comparison list which were not in the base list
|
228
|
-
comparison_validations.each do |
|
229
|
-
unless result.key?
|
230
|
-
result[
|
228
|
+
comparison_validations.each do |name, validation|
|
229
|
+
unless result.key? name
|
230
|
+
result[name] = {
|
231
231
|
exists: false
|
232
232
|
}
|
233
233
|
end
|
@@ -241,9 +241,9 @@ module DynamicMigrations
|
|
241
241
|
def self.compare_foreign_key_constraints foreign_key_constraints, comparison_foreign_key_constraints
|
242
242
|
result = {}
|
243
243
|
# the base foreign_key_constraints
|
244
|
-
foreign_key_constraints.each do |
|
244
|
+
foreign_key_constraints.each do |name, foreign_key_constraint|
|
245
245
|
# compare this foreign_key_constraint to the equivilent in the comparison list
|
246
|
-
result[
|
246
|
+
result[name] = compare_record foreign_key_constraint, comparison_foreign_key_constraints[name], [
|
247
247
|
:column_names,
|
248
248
|
:foreign_schema_name,
|
249
249
|
:foreign_table_name,
|
@@ -253,9 +253,9 @@ module DynamicMigrations
|
|
253
253
|
]
|
254
254
|
end
|
255
255
|
# look for any foreign_key_constraints in the comparison list which were not in the base list
|
256
|
-
comparison_foreign_key_constraints.each do |
|
257
|
-
unless result.key?
|
258
|
-
result[
|
256
|
+
comparison_foreign_key_constraints.each do |name, foreign_key_constraint|
|
257
|
+
unless result.key? name
|
258
|
+
result[name] = {
|
259
259
|
exists: false
|
260
260
|
}
|
261
261
|
end
|
@@ -12,7 +12,7 @@ module DynamicMigrations
|
|
12
12
|
end
|
13
13
|
|
14
14
|
attr_reader :table
|
15
|
-
attr_reader :
|
15
|
+
attr_reader :name
|
16
16
|
attr_reader :description
|
17
17
|
attr_reader :null
|
18
18
|
attr_reader :default
|
@@ -29,13 +29,13 @@ module DynamicMigrations
|
|
29
29
|
attr_reader :updatable
|
30
30
|
|
31
31
|
# initialize a new object to represent a column in a postgres table
|
32
|
-
def initialize source, table,
|
32
|
+
def initialize source, table, name, data_type, null: true, default: nil, description: nil, character_maximum_length: nil, character_octet_length: nil, numeric_precision: nil, numeric_precision_radix: nil, numeric_scale: nil, datetime_precision: nil, interval_type: nil, udt_schema: nil, udt_name: nil, updatable: true
|
33
33
|
super source
|
34
34
|
raise ExpectedTableError, table unless table.is_a? Table
|
35
35
|
@table = table
|
36
36
|
|
37
|
-
raise ExpectedSymbolError,
|
38
|
-
@
|
37
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
38
|
+
@name = name
|
39
39
|
|
40
40
|
@data_type = data_type
|
41
41
|
|
@@ -16,16 +16,16 @@ module DynamicMigrations
|
|
16
16
|
|
17
17
|
# returns the column object for the provided column name, and raises an
|
18
18
|
# error if the column does not exist
|
19
|
-
def column
|
20
|
-
raise ExpectedSymbolError,
|
21
|
-
raise ColumnDoesNotExistError unless has_column?
|
22
|
-
@columns[
|
19
|
+
def column name
|
20
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
21
|
+
raise ColumnDoesNotExistError unless has_column? name
|
22
|
+
@columns[name]
|
23
23
|
end
|
24
24
|
|
25
25
|
# returns true if this table has a column with the provided name, otherwise false
|
26
|
-
def has_column?
|
27
|
-
raise ExpectedSymbolError,
|
28
|
-
@columns.key?
|
26
|
+
def has_column? name
|
27
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
28
|
+
@columns.key? name
|
29
29
|
end
|
30
30
|
|
31
31
|
# returns an array of this tables columns
|
@@ -38,20 +38,20 @@ module DynamicMigrations
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# adds a new column to this table, and returns it
|
41
|
-
def add_column
|
42
|
-
if has_column?
|
43
|
-
raise(DuplicateColumnError, "Column #{
|
41
|
+
def add_column name, data_type, **column_options
|
42
|
+
if has_column? name
|
43
|
+
raise(DuplicateColumnError, "Column #{name} already exists")
|
44
44
|
end
|
45
45
|
included_target = self
|
46
46
|
if included_target.is_a? Table
|
47
|
-
new_column = @columns[
|
47
|
+
new_column = @columns[name] = Column.new source, included_target, name, data_type, **column_options
|
48
48
|
else
|
49
49
|
raise ModuleIncludedIntoUnexpectedTargetError, included_target
|
50
50
|
end
|
51
51
|
# sort the hash so that the columns are in alphabetical order by name
|
52
52
|
sorted_columns = {}
|
53
|
-
@columns.keys.sort.each do |
|
54
|
-
sorted_columns[
|
53
|
+
@columns.keys.sort.each do |name|
|
54
|
+
sorted_columns[name] = @columns[name]
|
55
55
|
end
|
56
56
|
@columns = sorted_columns
|
57
57
|
# return the new column
|
@@ -22,12 +22,12 @@ module DynamicMigrations
|
|
22
22
|
|
23
23
|
attr_reader :table
|
24
24
|
attr_reader :foreign_table
|
25
|
-
attr_reader :
|
25
|
+
attr_reader :name
|
26
26
|
attr_reader :deferrable
|
27
27
|
attr_reader :initially_deferred
|
28
28
|
|
29
29
|
# initialize a new object to represent a foreign_key_constraint in a postgres table
|
30
|
-
def initialize source, table, columns, foreign_table, foreign_columns,
|
30
|
+
def initialize source, table, columns, foreign_table, foreign_columns, name, deferrable: false, initially_deferred: false
|
31
31
|
super source
|
32
32
|
|
33
33
|
raise ExpectedTableError, table unless table.is_a? Table
|
@@ -43,7 +43,7 @@ module DynamicMigrations
|
|
43
43
|
raise ExpectedArrayOfColumnsError
|
44
44
|
end
|
45
45
|
|
46
|
-
if table.
|
46
|
+
if table.name == foreign_table.name && table.schema.name == foreign_table.schema.name
|
47
47
|
raise ExpectedDifferentTablesError
|
48
48
|
end
|
49
49
|
|
@@ -61,8 +61,8 @@ module DynamicMigrations
|
|
61
61
|
add_column column, true
|
62
62
|
end
|
63
63
|
|
64
|
-
raise ExpectedSymbolError,
|
65
|
-
@
|
64
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
65
|
+
@name = name
|
66
66
|
|
67
67
|
raise ExpectedBooleanError, deferrable unless [true, false].include?(deferrable)
|
68
68
|
@deferrable = deferrable
|
@@ -88,11 +88,11 @@ module DynamicMigrations
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def foreign_schema_name
|
91
|
-
@foreign_table.schema.
|
91
|
+
@foreign_table.schema.name
|
92
92
|
end
|
93
93
|
|
94
94
|
def foreign_table_name
|
95
|
-
@foreign_table.
|
95
|
+
@foreign_table.name
|
96
96
|
end
|
97
97
|
|
98
98
|
private
|
@@ -113,15 +113,15 @@ module DynamicMigrations
|
|
113
113
|
end
|
114
114
|
|
115
115
|
# assert that the provided column exists within this foreign_key_constraints table
|
116
|
-
unless t.has_column? column.
|
116
|
+
unless t.has_column? column.name
|
117
117
|
raise ExpectedArrayOfColumnsError, "One or more columns do not exist in this foreign_key_constraints table"
|
118
118
|
end
|
119
119
|
|
120
|
-
if cs.key? column.
|
121
|
-
raise(DuplicateColumnError, "Column #{column.
|
120
|
+
if cs.key? column.name
|
121
|
+
raise(DuplicateColumnError, "Column #{column.name} already exists")
|
122
122
|
end
|
123
123
|
|
124
|
-
cs[column.
|
124
|
+
cs[column.name] = column
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
data/lib/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraints.rb
CHANGED
@@ -16,16 +16,16 @@ module DynamicMigrations
|
|
16
16
|
|
17
17
|
# returns the foreign_key_constraint object for the provided foreign_key_constraint name, and raises an
|
18
18
|
# error if the foreign_key_constraint does not exist
|
19
|
-
def foreign_key_constraint
|
20
|
-
raise ExpectedSymbolError,
|
21
|
-
raise ForeignKeyConstraintDoesNotExistError unless has_foreign_key_constraint?
|
22
|
-
@foreign_key_constraints[
|
19
|
+
def foreign_key_constraint name
|
20
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
21
|
+
raise ForeignKeyConstraintDoesNotExistError unless has_foreign_key_constraint? name
|
22
|
+
@foreign_key_constraints[name]
|
23
23
|
end
|
24
24
|
|
25
25
|
# returns true if this table has a foreign_key_constraint with the provided name, otherwise false
|
26
|
-
def has_foreign_key_constraint?
|
27
|
-
raise ExpectedSymbolError,
|
28
|
-
@foreign_key_constraints.key?
|
26
|
+
def has_foreign_key_constraint? name
|
27
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
28
|
+
@foreign_key_constraints.key? name
|
29
29
|
end
|
30
30
|
|
31
31
|
# returns an array of this tables foreign_key_constraints
|
@@ -38,9 +38,9 @@ module DynamicMigrations
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# adds a new foreign_key_constraint to this table, and returns it
|
41
|
-
def add_foreign_key_constraint
|
42
|
-
if has_foreign_key_constraint?
|
43
|
-
raise(ForeignKeyConstraintAlreadyExistsError, "foreign_key_constraint #{
|
41
|
+
def add_foreign_key_constraint name, column_names, foreign_schema_name, foreign_table_name, foreign_column_names, **foreign_key_constraint_options
|
42
|
+
if has_foreign_key_constraint? name
|
43
|
+
raise(ForeignKeyConstraintAlreadyExistsError, "foreign_key_constraint #{name} already exists")
|
44
44
|
end
|
45
45
|
columns = column_names.map { |column_name| column column_name }
|
46
46
|
foreign_schema = schema.database.schema foreign_schema_name, source
|
@@ -48,14 +48,14 @@ module DynamicMigrations
|
|
48
48
|
foreign_columns = foreign_column_names.map { |column_name| foreign_table.column column_name }
|
49
49
|
included_target = self
|
50
50
|
if included_target.is_a? Table
|
51
|
-
new_foreign_key_constraint = @foreign_key_constraints[
|
51
|
+
new_foreign_key_constraint = @foreign_key_constraints[name] = ForeignKeyConstraint.new source, included_target, columns, foreign_table, foreign_columns, name, **foreign_key_constraint_options
|
52
52
|
else
|
53
53
|
raise ModuleIncludedIntoUnexpectedTargetError, included_target
|
54
54
|
end
|
55
55
|
# sort the hash so that the foreign_key_constraints are in alphabetical order by name
|
56
56
|
sorted_foreign_key_constraints = {}
|
57
|
-
@foreign_key_constraints.keys.sort.each do |
|
58
|
-
sorted_foreign_key_constraints[
|
57
|
+
@foreign_key_constraints.keys.sort.each do |name|
|
58
|
+
sorted_foreign_key_constraints[name] = @foreign_key_constraints[name]
|
59
59
|
end
|
60
60
|
@foreign_key_constraints = sorted_foreign_key_constraints
|
61
61
|
# return the new foreign_key_constraint
|
@@ -31,7 +31,7 @@ module DynamicMigrations
|
|
31
31
|
end
|
32
32
|
|
33
33
|
attr_reader :table
|
34
|
-
attr_reader :
|
34
|
+
attr_reader :name
|
35
35
|
attr_reader :unique
|
36
36
|
attr_reader :where
|
37
37
|
attr_reader :type
|
@@ -41,7 +41,7 @@ module DynamicMigrations
|
|
41
41
|
attr_reader :nulls_position
|
42
42
|
|
43
43
|
# initialize a new object to represent a index in a postgres table
|
44
|
-
def initialize source, table, columns,
|
44
|
+
def initialize source, table, columns, name, unique: false, where: nil, type: :btree, deferrable: false, initially_deferred: false, include_columns: [], order: :asc, nulls_position: :last
|
45
45
|
super source
|
46
46
|
raise ExpectedTableError, table unless table.is_a? Table
|
47
47
|
@table = table
|
@@ -57,8 +57,8 @@ module DynamicMigrations
|
|
57
57
|
add_column column
|
58
58
|
end
|
59
59
|
|
60
|
-
raise ExpectedSymbolError,
|
61
|
-
@
|
60
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
61
|
+
@name = name
|
62
62
|
|
63
63
|
raise ExpectedBooleanError, unique unless [true, false].include?(unique)
|
64
64
|
@unique = unique
|
@@ -121,18 +121,18 @@ module DynamicMigrations
|
|
121
121
|
end
|
122
122
|
|
123
123
|
# assert that the provided column exists within this indexes table
|
124
|
-
unless @table.has_column? column.
|
124
|
+
unless @table.has_column? column.name
|
125
125
|
raise ExpectedArrayOfColumnsError, "One or more columns do not exist in this indexes table"
|
126
126
|
end
|
127
127
|
|
128
|
-
if @columns.key?(column.
|
129
|
-
raise(DuplicateColumnError, "Column #{column.
|
128
|
+
if @columns.key?(column.name) || @include_columns.key?(column.name)
|
129
|
+
raise(DuplicateColumnError, "Column #{column.name} already exists in index, or is already included")
|
130
130
|
end
|
131
131
|
|
132
132
|
if is_include_column
|
133
|
-
@include_columns[column.
|
133
|
+
@include_columns[column.name] = column
|
134
134
|
else
|
135
|
-
@columns[column.
|
135
|
+
@columns[column.name] = column
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -16,16 +16,16 @@ module DynamicMigrations
|
|
16
16
|
|
17
17
|
# returns the index object for the provided index name, and raises an
|
18
18
|
# error if the index does not exist
|
19
|
-
def index
|
20
|
-
raise ExpectedSymbolError,
|
21
|
-
raise IndexDoesNotExistError unless has_index?
|
22
|
-
@indexes[
|
19
|
+
def index name
|
20
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
21
|
+
raise IndexDoesNotExistError unless has_index? name
|
22
|
+
@indexes[name]
|
23
23
|
end
|
24
24
|
|
25
25
|
# returns true if this table has a index with the provided name, otherwise false
|
26
|
-
def has_index?
|
27
|
-
raise ExpectedSymbolError,
|
28
|
-
@indexes.key?
|
26
|
+
def has_index? name
|
27
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
28
|
+
@indexes.key? name
|
29
29
|
end
|
30
30
|
|
31
31
|
# returns an array of this tables indexes
|
@@ -41,22 +41,22 @@ module DynamicMigrations
|
|
41
41
|
# include_column_names in broken out from index_options, because it is converted from an
|
42
42
|
# array of column names into an array of columns, and then recombined with the other
|
43
43
|
# options which are sent to the index initialize method
|
44
|
-
def add_index
|
45
|
-
if has_index?
|
46
|
-
raise(IndexAlreadyExistsError, "index #{
|
44
|
+
def add_index name, column_names, include_column_names: [], **index_options
|
45
|
+
if has_index? name
|
46
|
+
raise(IndexAlreadyExistsError, "index #{name} already exists")
|
47
47
|
end
|
48
48
|
columns = column_names.map { |column_name| column column_name }
|
49
49
|
include_columns = include_column_names.map { |column_name| column column_name }
|
50
50
|
included_target = self
|
51
51
|
if included_target.is_a? Table
|
52
|
-
new_index = @indexes[
|
52
|
+
new_index = @indexes[name] = Index.new source, included_target, columns, name, include_columns: include_columns, **index_options
|
53
53
|
else
|
54
54
|
raise ModuleIncludedIntoUnexpectedTargetError, included_target
|
55
55
|
end
|
56
56
|
# sort the hash so that the indexes are in alphabetical order by name
|
57
57
|
sorted_indexes = {}
|
58
|
-
@indexes.keys.sort.each do |
|
59
|
-
sorted_indexes[
|
58
|
+
@indexes.keys.sort.each do |name|
|
59
|
+
sorted_indexes[name] = @indexes[name]
|
60
60
|
end
|
61
61
|
@indexes = sorted_indexes
|
62
62
|
# return the new index
|
@@ -23,11 +23,11 @@ module DynamicMigrations
|
|
23
23
|
end
|
24
24
|
|
25
25
|
attr_reader :table
|
26
|
-
attr_reader :
|
26
|
+
attr_reader :name
|
27
27
|
attr_reader :index_type
|
28
28
|
|
29
29
|
# initialize a new object to represent a primary_key in a postgres table
|
30
|
-
def initialize source, table, columns,
|
30
|
+
def initialize source, table, columns, name, index_type: :btree
|
31
31
|
super source
|
32
32
|
raise ExpectedTableError, table unless table.is_a? Table
|
33
33
|
@table = table
|
@@ -42,8 +42,8 @@ module DynamicMigrations
|
|
42
42
|
add_column column
|
43
43
|
end
|
44
44
|
|
45
|
-
raise ExpectedSymbolError,
|
46
|
-
@
|
45
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
46
|
+
@name = name
|
47
47
|
|
48
48
|
raise UnexpectedIndexTypeError, index_type unless INDEX_TYPES.include?(index_type)
|
49
49
|
@index_type = index_type
|
@@ -64,15 +64,15 @@ module DynamicMigrations
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# assert that the provided column exists within this primary keys table
|
67
|
-
unless @table.has_column? column.
|
67
|
+
unless @table.has_column? column.name
|
68
68
|
raise ExpectedArrayOfColumnsError, "One or more columns do not exist in this primary keys table"
|
69
69
|
end
|
70
70
|
|
71
|
-
if @columns.key?(column.
|
72
|
-
raise(DuplicateColumnError, "Column #{column.
|
71
|
+
if @columns.key?(column.name)
|
72
|
+
raise(DuplicateColumnError, "Column #{column.name} already exists in primary_key, or is already included")
|
73
73
|
end
|
74
74
|
|
75
|
-
@columns[column.
|
75
|
+
@columns[column.name] = column
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -29,13 +29,13 @@ module DynamicMigrations
|
|
29
29
|
end
|
30
30
|
|
31
31
|
attr_reader :table
|
32
|
-
attr_reader :
|
32
|
+
attr_reader :name
|
33
33
|
attr_reader :index_type
|
34
34
|
attr_reader :deferrable
|
35
35
|
attr_reader :initially_deferred
|
36
36
|
|
37
37
|
# initialize a new object to represent a unique_constraint in a postgres table
|
38
|
-
def initialize source, table, columns,
|
38
|
+
def initialize source, table, columns, name, index_type: :btree, deferrable: false, initially_deferred: false
|
39
39
|
super source
|
40
40
|
raise ExpectedTableError, table unless table.is_a? Table
|
41
41
|
@table = table
|
@@ -50,8 +50,8 @@ module DynamicMigrations
|
|
50
50
|
add_column column
|
51
51
|
end
|
52
52
|
|
53
|
-
raise ExpectedSymbolError,
|
54
|
-
@
|
53
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
54
|
+
@name = name
|
55
55
|
|
56
56
|
raise UnexpectedIndexTypeError, index_type unless INDEX_TYPES.include?(index_type)
|
57
57
|
@index_type = index_type
|
@@ -82,15 +82,15 @@ module DynamicMigrations
|
|
82
82
|
end
|
83
83
|
|
84
84
|
# assert that the provided column exists within this unique_constraints table
|
85
|
-
unless @table.has_column? column.
|
85
|
+
unless @table.has_column? column.name
|
86
86
|
raise ExpectedArrayOfColumnsError, "One or more columns do not exist in this unique_constraints table"
|
87
87
|
end
|
88
88
|
|
89
|
-
if @columns.key?(column.
|
90
|
-
raise(DuplicateColumnError, "Column #{column.
|
89
|
+
if @columns.key?(column.name)
|
90
|
+
raise(DuplicateColumnError, "Column #{column.name} already exists in unique_constraint, or is already included")
|
91
91
|
end
|
92
92
|
|
93
|
-
@columns[column.
|
93
|
+
@columns[column.name] = column
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -16,16 +16,16 @@ module DynamicMigrations
|
|
16
16
|
|
17
17
|
# returns the unique_constraint object for the provided unique_constraint name, and raises an
|
18
18
|
# error if the unique_constraint does not exist
|
19
|
-
def unique_constraint
|
20
|
-
raise ExpectedSymbolError,
|
21
|
-
raise UniqueConstraintDoesNotExistError unless has_unique_constraint?
|
22
|
-
@unique_constraints[
|
19
|
+
def unique_constraint name
|
20
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
21
|
+
raise UniqueConstraintDoesNotExistError unless has_unique_constraint? name
|
22
|
+
@unique_constraints[name]
|
23
23
|
end
|
24
24
|
|
25
25
|
# returns true if this table has a unique_constraint with the provided name, otherwise false
|
26
|
-
def has_unique_constraint?
|
27
|
-
raise ExpectedSymbolError,
|
28
|
-
@unique_constraints.key?
|
26
|
+
def has_unique_constraint? name
|
27
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
28
|
+
@unique_constraints.key? name
|
29
29
|
end
|
30
30
|
|
31
31
|
# returns an array of this tables unique_constraints
|
@@ -38,21 +38,21 @@ module DynamicMigrations
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# adds a new unique_constraint to this table, and returns it
|
41
|
-
def add_unique_constraint
|
42
|
-
if has_unique_constraint?
|
43
|
-
raise(UniqueConstraintAlreadyExistsError, "unique_constraint #{
|
41
|
+
def add_unique_constraint name, column_names, **unique_constraint_options
|
42
|
+
if has_unique_constraint? name
|
43
|
+
raise(UniqueConstraintAlreadyExistsError, "unique_constraint #{name} already exists")
|
44
44
|
end
|
45
45
|
columns = column_names.map { |column_name| column column_name }
|
46
46
|
included_target = self
|
47
47
|
if included_target.is_a? Table
|
48
|
-
new_unique_constraint = @unique_constraints[
|
48
|
+
new_unique_constraint = @unique_constraints[name] = UniqueConstraint.new source, included_target, columns, name, **unique_constraint_options
|
49
49
|
else
|
50
50
|
raise ModuleIncludedIntoUnexpectedTargetError, included_target
|
51
51
|
end
|
52
52
|
# sort the hash so that the unique_constraints are in alphabetical order by name
|
53
53
|
sorted_unique_constraints = {}
|
54
|
-
@unique_constraints.keys.sort.each do |
|
55
|
-
sorted_unique_constraints[
|
54
|
+
@unique_constraints.keys.sort.each do |name|
|
55
|
+
sorted_unique_constraints[name] = @unique_constraints[name]
|
56
56
|
end
|
57
57
|
@unique_constraints = sorted_unique_constraints
|
58
58
|
# return the new unique_constraint
|
@@ -18,13 +18,13 @@ module DynamicMigrations
|
|
18
18
|
end
|
19
19
|
|
20
20
|
attr_reader :table
|
21
|
-
attr_reader :
|
21
|
+
attr_reader :name
|
22
22
|
attr_reader :check_clause
|
23
23
|
attr_reader :deferrable
|
24
24
|
attr_reader :initially_deferred
|
25
25
|
|
26
26
|
# initialize a new object to represent a validation in a postgres table
|
27
|
-
def initialize source, table, columns,
|
27
|
+
def initialize source, table, columns, name, check_clause, deferrable: false, initially_deferred: false
|
28
28
|
super source
|
29
29
|
raise ExpectedTableError, table unless table.is_a? Table
|
30
30
|
@table = table
|
@@ -39,8 +39,8 @@ module DynamicMigrations
|
|
39
39
|
add_column column
|
40
40
|
end
|
41
41
|
|
42
|
-
raise ExpectedSymbolError,
|
43
|
-
@
|
42
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
43
|
+
@name = name
|
44
44
|
|
45
45
|
raise ExpectedStringError, check_clause unless check_clause.is_a? String
|
46
46
|
@check_clause = check_clause
|
@@ -71,15 +71,15 @@ module DynamicMigrations
|
|
71
71
|
end
|
72
72
|
|
73
73
|
# assert that the provided column exists within this validations table
|
74
|
-
unless @table.has_column? column.
|
74
|
+
unless @table.has_column? column.name
|
75
75
|
raise ExpectedArrayOfColumnsError, "One or more columns do not exist in this validations table"
|
76
76
|
end
|
77
77
|
|
78
|
-
if @columns.key? column.
|
79
|
-
raise(DuplicateColumnError, "Column #{column.
|
78
|
+
if @columns.key? column.name
|
79
|
+
raise(DuplicateColumnError, "Column #{column.name} already exists")
|
80
80
|
end
|
81
81
|
|
82
|
-
@columns[column.
|
82
|
+
@columns[column.name] = column
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -16,16 +16,16 @@ module DynamicMigrations
|
|
16
16
|
|
17
17
|
# returns the validation object for the provided validation name, and raises an
|
18
18
|
# error if the validation does not exist
|
19
|
-
def validation
|
20
|
-
raise ExpectedSymbolError,
|
21
|
-
raise ValidationDoesNotExistError unless has_validation?
|
22
|
-
@validations[
|
19
|
+
def validation name
|
20
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
21
|
+
raise ValidationDoesNotExistError unless has_validation? name
|
22
|
+
@validations[name]
|
23
23
|
end
|
24
24
|
|
25
25
|
# returns true if this table has a validation with the provided name, otherwise false
|
26
|
-
def has_validation?
|
27
|
-
raise ExpectedSymbolError,
|
28
|
-
@validations.key?
|
26
|
+
def has_validation? name
|
27
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
28
|
+
@validations.key? name
|
29
29
|
end
|
30
30
|
|
31
31
|
# returns an array of this tables validations
|
@@ -38,21 +38,21 @@ module DynamicMigrations
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# adds a new validation to this table, and returns it
|
41
|
-
def add_validation
|
42
|
-
if has_validation?
|
43
|
-
raise(ValidationAlreadyExistsError, "Validation #{
|
41
|
+
def add_validation name, column_names, check_clause, **validation_options
|
42
|
+
if has_validation? name
|
43
|
+
raise(ValidationAlreadyExistsError, "Validation #{name} already exists")
|
44
44
|
end
|
45
45
|
columns = column_names.map { |column_name| column column_name }
|
46
46
|
included_target = self
|
47
47
|
if included_target.is_a? Table
|
48
|
-
new_validation = @validations[
|
48
|
+
new_validation = @validations[name] = Validation.new source, included_target, columns, name, check_clause, **validation_options
|
49
49
|
else
|
50
50
|
raise ModuleIncludedIntoUnexpectedTargetError, included_target
|
51
51
|
end
|
52
52
|
# sort the hash so that the validations are in alphabetical order by name
|
53
53
|
sorted_validations = {}
|
54
|
-
@validations.keys.sort.each do |
|
55
|
-
sorted_validations[
|
54
|
+
@validations.keys.sort.each do |name|
|
55
|
+
sorted_validations[name] = @validations[name]
|
56
56
|
end
|
57
57
|
@validations = sorted_validations
|
58
58
|
# return the new validation
|
@@ -20,20 +20,20 @@ module DynamicMigrations
|
|
20
20
|
include UniqueConstraints
|
21
21
|
|
22
22
|
attr_reader :schema
|
23
|
-
attr_reader :
|
23
|
+
attr_reader :name
|
24
24
|
attr_reader :description
|
25
25
|
|
26
26
|
# initialize a new object to represent a postgres table
|
27
|
-
def initialize source, schema,
|
27
|
+
def initialize source, schema, name, description = nil
|
28
28
|
super source
|
29
29
|
raise ExpectedSchemaError, schema unless schema.is_a? Schema
|
30
|
-
raise ExpectedSymbolError,
|
30
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
31
31
|
unless description.nil?
|
32
32
|
raise ExpectedStringError, description unless description.is_a? String
|
33
33
|
@description = description
|
34
34
|
end
|
35
35
|
@schema = schema
|
36
|
-
@
|
36
|
+
@name = name
|
37
37
|
@columns = {}
|
38
38
|
@validations = {}
|
39
39
|
@indexes = {}
|
@@ -47,10 +47,10 @@ module DynamicMigrations
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# add a primary key to this table
|
50
|
-
def add_primary_key
|
50
|
+
def add_primary_key name, column_names, **primary_key_options
|
51
51
|
raise PrimaryKeyAlreadyExistsError if @primary_key
|
52
52
|
columns = column_names.map { |column_name| column column_name }
|
53
|
-
@primary_key = PrimaryKey.new source, self, columns,
|
53
|
+
@primary_key = PrimaryKey.new source, self, columns, name, **primary_key_options
|
54
54
|
end
|
55
55
|
|
56
56
|
# returns true if this table has a primary key, otherwise false
|
@@ -18,15 +18,15 @@ module DynamicMigrations
|
|
18
18
|
end
|
19
19
|
|
20
20
|
attr_reader :database
|
21
|
-
attr_reader :
|
21
|
+
attr_reader :name
|
22
22
|
|
23
23
|
# initialize a new object to represent a postgres schema
|
24
|
-
def initialize source, database,
|
24
|
+
def initialize source, database, name
|
25
25
|
super source
|
26
26
|
raise ExpectedDatabaseError, database unless database.is_a? Database
|
27
|
-
raise ExpectedSymbolError,
|
27
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
28
28
|
@database = database
|
29
|
-
@
|
29
|
+
@name = name
|
30
30
|
@tables = {}
|
31
31
|
end
|
32
32
|
|
@@ -18,14 +18,14 @@ module DynamicMigrations
|
|
18
18
|
include LoadedSchemasBuilder
|
19
19
|
|
20
20
|
attr_reader :server
|
21
|
-
attr_reader :
|
21
|
+
attr_reader :name
|
22
22
|
|
23
23
|
# initialize a new object to represent a postgres database
|
24
|
-
def initialize server,
|
24
|
+
def initialize server, name
|
25
25
|
raise ExpectedServerError, server unless server.is_a? Server
|
26
|
-
raise ExpectedSymbolError,
|
26
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
27
27
|
@server = server
|
28
|
-
@
|
28
|
+
@name = name
|
29
29
|
@configured_schemas = {}
|
30
30
|
@loaded_schemas = {}
|
31
31
|
end
|
@@ -18,15 +18,15 @@ module DynamicMigrations
|
|
18
18
|
@databases = {}
|
19
19
|
end
|
20
20
|
|
21
|
-
def add_database
|
22
|
-
raise ExpectedSymbolError,
|
23
|
-
raise DatabaseAlreadyExistsError, "database `#{
|
24
|
-
@databases[
|
21
|
+
def add_database name
|
22
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
23
|
+
raise DatabaseAlreadyExistsError, "database `#{name}` already exists" if @databases.key? name
|
24
|
+
@databases[name] = Database.new self, name
|
25
25
|
end
|
26
26
|
|
27
|
-
def database
|
28
|
-
raise ExpectedSymbolError,
|
29
|
-
@databases[
|
27
|
+
def database name
|
28
|
+
raise ExpectedSymbolError, name unless name.is_a? Symbol
|
29
|
+
@databases[name]
|
30
30
|
end
|
31
31
|
|
32
32
|
def databases
|
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:
|
4
|
+
version: 2.0.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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|