neo4j-rake_tasks 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48fcf8d2f7bd17afe69c78490429f24b8d482612
4
- data.tar.gz: 2531e92b076051887d0da60b0d2eafaaf650d5d0
3
+ metadata.gz: 914ebd590bc305c15848a3964495e2f48cb7b119
4
+ data.tar.gz: 715b564075c5248879dde37304bcb97f7cca61df
5
5
  SHA512:
6
- metadata.gz: deb530721f87d8a44b9248d960a362cb4d9f03124add7c455f5923e7d96b68038f9dadffe00bf82352fdab0aa8ca6c0326a698862089506311a08bc9775fa120
7
- data.tar.gz: f9cea61b138f48ca444c94deadf0c0a5f6504e99da37fdd2d34a11b7be932b24f51134a38ff0e38b6508f1e43c4e36f7287b7404804ae89408143f5de7081b71
6
+ metadata.gz: 93ea085e16181e17f274dff8e0813a310191ba8dd9bf414e8c43da7c60b04cb8ad765becc282e7027bccd1c55a366d3ee5c091a20466bef7099a62bc13456ee0
7
+ data.tar.gz: 80a5d30d3c25b1b2f636a966de4b6e667757c0c7a9d36bf78450e17b9cbe4aa5b490336c725f1fd1296fd74fd07e02377c76a11efe744d81e42ce2c9a11576e7
@@ -110,6 +110,26 @@ namespace :neo4j do
110
110
  server_manager.info
111
111
  end
112
112
 
113
+ desc 'List indexes for the Neo4j server'
114
+ task :indexes, :environment do |_, args|
115
+ args.with_defaults(environment: :development)
116
+
117
+ puts "Getting Neo4j indexes for #{args[:environment]}..."
118
+
119
+ server_manager = server_manager(args[:environment])
120
+ server_manager.print_indexes
121
+ end
122
+
123
+ desc 'List constraints for the Neo4j server'
124
+ task :constraints, :environment do |_, args|
125
+ args.with_defaults(environment: :development)
126
+
127
+ puts "Getting Neo4j constraints for #{args[:environment]}..."
128
+
129
+ server_manager = server_manager(args[:environment])
130
+ server_manager.print_constraints
131
+ end
132
+
113
133
  desc 'Restart the Neo4j Server'
114
134
  task :restart, :environment do |_, args|
115
135
  args.with_defaults(environment: :development)
@@ -22,7 +22,7 @@ module Neo4j
22
22
  FileUtils.rm archive_path
23
23
  end
24
24
 
25
- config_port!(7474) if server_version >= '3.0.0'
25
+ config_port!(7474) if server_version_greater_than?('3.0.0')
26
26
 
27
27
  puts "Neo4j installed to: #{@path}"
28
28
  end
@@ -75,7 +75,7 @@ module Neo4j
75
75
 
76
76
  stop
77
77
 
78
- paths = if server_version >= '3.0.0'
78
+ paths = if server_version_greater_than?('3.0.0')
79
79
  ['data/databases/graph.db/*', 'logs/*']
80
80
  else
81
81
  ['data/graph.db/*', 'data/log/*']
@@ -115,7 +115,7 @@ module Neo4j
115
115
  def config_port!(port)
116
116
  puts "Config ports #{port} (HTTP) / #{port - 1} (HTTPS) / #{port - 2} (Bolt)"
117
117
 
118
- if server_version >= '3.0.0'
118
+ if server_version_greater_than?('3.0.0')
119
119
  # These are not ideal, perhaps...
120
120
  modify_config_file('dbms.connector.https.enabled' => false,
121
121
  'dbms.connector.http.enabled' => true,
@@ -137,6 +137,15 @@ module Neo4j
137
137
  File.open(property_configuration_path, 'w') { |file| file << modify_config_contents(contents, properties) }
138
138
  end
139
139
 
140
+ def get_config_property(property)
141
+ lines = File.read(property_configuration_path).lines
142
+ config_lines = lines.grep(/^\s*[^#]/).map(&:strip).reject(&:empty?)
143
+
144
+ lines.find do |line|
145
+ line.match(/\s*#{property}=/)
146
+ end.split('=')[1]
147
+ end
148
+
140
149
  def modify_config_contents(contents, properties)
141
150
  properties.inject(contents) do |r, (property, value)|
142
151
  r.gsub(/^\s*(#\s*)?#{property}\s*=\s*(.+)/, "#{property}=#{value}")
@@ -151,8 +160,29 @@ module Neo4j
151
160
  class_for_os.new(path)
152
161
  end
153
162
 
163
+ def print_indexes
164
+ print_indexes_or_constraints(:index)
165
+ end
166
+
167
+ def print_constraints
168
+ print_indexes_or_constraints(:constraint)
169
+ end
170
+
154
171
  protected
155
172
 
173
+ def print_indexes_or_constraints(type)
174
+ url = File.join(server_url, "db/data/schema/#{type}")
175
+ data = JSON.load(open(url).read)
176
+ data.sort_by {|i| i['label'] }.chunk do |index|
177
+ index['label']
178
+ end.each do |label, indexes|
179
+ puts "\e[36m#{label}\e[0m"
180
+ indexes.each do |index|
181
+ puts ' ' + index['property_keys'].join(', ')
182
+ end
183
+ end
184
+ end
185
+
156
186
  def start_argument(wait)
157
187
  wait ? 'start' : 'start-no-wait'
158
188
  end
@@ -173,8 +203,19 @@ module Neo4j
173
203
  binary_command_path(neo4j_shell_binary_filename)
174
204
  end
175
205
 
206
+ def server_url
207
+ if server_version_greater_than?('3.0.0')
208
+ get_config_property('dbms.connector.http.address').strip.tap do |address|
209
+ address.prepend('http://') unless address.match(/^http:\/\//)
210
+ end
211
+ else
212
+ port = get_config_property('org.neo4j.server.webserver.https.port')
213
+ "http://localhost:#{port}"
214
+ end.strip
215
+ end
216
+
176
217
  def property_configuration_path
177
- if server_version >= '3.0.0'
218
+ if server_version_greater_than?('3.0.0')
178
219
  @path.join('conf', 'neo4j.conf')
179
220
  else
180
221
  @path.join('conf', 'neo4j-server.properties')
@@ -206,7 +247,7 @@ module Neo4j
206
247
  end
207
248
 
208
249
  def pid_path
209
- if server_version >= '3.0.0'
250
+ if server_version_greater_than?('3.0.0')
210
251
  @path.join('run/neo4j.pid')
211
252
  else
212
253
  @path.join('data/neo4j-service.pid')
@@ -217,6 +258,10 @@ module Neo4j
217
258
 
218
259
  NEO4J_VERSIONS_URL = 'https://raw.githubusercontent.com/neo4jrb/neo4j-rake_tasks/master/neo4j_versions.yml'
219
260
 
261
+ def server_version_greater_than?(version)
262
+ Gem::Version.new(server_version) > Gem::Version.new(version)
263
+ end
264
+
220
265
  def server_version
221
266
  kernel_jar_path = Dir.glob(@path.join('lib/neo4j-kernel-*.jar'))[0]
222
267
  kernel_jar_path.match(/neo4j-kernel-([\d\.]+)\.jar$/)[1]
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module RakeTasks
3
- VERSION = '0.6.1'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-rake_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored