nandi 0.11.3 → 0.13.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 +4 -4
- data/lib/generators/nandi/index/USAGE +31 -0
- data/lib/generators/nandi/index/index_generator.rb +53 -0
- data/lib/generators/nandi/index/templates/add_index.rb +14 -0
- data/lib/nandi/compiled_migration.rb +1 -1
- data/lib/nandi/file_matcher.rb +1 -1
- data/lib/nandi/lockfile.rb +2 -2
- data/lib/nandi/renderers/active_record/generate.rb +1 -1
- data/lib/nandi/validation/timeout_validator.rb +3 -1
- data/lib/nandi/version.rb +1 -1
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e12cc00673e41d4494ea444a6a44524cca908c7bda4a315bd681dbec9cf7563
|
4
|
+
data.tar.gz: 29f0803224e74092b1bce4eaa673cc811bde033e0b9cd72359390094e34a62f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
data/lib/nandi/file_matcher.rb
CHANGED
data/lib/nandi/lockfile.rb
CHANGED
@@ -58,9 +58,9 @@ module Nandi
|
|
58
58
|
# worse merge conflict problems (e.g. if we randomised the order on
|
59
59
|
# writing the file, the whole thing would conflict pretty much every time
|
60
60
|
# it was regenerated).
|
61
|
-
content =
|
61
|
+
content = lockfile.to_h.deep_stringify_keys.sort_by do |k, _|
|
62
62
|
Digest::SHA256.hexdigest(k)
|
63
|
-
end
|
63
|
+
end.to_h.to_yaml
|
64
64
|
|
65
65
|
File.write(path, content)
|
66
66
|
end
|
data/lib/nandi/version.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.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:
|
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:
|
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:
|
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,14 +315,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
311
315
|
requirements:
|
312
316
|
- - ">="
|
313
317
|
- !ruby/object:Gem::Version
|
314
|
-
version: 2.
|
318
|
+
version: 2.6.0
|
315
319
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
316
320
|
requirements:
|
317
321
|
- - ">="
|
318
322
|
- !ruby/object:Gem::Version
|
319
323
|
version: '0'
|
320
324
|
requirements: []
|
321
|
-
rubygems_version: 3.
|
325
|
+
rubygems_version: 3.3.3
|
322
326
|
signing_key:
|
323
327
|
specification_version: 4
|
324
328
|
summary: Fear-free migrations for PostgreSQL
|