nandi 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +483 -0
  3. data/Rakefile +8 -0
  4. data/exe/nandi-enforce +36 -0
  5. data/lib/generators/nandi/check_constraint/USAGE +19 -0
  6. data/lib/generators/nandi/check_constraint/check_constraint_generator.rb +52 -0
  7. data/lib/generators/nandi/check_constraint/templates/add_check_constraint.rb +15 -0
  8. data/lib/generators/nandi/check_constraint/templates/validate_check_constraint.rb +9 -0
  9. data/lib/generators/nandi/compile/USAGE +19 -0
  10. data/lib/generators/nandi/compile/compile_generator.rb +62 -0
  11. data/lib/generators/nandi/foreign_key/USAGE +47 -0
  12. data/lib/generators/nandi/foreign_key/foreign_key_generator.rb +91 -0
  13. data/lib/generators/nandi/foreign_key/templates/add_foreign_key.rb +13 -0
  14. data/lib/generators/nandi/foreign_key/templates/add_reference.rb +11 -0
  15. data/lib/generators/nandi/foreign_key/templates/validate_foreign_key.rb +9 -0
  16. data/lib/generators/nandi/migration/USAGE +9 -0
  17. data/lib/generators/nandi/migration/migration_generator.rb +24 -0
  18. data/lib/generators/nandi/migration/templates/migration.rb +13 -0
  19. data/lib/generators/nandi/not_null_check/USAGE +19 -0
  20. data/lib/generators/nandi/not_null_check/not_null_check_generator.rb +56 -0
  21. data/lib/generators/nandi/not_null_check/templates/add_not_null_check.rb +11 -0
  22. data/lib/generators/nandi/not_null_check/templates/validate_not_null_check.rb +9 -0
  23. data/lib/nandi.rb +35 -0
  24. data/lib/nandi/compiled_migration.rb +86 -0
  25. data/lib/nandi/config.rb +126 -0
  26. data/lib/nandi/file_diff.rb +32 -0
  27. data/lib/nandi/file_matcher.rb +72 -0
  28. data/lib/nandi/formatting.rb +79 -0
  29. data/lib/nandi/instructions.rb +21 -0
  30. data/lib/nandi/instructions/add_check_constraint.rb +23 -0
  31. data/lib/nandi/instructions/add_column.rb +24 -0
  32. data/lib/nandi/instructions/add_foreign_key.rb +40 -0
  33. data/lib/nandi/instructions/add_index.rb +50 -0
  34. data/lib/nandi/instructions/add_reference.rb +23 -0
  35. data/lib/nandi/instructions/change_column_default.rb +23 -0
  36. data/lib/nandi/instructions/create_table.rb +83 -0
  37. data/lib/nandi/instructions/drop_constraint.rb +22 -0
  38. data/lib/nandi/instructions/drop_table.rb +21 -0
  39. data/lib/nandi/instructions/irreversible_migration.rb +15 -0
  40. data/lib/nandi/instructions/remove_column.rb +23 -0
  41. data/lib/nandi/instructions/remove_index.rb +41 -0
  42. data/lib/nandi/instructions/remove_not_null_constraint.rb +22 -0
  43. data/lib/nandi/instructions/remove_reference.rb +23 -0
  44. data/lib/nandi/instructions/validate_constraint.rb +22 -0
  45. data/lib/nandi/lockfile.rb +58 -0
  46. data/lib/nandi/migration.rb +388 -0
  47. data/lib/nandi/renderers.rb +7 -0
  48. data/lib/nandi/renderers/active_record.rb +13 -0
  49. data/lib/nandi/renderers/active_record/generate.rb +59 -0
  50. data/lib/nandi/renderers/active_record/instructions.rb +146 -0
  51. data/lib/nandi/safe_migration_enforcer.rb +143 -0
  52. data/lib/nandi/timeout_policies.rb +38 -0
  53. data/lib/nandi/timeout_policies/access_exclusive.rb +54 -0
  54. data/lib/nandi/timeout_policies/concurrent.rb +64 -0
  55. data/lib/nandi/validation.rb +11 -0
  56. data/lib/nandi/validation/add_column_validator.rb +43 -0
  57. data/lib/nandi/validation/add_reference_validator.rb +38 -0
  58. data/lib/nandi/validation/each_validator.rb +34 -0
  59. data/lib/nandi/validation/failure_helpers.rb +35 -0
  60. data/lib/nandi/validation/remove_index_validator.rb +30 -0
  61. data/lib/nandi/validation/result.rb +30 -0
  62. data/lib/nandi/validation/timeout_validator.rb +37 -0
  63. data/lib/nandi/validator.rb +102 -0
  64. data/lib/templates/nandi/renderers/active_record/generate/show.rb.erb +27 -0
  65. data/lib/templates/nandi/renderers/active_record/instructions/add_check_constraint/show.rb.erb +7 -0
  66. data/lib/templates/nandi/renderers/active_record/instructions/add_column/show.rb.erb +6 -0
  67. data/lib/templates/nandi/renderers/active_record/instructions/add_foreign_key/show.rb.erb +5 -0
  68. data/lib/templates/nandi/renderers/active_record/instructions/add_index/show.rb.erb +5 -0
  69. data/lib/templates/nandi/renderers/active_record/instructions/add_reference/show.rb.erb +5 -0
  70. data/lib/templates/nandi/renderers/active_record/instructions/change_column_default/show.rb.erb +1 -0
  71. data/lib/templates/nandi/renderers/active_record/instructions/create_table/show.rb.erb +8 -0
  72. data/lib/templates/nandi/renderers/active_record/instructions/drop_constraint/show.rb.erb +4 -0
  73. data/lib/templates/nandi/renderers/active_record/instructions/drop_table/show.rb.erb +1 -0
  74. data/lib/templates/nandi/renderers/active_record/instructions/irreversible_migration/show.rb.erb +1 -0
  75. data/lib/templates/nandi/renderers/active_record/instructions/remove_column/show.rb.erb +5 -0
  76. data/lib/templates/nandi/renderers/active_record/instructions/remove_index/show.rb.erb +4 -0
  77. data/lib/templates/nandi/renderers/active_record/instructions/remove_not_null_constraint/show.rb.erb +1 -0
  78. data/lib/templates/nandi/renderers/active_record/instructions/remove_reference/show.rb.erb +5 -0
  79. data/lib/templates/nandi/renderers/active_record/instructions/validate_constraint/show.rb.erb +3 -0
  80. metadata +317 -0
@@ -0,0 +1,7 @@
1
+ execute <<-SQL
2
+ ALTER TABLE <%= table %>
3
+ ADD CONSTRAINT <%= name %>
4
+ CHECK (<%= check %>)
5
+ NOT VALID
6
+ SQL
7
+
@@ -0,0 +1,6 @@
1
+ add_column(
2
+ <%= table %>,
3
+ <%= name %>,
4
+ <%= type %>,
5
+ <%= extra_args %>
6
+ )
@@ -0,0 +1,5 @@
1
+ add_foreign_key(
2
+ <%= table %>,
3
+ <%= target %>,
4
+ <%= extra_args %>
5
+ )
@@ -0,0 +1,5 @@
1
+ add_index(
2
+ <%= table %>,
3
+ <%= fields %>,
4
+ <%= extra_args %>
5
+ )
@@ -0,0 +1,5 @@
1
+ add_reference(
2
+ <%= table %>,
3
+ <%= ref_name %>,
4
+ <%= extra_args %>
5
+ )
@@ -0,0 +1 @@
1
+ change_column_default <%= table %>, <%= column %>, <%= value %>
@@ -0,0 +1,8 @@
1
+ create_table <%= table %><% if extra_args? %>, <%= extra_args %><% end %> do |t|
2
+ <% columns.each do |column| %>
3
+ t.column <%= column.name %>, <%= column.type %><%= ", #{column.args}" if column.args %>
4
+ <% end %>
5
+ <% if timestamps? %>
6
+ t.timestamps<%= " #{timestamps_args}" if timestamps_args? %>
7
+ <% end %>
8
+ end
@@ -0,0 +1,4 @@
1
+ execute <<-SQL
2
+ ALTER TABLE <%= table %> DROP CONSTRAINT <%= name %>
3
+ SQL
4
+
@@ -0,0 +1 @@
1
+ raise ActiveRecord::IrreversibleMigration
@@ -0,0 +1,5 @@
1
+ remove_column(
2
+ <%= table %>,
3
+ <%= name %>,
4
+ <%= extra_args %>
5
+ )
@@ -0,0 +1,4 @@
1
+ remove_index(
2
+ <%= table %>,
3
+ <%= extra_args %>
4
+ )
@@ -0,0 +1 @@
1
+ change_column_null <%= table %>, <%= column %>, true
@@ -0,0 +1,5 @@
1
+ remove_reference(
2
+ <%= table %>,
3
+ <%= ref_name %>,
4
+ <%= extra_args %>
5
+ )
@@ -0,0 +1,3 @@
1
+ execute <<-SQL
2
+ ALTER TABLE <%= table %> VALIDATE CONSTRAINT <%= name %>
3
+ SQL
metadata ADDED
@@ -0,0 +1,317 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nandi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - James Turley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cells
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-monads
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tilt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '11.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '11.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: gc_ruboconfig
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.3.14
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.3.14
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.7.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.7.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 5.2.3
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 5.2.3
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '10.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '10.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec_junit_formatter
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.4'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.4'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.61'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.61'
195
+ - !ruby/object:Gem::Dependency
196
+ name: yard
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '0.9'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '0.9'
209
+ description:
210
+ email:
211
+ - jamesturley@gocardless.com
212
+ executables:
213
+ - nandi-enforce
214
+ extensions: []
215
+ extra_rdoc_files: []
216
+ files:
217
+ - README.md
218
+ - Rakefile
219
+ - exe/nandi-enforce
220
+ - lib/generators/nandi/check_constraint/USAGE
221
+ - lib/generators/nandi/check_constraint/check_constraint_generator.rb
222
+ - lib/generators/nandi/check_constraint/templates/add_check_constraint.rb
223
+ - lib/generators/nandi/check_constraint/templates/validate_check_constraint.rb
224
+ - lib/generators/nandi/compile/USAGE
225
+ - lib/generators/nandi/compile/compile_generator.rb
226
+ - lib/generators/nandi/foreign_key/USAGE
227
+ - lib/generators/nandi/foreign_key/foreign_key_generator.rb
228
+ - lib/generators/nandi/foreign_key/templates/add_foreign_key.rb
229
+ - lib/generators/nandi/foreign_key/templates/add_reference.rb
230
+ - lib/generators/nandi/foreign_key/templates/validate_foreign_key.rb
231
+ - lib/generators/nandi/migration/USAGE
232
+ - lib/generators/nandi/migration/migration_generator.rb
233
+ - lib/generators/nandi/migration/templates/migration.rb
234
+ - lib/generators/nandi/not_null_check/USAGE
235
+ - lib/generators/nandi/not_null_check/not_null_check_generator.rb
236
+ - lib/generators/nandi/not_null_check/templates/add_not_null_check.rb
237
+ - lib/generators/nandi/not_null_check/templates/validate_not_null_check.rb
238
+ - lib/nandi.rb
239
+ - lib/nandi/compiled_migration.rb
240
+ - lib/nandi/config.rb
241
+ - lib/nandi/file_diff.rb
242
+ - lib/nandi/file_matcher.rb
243
+ - lib/nandi/formatting.rb
244
+ - lib/nandi/instructions.rb
245
+ - lib/nandi/instructions/add_check_constraint.rb
246
+ - lib/nandi/instructions/add_column.rb
247
+ - lib/nandi/instructions/add_foreign_key.rb
248
+ - lib/nandi/instructions/add_index.rb
249
+ - lib/nandi/instructions/add_reference.rb
250
+ - lib/nandi/instructions/change_column_default.rb
251
+ - lib/nandi/instructions/create_table.rb
252
+ - lib/nandi/instructions/drop_constraint.rb
253
+ - lib/nandi/instructions/drop_table.rb
254
+ - lib/nandi/instructions/irreversible_migration.rb
255
+ - lib/nandi/instructions/remove_column.rb
256
+ - lib/nandi/instructions/remove_index.rb
257
+ - lib/nandi/instructions/remove_not_null_constraint.rb
258
+ - lib/nandi/instructions/remove_reference.rb
259
+ - lib/nandi/instructions/validate_constraint.rb
260
+ - lib/nandi/lockfile.rb
261
+ - lib/nandi/migration.rb
262
+ - lib/nandi/renderers.rb
263
+ - lib/nandi/renderers/active_record.rb
264
+ - lib/nandi/renderers/active_record/generate.rb
265
+ - lib/nandi/renderers/active_record/instructions.rb
266
+ - lib/nandi/safe_migration_enforcer.rb
267
+ - lib/nandi/timeout_policies.rb
268
+ - lib/nandi/timeout_policies/access_exclusive.rb
269
+ - lib/nandi/timeout_policies/concurrent.rb
270
+ - lib/nandi/validation.rb
271
+ - lib/nandi/validation/add_column_validator.rb
272
+ - lib/nandi/validation/add_reference_validator.rb
273
+ - lib/nandi/validation/each_validator.rb
274
+ - lib/nandi/validation/failure_helpers.rb
275
+ - lib/nandi/validation/remove_index_validator.rb
276
+ - lib/nandi/validation/result.rb
277
+ - lib/nandi/validation/timeout_validator.rb
278
+ - lib/nandi/validator.rb
279
+ - lib/templates/nandi/renderers/active_record/generate/show.rb.erb
280
+ - lib/templates/nandi/renderers/active_record/instructions/add_check_constraint/show.rb.erb
281
+ - lib/templates/nandi/renderers/active_record/instructions/add_column/show.rb.erb
282
+ - lib/templates/nandi/renderers/active_record/instructions/add_foreign_key/show.rb.erb
283
+ - 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
+ - lib/templates/nandi/renderers/active_record/instructions/change_column_default/show.rb.erb
286
+ - lib/templates/nandi/renderers/active_record/instructions/create_table/show.rb.erb
287
+ - lib/templates/nandi/renderers/active_record/instructions/drop_constraint/show.rb.erb
288
+ - lib/templates/nandi/renderers/active_record/instructions/drop_table/show.rb.erb
289
+ - lib/templates/nandi/renderers/active_record/instructions/irreversible_migration/show.rb.erb
290
+ - lib/templates/nandi/renderers/active_record/instructions/remove_column/show.rb.erb
291
+ - lib/templates/nandi/renderers/active_record/instructions/remove_index/show.rb.erb
292
+ - 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
+ - lib/templates/nandi/renderers/active_record/instructions/validate_constraint/show.rb.erb
295
+ homepage:
296
+ licenses: []
297
+ metadata: {}
298
+ post_install_message:
299
+ rdoc_options: []
300
+ require_paths:
301
+ - lib
302
+ required_ruby_version: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ required_rubygems_version: !ruby/object:Gem::Requirement
308
+ requirements:
309
+ - - ">="
310
+ - !ruby/object:Gem::Version
311
+ version: '0'
312
+ requirements: []
313
+ rubygems_version: 3.0.3
314
+ signing_key:
315
+ specification_version: 4
316
+ summary: Fear-free migrations for PostgreSQL
317
+ test_files: []