nandi 0.12.0 → 0.13.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: 1da0a62d10387d4dc47b1b00045d351559d8c3a6a08b9f3de2ad029b7948e0da
4
- data.tar.gz: f56710ba940ee97e004113b9d96aa6a5e4cc34b963f9c2d5dcbd8d3ae6c4b893
3
+ metadata.gz: 6e12cc00673e41d4494ea444a6a44524cca908c7bda4a315bd681dbec9cf7563
4
+ data.tar.gz: 29f0803224e74092b1bce4eaa673cc811bde033e0b9cd72359390094e34a62f9
5
5
  SHA512:
6
- metadata.gz: 5f9a1879fa3f414c020703cf521200a1d436f2af0da8b7051beadd91bbadf9556f3e811eef17d842e54b8c962b4051529f347b8900dda3ffe5c887bc4565928f
7
- data.tar.gz: fcbbc52d37437d8052016e3ff1182f3b603994ab002827ef7e6fbb182ee2a816ff383abde467f0c12f99da54141cbe8ffccb99748950143d047f04233e220733
6
+ metadata.gz: 9987773dcba43ad2750a7c2ea9fcb2640d9ced6ede820ef43d49bd4ee155b55d2b23bddaf0a88569067d6ab4b2730f40d95e5c1e1589786a71bb355f4ef4d682
7
+ data.tar.gz: 13804be5be06737df766ee92f7afa52da870553183566c6fdfa25522883accbcbfe624013cf4411aca1da0f199b549650e17e638796a7b4f2dfc53ec1c8a0080
data/README.md CHANGED
@@ -4,7 +4,7 @@ Friendly Postgres migrations for people who don't want to take down their databa
4
4
 
5
5
  ## Supported
6
6
 
7
- - Ruby 2.5 or above
7
+ - Ruby 2.6 or above
8
8
  - Rails 5.2 or above
9
9
  - Postgres 11 or above
10
10
 
@@ -356,16 +356,16 @@ db/safe_migrations/20190424123727_add_foreign_key_on_bars_to_foos.rb
356
356
  db/safe_migrations/20190424123728_validate_foreign_key_on_bars_to_foos.rb
357
357
  ```
358
358
 
359
- If you're adding the constraint to a column that already exists, you can use the `--no-column` flag to skip the first migration:
359
+ If you're adding the constraint to a column that already exists, you can use the `--no-create-column` flag to skip the first migration:
360
360
 
361
361
  ```
362
- rails generate nandi:foreign_key foos bars --no-column
362
+ rails generate nandi:foreign_key foos bars --no-create-column
363
363
  ```
364
364
 
365
365
  If your foreign key column is named differently, you can override it with the `--column` flag as seen in this example:
366
366
 
367
367
  ```
368
- rails generate nandi:foreign_key foos bar --no-column --column special_bar_ids
368
+ rails generate nandi:foreign_key foos bar --no-create-column --column special_bar_ids
369
369
  ```
370
370
 
371
371
  We generate the name of your foreign key for you. If you want or need to override it (e.g. if it exceeds the max length of a constraint name in Postgres), you can use the `--name` flag:
@@ -0,0 +1,31 @@
1
+ Description:
2
+ Generates new database indices
3
+
4
+ Example:
5
+ rails generate nandi:index table_name index_col
6
+
7
+ This will create:
8
+ db/safe_migrations/20190424123727_add_index_on_index_col_to_table_name.rb
9
+
10
+ or
11
+
12
+ rails generate nandi:index table_name_1,table_name_2 index_col
13
+
14
+ This will create:
15
+ db/safe_migrations/20190424123727_add_index_on_index_col_to_table_name_1.rb
16
+ db/safe_migrations/20190424123728_add_index_on_index_col_to_table_name_2.rb
17
+
18
+ or
19
+
20
+ rails generate nandi:index table_name index_col_1,index_col_2
21
+
22
+ This will create:
23
+ db/safe_migrations/20190424123727_add_index_on_index_col_1_index_col_2_to_table_name.rb
24
+
25
+ or
26
+
27
+ rails generate nandi:index table_name index_col --index_name bespoke_idx_name
28
+
29
+ This will create:
30
+ db/safe_migrations/20190424123727_add_index_on_index_col_to_table_name.rb
31
+ with the specified bespoke index name
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "nandi/formatting"
5
+
6
+ module Nandi
7
+ class IndexGenerator < Rails::Generators::Base
8
+ include Nandi::Formatting
9
+
10
+ argument :tables, type: :string
11
+ argument :columns, type: :string
12
+ class_option :index_name, type: :string
13
+
14
+ source_root File.expand_path("templates", __dir__)
15
+
16
+ attr_reader :add_index_name, :index_name, :table, :columns
17
+
18
+ def add_index
19
+ tables_list = tables.split(",")
20
+ @columns = columns.split(",")
21
+
22
+ tables_list.each_with_index do |table, idx|
23
+ next if table.empty?
24
+
25
+ @table = table.to_sym
26
+
27
+ @add_index_name = "add_index_on_#{columns.join('_')}_to_#{table}"
28
+ @index_name = (
29
+ override_index_name || "idx_#{table}_on_#{columns.join('_')}"
30
+ ).to_sym
31
+
32
+ template(
33
+ "add_index.rb",
34
+ "#{base_path}/#{timestamp(idx)}_#{add_index_name}.rb",
35
+ )
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def timestamp(offset = 0)
42
+ (Time.now.utc + offset).strftime("%Y%m%d%H%M%S")
43
+ end
44
+
45
+ def base_path
46
+ Nandi.config.migration_directory || "db/safe_migrations"
47
+ end
48
+
49
+ def override_index_name
50
+ options["index_name"]&.to_sym
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= add_index_name.camelize %> < Nandi::Migration
4
+ def up
5
+ add_index <%= format_value(table) %>,
6
+ %i<%= format_value(columns).tr('"', '') %>,
7
+ name: <%= format_value(index_name) %>
8
+ end
9
+
10
+ def down
11
+ remove_index <%= format_value(table) %>,
12
+ %i<%= format_value(columns).tr('"', '') %>
13
+ end
14
+ end
@@ -24,7 +24,7 @@ module Nandi
24
24
 
25
25
  unless validation.valid?
26
26
  raise InvalidMigrationError, "Migration #{source_file_path} " \
27
- "is not valid:\n#{validation.error_list}"
27
+ "is not valid:\n#{validation.error_list}"
28
28
  end
29
29
 
30
30
  self
data/lib/nandi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nandi
4
- VERSION = "0.12.0"
4
+ VERSION = "0.13.0"
5
5
  end
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.12.0
4
+ version: 0.13.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: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 2.25.0
103
+ version: 3.3.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 2.25.0
110
+ version: 3.3.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: pry-byebug
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +234,9 @@ files:
234
234
  - lib/generators/nandi/foreign_key/templates/add_foreign_key.rb
235
235
  - lib/generators/nandi/foreign_key/templates/add_reference.rb
236
236
  - lib/generators/nandi/foreign_key/templates/validate_foreign_key.rb
237
+ - lib/generators/nandi/index/USAGE
238
+ - lib/generators/nandi/index/index_generator.rb
239
+ - lib/generators/nandi/index/templates/add_index.rb
237
240
  - lib/generators/nandi/migration/USAGE
238
241
  - lib/generators/nandi/migration/migration_generator.rb
239
242
  - lib/generators/nandi/migration/templates/migration.rb
@@ -302,7 +305,8 @@ files:
302
305
  homepage: https://github.com/gocardless/nandi
303
306
  licenses:
304
307
  - MIT
305
- metadata: {}
308
+ metadata:
309
+ rubygems_mfa_required: 'true'
306
310
  post_install_message:
307
311
  rdoc_options: []
308
312
  require_paths:
@@ -311,7 +315,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
311
315
  requirements:
312
316
  - - ">="
313
317
  - !ruby/object:Gem::Version
314
- version: 2.4.0
318
+ version: 2.6.0
315
319
  required_rubygems_version: !ruby/object:Gem::Requirement
316
320
  requirements:
317
321
  - - ">="