nandi 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -8
- data/lib/generators/nandi/foreign_key/foreign_key_generator.rb +3 -3
- data/lib/generators/nandi/foreign_key/templates/add_reference.rb +2 -2
- data/lib/nandi/instructions.rb +0 -2
- data/lib/nandi/migration.rb +0 -25
- data/lib/nandi/renderers/active_record/instructions.rb +0 -12
- data/lib/nandi/validation.rb +0 -1
- data/lib/nandi/validation/each_validator.rb +0 -2
- data/lib/nandi/version.rb +5 -0
- metadata +16 -13
- data/lib/nandi/instructions/add_reference.rb +0 -23
- data/lib/nandi/instructions/remove_reference.rb +0 -23
- data/lib/nandi/validation/add_reference_validator.rb +0 -38
- data/lib/templates/nandi/renderers/active_record/instructions/add_reference/show.rb.erb +0 -5
- data/lib/templates/nandi/renderers/active_record/instructions/remove_reference/show.rb.erb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba61fdd052ec58212031846c92ad947cb1f7cb8c033271b101f5973a2b7074f6
|
4
|
+
data.tar.gz: b0c30216fb5544927d1d3b47ef0ad87d935a9ea8859c37a8779662a65f88d9f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4c0ecfcb5e1a84c4a8b2e0721f4e48a8abff3f6bde78f04184544e9004987a4f155eebb3342b780fc793bc2d5104a8a98d7d25c6fcc9f8da43cdd70e0b5f9fd
|
7
|
+
data.tar.gz: aedffb405097c5d9e988e001eab0c929ed0fab64b1b9b04a534051fa59aa16634c3c9071bf5daf31b7c416bfa94679b020685bd8c201c78d0552ebbcf60e0a75
|
data/README.md
CHANGED
@@ -161,11 +161,11 @@ We now have three new migration files:
|
|
161
161
|
|
162
162
|
class AddReferenceOnFoosToBars < Nandi::Migration
|
163
163
|
def up
|
164
|
-
|
164
|
+
add_column :foos, :bar_id, :bigint
|
165
165
|
end
|
166
166
|
|
167
167
|
def down
|
168
|
-
|
168
|
+
remove_column :foos, :bar_id
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -286,12 +286,6 @@ create_table :widgets do |t|
|
|
286
286
|
end
|
287
287
|
```
|
288
288
|
|
289
|
-
### `#add_reference(table, ref_name, **extra_args)`
|
290
|
-
Adds a new reference column. Nandi will validate that the foreign key flag is not set to true; use `add_foreign_key` and `validate_foreign_key` instead!
|
291
|
-
|
292
|
-
### `#remove_reference(table, ref_name, **extra_args)`
|
293
|
-
Removes a reference column.
|
294
|
-
|
295
289
|
### `#remove_column(table, name, **extra_args)`
|
296
290
|
Remove an existing column.
|
297
291
|
|
@@ -11,7 +11,7 @@ module Nandi
|
|
11
11
|
argument :target, type: :string
|
12
12
|
class_option :name, type: :string
|
13
13
|
class_option :column, type: :string
|
14
|
-
class_option :type, type: :string
|
14
|
+
class_option :type, type: :string, default: "bigint"
|
15
15
|
class_option :no_create_column, type: :boolean
|
16
16
|
class_option :validation_timeout, type: :numeric, default: 15 * 60 * 1000
|
17
17
|
|
@@ -61,11 +61,11 @@ module Nandi
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def type
|
64
|
-
options["type"]
|
64
|
+
options["type"].to_sym
|
65
65
|
end
|
66
66
|
|
67
67
|
def reference_name
|
68
|
-
target.singularize.to_sym
|
68
|
+
"#{target.singularize}_id".to_sym
|
69
69
|
end
|
70
70
|
|
71
71
|
def base_path
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
class <%= add_reference_name.camelize %> < Nandi::Migration
|
4
4
|
def up
|
5
|
-
|
5
|
+
add_column <%= format_value(table) %>, <%= format_value(reference_name) %>, <%= format_value(type) %>
|
6
6
|
end
|
7
7
|
|
8
8
|
def down
|
9
|
-
|
9
|
+
remove_column <%= format_value(table) %>, <%= format_value(reference_name) %>
|
10
10
|
end
|
11
11
|
end
|
data/lib/nandi/instructions.rb
CHANGED
@@ -5,8 +5,6 @@ require "nandi/instructions/remove_index"
|
|
5
5
|
require "nandi/instructions/create_table"
|
6
6
|
require "nandi/instructions/drop_table"
|
7
7
|
require "nandi/instructions/add_column"
|
8
|
-
require "nandi/instructions/add_reference"
|
9
|
-
require "nandi/instructions/remove_reference"
|
10
8
|
require "nandi/instructions/remove_column"
|
11
9
|
require "nandi/instructions/add_foreign_key"
|
12
10
|
require "nandi/instructions/drop_constraint"
|
data/lib/nandi/migration.rb
CHANGED
@@ -188,31 +188,6 @@ module Nandi
|
|
188
188
|
)
|
189
189
|
end
|
190
190
|
|
191
|
-
# Adds a new reference column. Nandi will validate that the foreign key flag
|
192
|
-
# is not set to true; use `add_foreign_key` and `validate_foreign_key` instead!
|
193
|
-
# @param table [Symbol, String] The name of the table to add the column to
|
194
|
-
# @param ref_name [Symbol, String] The referenced column name
|
195
|
-
# @param kwargs [Hash] Arbitrary options to be passed to the backend.
|
196
|
-
def add_reference(table, ref_name, **kwargs)
|
197
|
-
current_instructions << Instructions::AddReference.new(
|
198
|
-
table: table,
|
199
|
-
ref_name: ref_name,
|
200
|
-
**kwargs,
|
201
|
-
)
|
202
|
-
end
|
203
|
-
|
204
|
-
# Removes a reference column.
|
205
|
-
# @param table [Symbol, String] The name of the table to remove the reference from
|
206
|
-
# @param ref_name [Symbol, String] The referenced column name
|
207
|
-
# @param kwargs [Hash] Arbitrary options to be passed to the backend.
|
208
|
-
def remove_reference(table, ref_name, **kwargs)
|
209
|
-
current_instructions << Instructions::RemoveReference.new(
|
210
|
-
table: table,
|
211
|
-
ref_name: ref_name,
|
212
|
-
**kwargs,
|
213
|
-
)
|
214
|
-
end
|
215
|
-
|
216
191
|
# Remove an existing column.
|
217
192
|
# @param table [Symbol, String] The name of the table to remove the column
|
218
193
|
# from.
|
@@ -82,18 +82,6 @@ module Nandi
|
|
82
82
|
formatted_property :extra_args
|
83
83
|
end
|
84
84
|
|
85
|
-
class AddReferenceCell < Base
|
86
|
-
formatted_property :table
|
87
|
-
formatted_property :ref_name
|
88
|
-
formatted_property :extra_args
|
89
|
-
end
|
90
|
-
|
91
|
-
class RemoveReferenceCell < Base
|
92
|
-
formatted_property :table
|
93
|
-
formatted_property :ref_name
|
94
|
-
formatted_property :extra_args
|
95
|
-
end
|
96
|
-
|
97
85
|
class RemoveColumnCell < Base
|
98
86
|
formatted_property :table
|
99
87
|
formatted_property :name
|
data/lib/nandi/validation.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nandi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- GoCardless Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -142,14 +142,20 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '12.3'
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 12.3.3
|
146
149
|
type: :development
|
147
150
|
prerelease: false
|
148
151
|
version_requirements: !ruby/object:Gem::Requirement
|
149
152
|
requirements:
|
150
153
|
- - "~>"
|
151
154
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
155
|
+
version: '12.3'
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 12.3.3
|
153
159
|
- !ruby/object:Gem::Dependency
|
154
160
|
name: rspec
|
155
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -208,7 +214,7 @@ dependencies:
|
|
208
214
|
version: '0.9'
|
209
215
|
description:
|
210
216
|
email:
|
211
|
-
-
|
217
|
+
- engineering@gocardless.com
|
212
218
|
executables:
|
213
219
|
- nandi-enforce
|
214
220
|
extensions: []
|
@@ -246,7 +252,6 @@ files:
|
|
246
252
|
- lib/nandi/instructions/add_column.rb
|
247
253
|
- lib/nandi/instructions/add_foreign_key.rb
|
248
254
|
- lib/nandi/instructions/add_index.rb
|
249
|
-
- lib/nandi/instructions/add_reference.rb
|
250
255
|
- lib/nandi/instructions/change_column_default.rb
|
251
256
|
- lib/nandi/instructions/create_table.rb
|
252
257
|
- lib/nandi/instructions/drop_constraint.rb
|
@@ -255,7 +260,6 @@ files:
|
|
255
260
|
- lib/nandi/instructions/remove_column.rb
|
256
261
|
- lib/nandi/instructions/remove_index.rb
|
257
262
|
- lib/nandi/instructions/remove_not_null_constraint.rb
|
258
|
-
- lib/nandi/instructions/remove_reference.rb
|
259
263
|
- lib/nandi/instructions/validate_constraint.rb
|
260
264
|
- lib/nandi/lockfile.rb
|
261
265
|
- lib/nandi/migration.rb
|
@@ -269,19 +273,18 @@ files:
|
|
269
273
|
- lib/nandi/timeout_policies/concurrent.rb
|
270
274
|
- lib/nandi/validation.rb
|
271
275
|
- lib/nandi/validation/add_column_validator.rb
|
272
|
-
- lib/nandi/validation/add_reference_validator.rb
|
273
276
|
- lib/nandi/validation/each_validator.rb
|
274
277
|
- lib/nandi/validation/failure_helpers.rb
|
275
278
|
- lib/nandi/validation/remove_index_validator.rb
|
276
279
|
- lib/nandi/validation/result.rb
|
277
280
|
- lib/nandi/validation/timeout_validator.rb
|
278
281
|
- lib/nandi/validator.rb
|
282
|
+
- lib/nandi/version.rb
|
279
283
|
- lib/templates/nandi/renderers/active_record/generate/show.rb.erb
|
280
284
|
- lib/templates/nandi/renderers/active_record/instructions/add_check_constraint/show.rb.erb
|
281
285
|
- lib/templates/nandi/renderers/active_record/instructions/add_column/show.rb.erb
|
282
286
|
- lib/templates/nandi/renderers/active_record/instructions/add_foreign_key/show.rb.erb
|
283
287
|
- lib/templates/nandi/renderers/active_record/instructions/add_index/show.rb.erb
|
284
|
-
- lib/templates/nandi/renderers/active_record/instructions/add_reference/show.rb.erb
|
285
288
|
- lib/templates/nandi/renderers/active_record/instructions/change_column_default/show.rb.erb
|
286
289
|
- lib/templates/nandi/renderers/active_record/instructions/create_table/show.rb.erb
|
287
290
|
- lib/templates/nandi/renderers/active_record/instructions/drop_constraint/show.rb.erb
|
@@ -290,10 +293,10 @@ files:
|
|
290
293
|
- lib/templates/nandi/renderers/active_record/instructions/remove_column/show.rb.erb
|
291
294
|
- lib/templates/nandi/renderers/active_record/instructions/remove_index/show.rb.erb
|
292
295
|
- lib/templates/nandi/renderers/active_record/instructions/remove_not_null_constraint/show.rb.erb
|
293
|
-
- lib/templates/nandi/renderers/active_record/instructions/remove_reference/show.rb.erb
|
294
296
|
- lib/templates/nandi/renderers/active_record/instructions/validate_constraint/show.rb.erb
|
295
|
-
homepage:
|
296
|
-
licenses:
|
297
|
+
homepage: https://github.com/gocardless/nandi
|
298
|
+
licenses:
|
299
|
+
- MIT
|
297
300
|
metadata: {}
|
298
301
|
post_install_message:
|
299
302
|
rdoc_options: []
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nandi
|
4
|
-
module Instructions
|
5
|
-
class AddReference
|
6
|
-
attr_reader :table, :ref_name, :extra_args
|
7
|
-
|
8
|
-
def initialize(table:, ref_name:, **kwargs)
|
9
|
-
@table = table
|
10
|
-
@ref_name = ref_name
|
11
|
-
@extra_args = kwargs
|
12
|
-
end
|
13
|
-
|
14
|
-
def procedure
|
15
|
-
:add_reference
|
16
|
-
end
|
17
|
-
|
18
|
-
def lock
|
19
|
-
Nandi::Migration::LockWeights::ACCESS_EXCLUSIVE
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nandi
|
4
|
-
module Instructions
|
5
|
-
class RemoveReference
|
6
|
-
attr_reader :table, :ref_name, :extra_args
|
7
|
-
|
8
|
-
def initialize(table:, ref_name:, **kwargs)
|
9
|
-
@table = table
|
10
|
-
@ref_name = ref_name
|
11
|
-
@extra_args = kwargs
|
12
|
-
end
|
13
|
-
|
14
|
-
def procedure
|
15
|
-
:remove_reference
|
16
|
-
end
|
17
|
-
|
18
|
-
def lock
|
19
|
-
Nandi::Migration::LockWeights::ACCESS_EXCLUSIVE
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "nandi/validation/failure_helpers"
|
4
|
-
|
5
|
-
module Nandi
|
6
|
-
module Validation
|
7
|
-
class AddReferenceValidator
|
8
|
-
include Nandi::Validation::FailureHelpers
|
9
|
-
|
10
|
-
def self.call(instruction)
|
11
|
-
new(instruction).call
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(instruction)
|
15
|
-
@instruction = instruction
|
16
|
-
end
|
17
|
-
|
18
|
-
def call
|
19
|
-
foreign_key = instruction.extra_args.fetch(:foreign_key) { false }
|
20
|
-
|
21
|
-
assert(
|
22
|
-
!foreign_key,
|
23
|
-
foreign_key_message,
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def foreign_key_message
|
30
|
-
"Adding a foreign key constraint must be done in two separate migrations. " \
|
31
|
-
"Use the `add_foreign_key` and `validate_foreign_key` methods, or the " \
|
32
|
-
"nandi:foreign_key generator, to do this."
|
33
|
-
end
|
34
|
-
|
35
|
-
attr_reader :instruction
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|