@@ -696,12 +696,14 @@ impl RelationshipSetupState {
696696 )
697697 } ) ?;
698698 for ( label, node) in rel_spec. nodes . iter ( ) . flatten ( ) {
699- sub_components. push ( ComponentState {
700- object_label : ElementType :: Node ( label. clone ( ) ) ,
701- index_def : IndexDef :: KeyConstraint {
702- field_names : key_field_names. clone ( ) ,
703- } ,
704- } ) ;
699+ if let Some ( primary_key_fields) = & node. index_options . primary_key_fields {
700+ sub_components. push ( ComponentState {
701+ object_label : ElementType :: Node ( label. clone ( ) ) ,
702+ index_def : IndexDef :: KeyConstraint {
703+ field_names : primary_key_fields. clone ( ) ,
704+ } ,
705+ } ) ;
706+ }
705707 for index_def in & node. index_options . vector_indexes {
706708 sub_components. push ( ComponentState {
707709 object_label : ElementType :: Node ( label. clone ( ) ) ,
@@ -885,8 +887,12 @@ impl components::Operator for SetupComponentOperator {
885887 let matcher = state. object_label . matcher ( qualifier) ;
886888 let query = neo4rs:: query ( & match & state. index_def {
887889 IndexDef :: KeyConstraint { field_names } => {
890+ let key_type = match & state. object_label {
891+ ElementType :: Node ( _) => "NODE" ,
892+ ElementType :: Relationship ( _) => "RELATIONSHIP" ,
893+ } ;
888894 format ! (
889- "CREATE CONSTRAINT {name} IF NOT EXISTS FOR {matcher} REQUIRE {field_names} IS UNIQUE " ,
895+ "CREATE CONSTRAINT {name} IF NOT EXISTS FOR {matcher} REQUIRE {field_names} IS {key_type} KEY " ,
890896 name=key. name,
891897 field_names=build_composite_field_names( qualifier, & field_names) ,
892898 )
0 commit comments