schema-tools 1.0.2 → 1.0.4

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: b697abd15a8fdf11898256f4bb6d83cb7fe15bbb57200490eec640b0495ce9e5
4
- data.tar.gz: 94c925ff0a00334640819f2513f48da352fa25d4c40224f1650eebaaeb159de0
3
+ metadata.gz: 85f554d54d4b8d6279927e4aefbd0b54311e1f09acb72fd7b32979b2a869ba10
4
+ data.tar.gz: b8bda0335ebd5db723620301f2d83cd0168d8b08208230497a5f616de7f3ccf1
5
5
  SHA512:
6
- metadata.gz: bec07e936a724a9df9193ede4f5a642ea38b5b207711aa6beb1f8c3b79591031f1cca739349f04298d1c0fea25cf5220a7f4006ec7853f7ec370be129cd8481e
7
- data.tar.gz: 2d98c0b488cd99f36e133a6628834cb4a7b718eee1ac134567905cacd96ff62c1cbb67bab198f65fc6836d2556e5279a3a4eb368bd38c35ff33479c76898145a
6
+ metadata.gz: 94f970235179e236828b02bc53e7fa89b53c223bd671eda73419ab2bf6496ee14972b3288658d12d9856be44511f2cceb41b62badf8b913f73a56db5411a71a7
7
+ data.tar.gz: c7de4ac81c1a17dc4fe42799e434ae861523c3fdcfd3f20dac61bfde8d1983d0151ae8fd33dfac54db4ab458220ef9554bba0641f0825c6642f97fe0ed018731
data/README.md CHANGED
@@ -15,6 +15,12 @@ Install this Ruby gem.
15
15
  gem install schema-tools
16
16
  ```
17
17
 
18
+ Add (or edit) a file called `Rakefile` and add this line:
19
+
20
+ ```ruby
21
+ require 'schema_tools'
22
+ ```
23
+
18
24
  ### Configuration
19
25
 
20
26
  Set the connection URL for your OpenSearch or Elasticsearch instance:
@@ -35,6 +41,12 @@ export OPENSEARCH_USERNAME=your_username
35
41
  export OPENSEARCH_PASSWORD=your_password
36
42
  ```
37
43
 
44
+ ### View available rake tasks
45
+
46
+ ```sh
47
+ rake -T | grep " schema:"
48
+ ```
49
+
38
50
  ### Download an existing schema
39
51
 
40
52
  Run `rake schema:download` to download a schema from an existing alias or index:
@@ -6,77 +6,66 @@ require_relative 'settings_filter'
6
6
 
7
7
  module SchemaTools
8
8
  def self.new_alias(client:)
9
- puts "Warning: This tool only supports migrating aliases."
10
- puts "Create an alias for this index by running:"
11
- puts "rake schema:alias"
12
- puts "\nDownload this index schema anyway? Y/n"
13
-
14
- choice = STDIN.gets&.chomp&.downcase
15
- if choice.nil? || choice.empty? || choice == 'y' || choice == 'yes'
16
- # User wants to proceed with creating a new alias
17
- puts "\nEnter a new alias name:"
18
- alias_name = STDIN.gets&.chomp
19
- if alias_name.nil? || alias_name.empty?
20
- puts "No alias name provided. Exiting."
21
- exit 1
22
- end
23
-
24
- if client.alias_exists?(alias_name)
25
- puts "Alias '#{alias_name}' already exists."
26
- exit 1
27
- end
28
-
29
- timestamp = Time.now.strftime("%Y%m%d%H%M%S")
30
- index_name = "#{alias_name}-#{timestamp}"
31
-
32
- puts "Creating index '#{index_name}' with alias '#{alias_name}'..."
33
-
34
- sample_settings = {
35
- "number_of_shards" => 1,
36
- "number_of_replicas" => 0,
37
- "analysis" => {
38
- "analyzer" => {
39
- "default" => {
40
- "type" => "standard"
41
- }
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"
42
33
  }
43
34
  }
44
35
  }
45
-
46
- sample_mappings = {
47
- "properties" => {
48
- "id" => {
49
- "type" => "keyword"
50
- },
51
- "created_at" => {
52
- "type" => "date"
53
- },
54
- "updated_at" => {
55
- "type" => "date"
56
- }
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"
57
48
  }
58
49
  }
59
-
60
- client.create_index(index_name, sample_settings, sample_mappings)
61
- client.create_alias(alias_name, index_name)
62
-
63
- puts "✓ Created index '#{index_name}' with alias '#{alias_name}'"
64
-
65
- schema_path = File.join(Config.schemas_path, alias_name)
66
- FileUtils.mkdir_p(schema_path)
67
-
68
- settings_file = File.join(schema_path, 'settings.json')
69
- mappings_file = File.join(schema_path, 'mappings.json')
70
-
71
- File.write(settings_file, JSON.pretty_generate(sample_settings))
72
- File.write(mappings_file, JSON.pretty_generate(sample_mappings))
73
-
74
- puts "✓ Sample schema created at #{schema_path}"
75
- puts " - settings.json"
76
- puts " - mappings.json"
77
- else
78
- puts "Exiting. Run 'rake schema:alias' to create an alias for an existing index."
79
- 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"
80
69
  end
81
70
 
82
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,12 +4,19 @@ 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 in development/test environment
12
+ if defined?(Rails) && (Rails.env.development? || Rails.env.test?) ||
13
+ !defined?(Rails) && (ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test' || ENV['RAILS_ENV'].nil?)
14
+ test_rake_file = File.join(File.dirname(__FILE__), '..', 'tasks', 'test.rake')
15
+ load test_rake_file if File.exist?(test_rake_file)
16
+ end
10
17
  end
11
18
  end
12
19
  end
13
20
 
14
- # Auto-load tasks when this file is required
15
- SchemaTools::RakeTasks.load_tasks
21
+ # Tasks are loaded automatically in Rails apps via Railtie
22
+ # For non-Rails usage, call SchemaTools::RakeTasks.load_tasks manually
data/lib/schema_tools.rb CHANGED
@@ -3,4 +3,7 @@ require 'schema_tools/rake_tasks'
3
3
  # Load Railtie for automatic rake task loading in Rails apps
4
4
  if defined?(Rails)
5
5
  require 'schema_tools/railtie'
6
+ else
7
+ # For non-Rails usage, load tasks immediately
8
+ SchemaTools::RakeTasks.load_tasks
6
9
  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.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Kuzsma