schema-tools 1.0.3 → 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 +4 -4
- data/lib/schema_tools/new_alias.rb +55 -61
- data/lib/schema_tools/railtie.rb +7 -5
- data/lib/schema_tools/rake_tasks.rb +8 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85f554d54d4b8d6279927e4aefbd0b54311e1f09acb72fd7b32979b2a869ba10
|
4
|
+
data.tar.gz: b8bda0335ebd5db723620301f2d83cd0168d8b08208230497a5f616de7f3ccf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94f970235179e236828b02bc53e7fa89b53c223bd671eda73419ab2bf6496ee14972b3288658d12d9856be44511f2cceb41b62badf8b913f73a56db5411a71a7
|
7
|
+
data.tar.gz: c7de4ac81c1a17dc4fe42799e434ae861523c3fdcfd3f20dac61bfde8d1983d0151ae8fd33dfac54db4ab458220ef9554bba0641f0825c6642f97fe0ed018731
|
@@ -6,72 +6,66 @@ require_relative 'settings_filter'
|
|
6
6
|
|
7
7
|
module SchemaTools
|
8
8
|
def self.new_alias(client:)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
puts "
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"
|
31
|
-
|
32
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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:)
|
data/lib/schema_tools/railtie.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'schema_tools/rake_tasks'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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,16 @@ require 'rake/tasklib'
|
|
4
4
|
module SchemaTools
|
5
5
|
module RakeTasks
|
6
6
|
def self.load_tasks
|
7
|
-
#
|
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
|