schema-tools 1.0.3 → 1.0.5

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: 9b0a1829a0042b9d9e031af29d3684bb90a52af86943de3b12b95f55c8c0ac0b
4
- data.tar.gz: 4b6675502d201d507ba404becfd2f310278abb6bf5f00751916d56a5a65a1708
3
+ metadata.gz: d7eb15996fbabd0923cf28e8ecd2142a28c3af1fb7ce0373220d64470f9f2aee
4
+ data.tar.gz: 6806c8094271fb77e1e61c4bb98f3efc7d670fb40652f75c642f30445ee19adc
5
5
  SHA512:
6
- metadata.gz: 3306dea2eb57653f934bc9f18c6cf646bc12f2a2dfb55b905b899f69fefb84381d074486cc3c6bad865b73b353dd5b1e1059c117b36f9ba62533ae69f76f0e3c
7
- data.tar.gz: 120bf4d22a5f50b5c68e9830aa0b900e089cdf11883480c2448216906ca79b4351bd318c31e59d2e77d770a25081cc736dfcd59cc17eac1b5a744f0116be6831
6
+ metadata.gz: 661f85da42d258a77599d4e4fe4165d8db11d9b235cedc7af77d1cbc48f41a6297f5a7c8449720b3f51ae02ac67ddefbef68ab0a777bb6425adaddefc567203c
7
+ data.tar.gz: a8bf7e23038a9059ad52faa347e58f6a5a4e50d228699a98a90a3d51c1f88c2be108d29e22370745e3a43979b6528af73dbf8dcdce580d5b042cd5d181a3d980
@@ -6,72 +6,66 @@ require_relative 'settings_filter'
6
6
 
7
7
  module SchemaTools
8
8
  def self.new_alias(client:)
9
- choice = STDIN.gets&.chomp&.downcase
10
- if choice.nil? || choice.empty? || choice == 'y' || choice == 'yes'
11
- # User wants to proceed with creating a new alias
12
- puts "\nEnter a new alias name:"
13
- alias_name = STDIN.gets&.chomp
14
- if alias_name.nil? || alias_name.empty?
15
- puts "No alias name provided. Exiting."
16
- exit 1
17
- end
18
-
19
- if client.alias_exists?(alias_name)
20
- puts "Alias '#{alias_name}' already exists."
21
- exit 1
22
- end
23
-
24
- timestamp = Time.now.strftime("%Y%m%d%H%M%S")
25
- index_name = "#{alias_name}-#{timestamp}"
26
-
27
- puts "Creating index '#{index_name}' with alias '#{alias_name}'..."
28
-
29
- sample_settings = {
30
- "number_of_shards" => 1,
31
- "number_of_replicas" => 0,
32
- "analysis" => {
33
- "analyzer" => {
34
- "default" => {
35
- "type" => "standard"
36
- }
9
+ puts "\nEnter a new alias name:"
10
+ alias_name = STDIN.gets&.chomp
11
+ if alias_name.nil? || alias_name.empty?
12
+ puts "No alias name provided. Exiting."
13
+ exit 1
14
+ end
15
+
16
+ if client.alias_exists?(alias_name)
17
+ puts "Alias '#{alias_name}' already exists."
18
+ exit 1
19
+ end
20
+
21
+ timestamp = Time.now.strftime("%Y%m%d%H%M%S")
22
+ index_name = "#{alias_name}-#{timestamp}"
23
+
24
+ puts "Creating index '#{index_name}' with alias '#{alias_name}'..."
25
+
26
+ sample_settings = {
27
+ "number_of_shards" => 1,
28
+ "number_of_replicas" => 0,
29
+ "analysis" => {
30
+ "analyzer" => {
31
+ "default" => {
32
+ "type" => "standard"
37
33
  }
38
34
  }
39
35
  }
40
-
41
- sample_mappings = {
42
- "properties" => {
43
- "id" => {
44
- "type" => "keyword"
45
- },
46
- "created_at" => {
47
- "type" => "date"
48
- },
49
- "updated_at" => {
50
- "type" => "date"
51
- }
36
+ }
37
+
38
+ sample_mappings = {
39
+ "properties" => {
40
+ "id" => {
41
+ "type" => "keyword"
42
+ },
43
+ "created_at" => {
44
+ "type" => "date"
45
+ },
46
+ "updated_at" => {
47
+ "type" => "date"
52
48
  }
53
49
  }
54
-
55
- client.create_index(index_name, sample_settings, sample_mappings)
56
- client.create_alias(alias_name, index_name)
57
-
58
- puts "✓ Created index '#{index_name}' with alias '#{alias_name}'"
59
-
60
- schema_path = File.join(Config.schemas_path, alias_name)
61
- FileUtils.mkdir_p(schema_path)
62
-
63
- settings_file = File.join(schema_path, 'settings.json')
64
- mappings_file = File.join(schema_path, 'mappings.json')
65
-
66
- File.write(settings_file, JSON.pretty_generate(sample_settings))
67
- File.write(mappings_file, JSON.pretty_generate(sample_mappings))
68
-
69
- puts "✓ Sample schema created at #{schema_path}"
70
- puts " - settings.json"
71
- puts " - mappings.json"
72
- else
73
- puts "Exiting. Run 'rake schema:alias' to create an alias for an existing index."
74
- end
50
+ }
51
+
52
+ client.create_index(index_name, sample_settings, sample_mappings)
53
+ client.create_alias(alias_name, index_name)
54
+
55
+ puts "✓ Created index '#{index_name}' with alias '#{alias_name}'"
56
+
57
+ schema_path = File.join(Config.schemas_path, alias_name)
58
+ FileUtils.mkdir_p(schema_path)
59
+
60
+ settings_file = File.join(schema_path, 'settings.json')
61
+ mappings_file = File.join(schema_path, 'mappings.json')
62
+
63
+ File.write(settings_file, JSON.pretty_generate(sample_settings))
64
+ File.write(mappings_file, JSON.pretty_generate(sample_mappings))
65
+
66
+ puts " Sample schema created at #{schema_path}"
67
+ puts " - settings.json"
68
+ puts " - mappings.json"
75
69
  end
76
70
 
77
71
  def self.create_alias_for_index(client:)
@@ -1,10 +1,12 @@
1
1
  require 'schema_tools/rake_tasks'
2
2
 
3
- module SchemaTools
4
- class Railtie < Rails::Railtie
5
- rake_tasks do
6
- # This will automatically load the rake tasks when Rails starts
7
- SchemaTools::RakeTasks.load_tasks
3
+ if defined?(Rails)
4
+ module SchemaTools
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ # This will automatically load the rake tasks when Rails starts
8
+ SchemaTools::RakeTasks.load_tasks
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -4,9 +4,17 @@ require 'rake/tasklib'
4
4
  module SchemaTools
5
5
  module RakeTasks
6
6
  def self.load_tasks
7
- # Only load schema.rake, not test.rake which requires development dependencies
7
+ # Load schema.rake
8
8
  schema_rake_file = File.join(File.dirname(__FILE__), '..', 'tasks', 'schema.rake')
9
9
  load schema_rake_file if File.exist?(schema_rake_file)
10
+
11
+ # Load test.rake only when we're in the gem's own development environment
12
+ # Check if we're in the gem's source directory (not a consuming app)
13
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
14
+ if File.exist?(File.join(gem_root, 'test')) && File.exist?(File.join(gem_root, 'test', 'spec_helper.rb'))
15
+ test_rake_file = File.join(File.dirname(__FILE__), '..', 'tasks', 'test.rake')
16
+ load test_rake_file if File.exist?(test_rake_file)
17
+ end
10
18
  end
11
19
  end
12
20
  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.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Kuzsma