Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail schema inspection when full text indexes exist #338

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/neo4j/core/cypher_session/adaptors/http.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'neo4j/core/cypher_session/adaptors'
require 'neo4j/core/cypher_session/adaptors/has_uri'
require 'neo4j/core/cypher_session/responses/http'
require 'neo4j/core/cypher_session/adaptors/schema'
require 'uri'

# TODO: Work with `Query` objects
Expand All @@ -9,6 +10,7 @@ module Core
class CypherSession
module Adaptors
class HTTP < Base
include Adaptors::Schema
attr_reader :requestor, :url

def initialize(url, options = {})
Expand Down Expand Up @@ -46,7 +48,15 @@ def version(_session)
end

# Schema inspection methods
def indexes(_session)

# Does this version support CALL clause?
def supports_call?
Gem::Version.new(version(nil)) >= Gem::Version.new('3.0.0')
end

def indexes(session)
return super(session) if supports_call?

response = @requestor.get('db/data/schema/index')

check_for_schema_response_error!(response)
Expand All @@ -61,7 +71,9 @@ def indexes(_session)
CONSTRAINT_TYPES = {
'UNIQUENESS' => :uniqueness
}
def constraints(_session, _label = nil, _options = {})
def constraints(session, _label = nil, _options = {})
return super(session) if supports_call?

response = @requestor.get('db/data/schema/constraint')

check_for_schema_response_error!(response)
Expand Down
14 changes: 10 additions & 4 deletions lib/neo4j/core/cypher_session/adaptors/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ def indexes(session)
result = query(session, 'CALL db.indexes()', {}, skip_instrumentation: true)

result.map do |row|
label, property = row.description.match(/INDEX ON :([^\(]+)\(([^\)]+)\)/)[1, 2]
match = row.description.match(/INDEX ON :([^\(]+)\(([^\)]+)\)/)
next unless match

label, property = match[1, 2]
{type: row.type.to_sym, label: label.to_sym, properties: [property.to_sym], state: row.state.to_sym}
end
end.compact
end

def constraints(session)
result = query(session, 'CALL db.indexes()', {}, skip_instrumentation: true)

result.select { |row| row.type == 'node_unique_property' }.map do |row|
label, property = row.description.match(/INDEX ON :([^\(]+)\(([^\)]+)\)/)[1, 2]
match = row.description.match(/INDEX ON :([^\(]+)\(([^\)]+)\)/)
next unless match

label, property = match[1, 2]
{type: :uniqueness, label: label.to_sym, properties: [property.to_sym]}
end
end.compact
end
end
end
Expand Down
29 changes: 28 additions & 1 deletion spec/neo4j/core/shared_examples/adaptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,28 @@ def get_object_by_id(id, adaptor)
end

describe 'schema inspection' do
before { delete_schema(real_session) }
def supports_full_text?
Gem::Version.new(adaptor.version(real_session)) >= Gem::Version.new('3.5.0')
end

before do
delete_schema(real_session)

if supports_full_text?
adaptor.query(
real_session,
<<-CYPHER
CALL db.indexes()
YIELD indexName WHERE indexName STARTS WITH "ftIndex"
WITH COLLECT(indexName) AS names
UNWIND names AS n
CALL db.index.fulltext.drop(n)
RETURN null
CYPHER
)
end
end

before do
create_constraint(real_session, :Album, :al_id, type: :unique)
create_constraint(real_session, :Album, :name, type: :unique)
Expand All @@ -397,6 +418,12 @@ def get_object_by_id(id, adaptor)
create_index(real_session, :Band, :ba_id)
create_index(real_session, :Band, :fisk)
create_index(real_session, :Person, :name)

if supports_full_text?
adaptor.query(real_session, 'CALL db.index.fulltext.createNodeIndex("ftIndex1", ["Album"], ["name"])')
adaptor.query(real_session, 'CALL db.index.fulltext.createNodeIndex("ftIndex2", ["Album", "Song"], ["name", "al_id", "so_id"])')
adaptor.query(real_session, 'CALL db.index.fulltext.createRelationshipIndex("ftIndex3", ["ALBUM_SONG"], ["songNumber"])')
end
end

describe 'constraints' do
Expand Down