schema-tools 1.0.10 → 1.0.11

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/schema_tools/seed.rb +50 -18
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ace88e188ea3e99453282c5b8a4f3160aabd50a1791b44adbbbbaa96ec2d9801
4
- data.tar.gz: c4cb7b090362308b92c9e8f857110d7d104eef7907649825669fc46cc34f567b
3
+ metadata.gz: 8b9242c466fb8b9221d3098cd5a935d097c09529ba31e1e99b5583516d76d4df
4
+ data.tar.gz: 3bcbac2b5ba73b4dabe14bfc19ca14dc35410751afaa65a5b56479250601caf7
5
5
  SHA512:
6
- metadata.gz: 9d69414e92b731a19f47c98cb97a0cb8c6f2994be31f61930d7fcab7cc60272bd4c5af2790cbdd5eae7061a737eef744f7ab643d58c0647dfb3b166ad1f8d2b3
7
- data.tar.gz: 2441ceb2f6d920aaf4e33b1116978f014e093bd433d4dc2ee3206b79d06c5dd43353de449f3fb7cc35a941a104eacdd8497e4601f246e4d2db5eaae79bb4a03b
6
+ metadata.gz: 4058c3e576346b8a9df2287c5e792f832db2771b22e00ba24c8dbaf501965999cec72f76621aee49d737de013b58bd8ba4d131daf36ced46db18737ef59414da
7
+ data.tar.gz: a83c83843c2585d6091799be9748974515d7bd0f1af3d616ff1f6c61c96d40c4014d209296aa2d200def2ea97ef2c2f158c1f63ba25eb8d9ff70dccd7944fcaf
@@ -2,21 +2,39 @@ module SchemaTools
2
2
  def self.seed(client:)
3
3
  # List available indices and aliases (connection already validated during client initialization)
4
4
  puts "Connecting to #{Config.connection_url}..."
5
+
6
+ options = print_aliases_and_indices(client)
7
+ if options.empty?
8
+ puts "No indices or aliases found in the cluster."
9
+ puts "Please create an index first."
10
+ exit 0
11
+ end
12
+
13
+ selected_option = prompt_for_selection(options)
14
+ puts "Selected #{selected_option[:type]}: #{selected_option[:name]}"
15
+
16
+ num_docs = prompt_for_positive_integer("How many documents would you like to seed?")
17
+
18
+ batch_size = prompt_for_positive_integer("What batch size would you like to use? \nUse a higher number for faster speed, lower number if you hit memory errors.", default: 50)
19
+
20
+ seeder = Seeder::Seeder.new(index_or_alias_name: selected_option[:name], client: client)
21
+ seeder.seed(num_docs: num_docs, batch_size: batch_size)
22
+ end
23
+
24
+ private
25
+
26
+ def self.print_aliases_and_indices(client)
5
27
  aliases = client.list_aliases
6
28
  indices = client.list_indices
7
29
 
8
30
  single_aliases = aliases.select { |alias_name, indices| indices.length == 1 && !alias_name.start_with?('.') }
9
31
  unaliased_indices = indices.reject { |index| aliases.values.flatten.include?(index) || index.start_with?('.') || client.index_closed?(index) }
10
32
 
33
+ return [] if single_aliases.empty? && unaliased_indices.empty?
34
+
11
35
  # Create a combined list with sequential numbering
12
36
  options = []
13
37
 
14
- if single_aliases.empty? && unaliased_indices.empty?
15
- puts "No indices or aliases found in the cluster."
16
- puts "Please create an index first."
17
- exit 0
18
- end
19
-
20
38
  puts "Available indices and aliases:"
21
39
 
22
40
  # Show aliases first
@@ -36,7 +54,11 @@ module SchemaTools
36
54
  puts "#{option_number}. #{index_name}"
37
55
  end
38
56
  end
39
-
57
+
58
+ options
59
+ end
60
+
61
+ def self.prompt_for_selection(options)
40
62
  puts "\nPlease select an index or alias by number (1-#{options.length}):"
41
63
  selection_input = STDIN.gets&.chomp
42
64
  if selection_input.nil?
@@ -50,24 +72,34 @@ module SchemaTools
50
72
  exit 1
51
73
  end
52
74
 
53
- selected_option = options[selection - 1]
54
- puts "Selected #{selected_option[:type]}: #{selected_option[:name]}"
75
+ options[selection - 1]
76
+ end
77
+
78
+ def self.prompt_for_positive_integer(message, default: nil)
79
+ if default
80
+ puts "\n#{message}"
81
+ puts "Press Enter to use default value (#{default}) or enter a custom value:"
82
+ else
83
+ puts "\n#{message}"
84
+ end
55
85
 
56
- # Prompt user for number of documents to seed
57
- puts "\nHow many documents would you like to seed?"
58
- num_docs_input = STDIN.gets&.chomp
59
- if num_docs_input.nil?
86
+ input = STDIN.gets&.chomp
87
+ if input.nil?
60
88
  puts "No input provided. Exiting."
61
89
  exit 1
62
90
  end
63
91
 
64
- num_docs = num_docs_input.to_i
65
- if num_docs <= 0
66
- puts "Invalid number of documents. Please enter a positive integer."
92
+ # Use default if input is empty and default is provided
93
+ if input.empty? && default
94
+ return default
95
+ end
96
+
97
+ value = input.to_i
98
+ if value <= 0
99
+ puts "Invalid input. Please enter a positive integer."
67
100
  exit 1
68
101
  end
69
102
 
70
- seeder = Seeder::Seeder.new(index_or_alias_name: selected_option[:name], client: client)
71
- seeder.seed(num_docs: num_docs, batch_size: 5)
103
+ value
72
104
  end
73
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Kuzsma