如何在Neo4J中修复约束和索引以获得更改的记录



我更改了neo4j中的记录名称。现在,我遇到了一个暗示未决迁移的错误。

class CreateOrganization < Neo4j::Migrations::Base
  def up
    execute("MATCH (n:Institution) SET n:Organization REMOVE n:Institution RETURN n")
  end
  def down
    execute("MATCH (n:Organization) SET n:Institution REMOVE n:Organization RETURN n")
  end
end

rails 5.1.4

neo4j 3.3.2

当我与CALL db.constraints核对时,我可以看到它们仍然指向机构。目标是让他们指向组织。

"CONSTRAINT ON ( institution:Institution ) ASSERT institution.uuid IS UNIQUE"

错误看起来像这样...

Neo4j::DeprecatedSchemaDefinitionError in SessionsController#new
Some schema elements were defined by the model (which is no longer 
supported), but they do not exist in the database. Run the following to 
create them if you haven't already: rake 
neo4j:generate_schema_migration[constraint,Organization,uuid] rake 
neo4j:generate_schema_migration[index,Organization,sector] And then run 
`rake neo4j:migrate` (zshell users may need to escape the brackets)

我运行

rake neo4j:generate_schema_migration[constraint,Organization,uuid]

我得到

zsh: no matches found: neo4j:generate_schema_migration[constraint,Organization,uuid]

更新:创建了布莱恩在答案中提供的迁移后,与约束有关的错误部分消失了。但是,与索引有关的错误部分仍然存在。我尝试使用助手从模型中的添加索引。

class AddIndexToOrganization < Neo4j::Migrations::Base
  def up
    add_index :Organization, :uuid
    drop_index :Institution, :uuid
  end
  def down
    drop_index :Organization, :uuid
    add_index :Institution, :uuid
  end
end
然后,我尝试运行迁移。这引发和错误:
== 20180224004338 AddIndexToOrganization: running... 
===========================
rake aborted!
Neo4j::MigrationError: Duplicate index for Organization#uuid

有趣的是,当我使用CALL db.indexes时,我找不到组织上的索引,这仍然是"INDEX ON :Institution(sector)" "Institution"

运行 MATCH (n:Institution) SET n:Organization REMOVE n:Institution RETURN n不会更改约束,只是标签。约束仍将为旧标签设置。您应该能够在新的迁移中使用drop_constraintadd_constraint的帮助者(请参阅"迁移帮助者"文档页面(。它应该看起来像:

class CreateOrganization < Neo4j::Migrations::Base
  def up
    add_constraint(:Organization, :uuid)
    remove_constraint(:Institution, :uuid)
  end
  def down
    remove_constraint(:Organization, :uuid)
    add_constraint(:Institution, :uuid)
  end
end

相关内容

  • 没有找到相关文章

最新更新