lib/neo4j/active_node/labels/index.rb in neo4j-7.2.3 vs lib/neo4j/active_node/labels/index.rb in neo4j-8.0.0.alpha.1

- old
+ new

@@ -18,70 +18,20 @@ # include Neo4j::ActiveNode # property :name # index :name # end def index(property) - Neo4j::Session.on_next_session_available do |_| - declared_properties.index_or_fail!(property, id_property_name) - schema_create_operation(:index, property) - end + return if Neo4j::ModelSchema.defined_constraint?(self, property) + + Neo4j::ModelSchema.add_defined_index(self, property) end # Creates a neo4j constraint on this class for given property # # @example # Person.constraint :name, type: :unique - def constraint(property, constraints = {type: :unique}) - Neo4j::Session.on_next_session_available do - declared_properties.constraint_or_fail!(property, id_property_name) - schema_create_operation(:constraint, property, constraints) - end - end - - # @param [Symbol] property The name of the property index to be dropped - def drop_index(property, options = {}) - Neo4j::Session.on_next_session_available do - declared_properties[property].unindex! if declared_properties[property] - schema_drop_operation(:index, property, options) - end - end - - # @param [Symbol] property The name of the property constraint to be dropped - # @param [Hash] constraint The constraint type to be dropped. - def drop_constraint(property, constraint = {type: :unique}) - Neo4j::Session.on_next_session_available do - declared_properties[property].unconstraint! if declared_properties[property] - schema_drop_operation(:constraint, property, constraint) - end - end - - def index?(property) - mapped_label.indexes[:property_keys].include?([property]) - end - - def constraint?(property) - mapped_label.unique_constraints[:property_keys].include?([property]) - end - - private - - def schema_create_operation(type, property, options = {}) - new_schema_class(type, property, options).create! - end - - def schema_drop_operation(type, property, options = {}) - new_schema_class(type, property, options).drop! - end - - def new_schema_class(type, property, options) - case type - when :index - Neo4j::Schema::ExactIndexOperation - when :constraint - Neo4j::Schema::UniqueConstraintOperation - else - fail "Unknown Schema Operation class #{type}" - end.new(mapped_label_name, property, options) + def constraint(property, _constraints = {type: :unique}) + Neo4j::ModelSchema.add_defined_constraint(self, property) end end end end