3

Here is a brief description of the problem:

irb(main):001:0> b = Bisac.first
 CYPHER 268ms MATCH (n:`Bisac`) RETURN n ORDER BY n.uuid LIMIT {limit_1} | {:limit_1=>1}
=> #<Bisac uuid: nil, bisac_code: "MUS037050", bisac_value: "MUSIC / Printed Music / Mixed Collections">

Here are the indexes:

  ON :Author(uuid)              ONLINE (for uniqueness constraint) 
  ON :Author(author_name)       ONLINE (for uniqueness constraint) 
  ON :Bisac(uuid)               ONLINE (for uniqueness constraint) 
  ON :Bisac(bisac_code)         ONLINE (for uniqueness constraint) 
  ON :Country(country_name)     ONLINE (for uniqueness constraint) 
  ON :Country(uuid)             ONLINE (for uniqueness constraint) 
  ON :Description(uuid)         ONLINE (for uniqueness constraint) 
  ON :Language(iso_639_2_code)  ONLINE (for uniqueness constraint) 
  ON :Language(uuid)            ONLINE (for uniqueness constraint) 
  ON :Publisher(uuid)           ONLINE (for uniqueness constraint) 
  ON :Publisher(publisher_name) ONLINE (for uniqueness constraint) 
  ON :Region(region_name)       ONLINE (for uniqueness constraint) 
  ON :Region(uuid)              ONLINE (for uniqueness constraint) 
  ON :Woka(woka_title)          ONLINE                             
  ON :Woka(uuid)                ONLINE (for uniqueness constraint) 
  ON :Woka(woka_id)             ONLINE (for uniqueness constraint) 

Can these uuid be changed to not null values since those seems to be useful? All data was loaded from CSV files. All indexes on uuid were created when data was accessed from Ruby on Rails console first time with statements like: b = Bisac.first, or a = Auhtor.first, etc.

LDB
  • 692
  • 6
  • 18

1 Answers1

4

Since Neo4j IDs can be recycled, ActiveNode requires a property on each model which can be unique. By default that's uuid, but you can choose it yourself using the id_property method.

If you want to populate the field, there's a migration tool for setting the uuids which is mentioned here:

https://github.com/neo4jrb/neo4j/wiki/Neo4j-v3-Migrations

But basically the fields are set using Ruby's SecureRandom.uuid. You could also do this yourself in the database with your own queries, or if you are able to rebuild the database with LOAD CSV you could add that as a column to your CSV file(s)

Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • Can I have please an example of such a query generating uuid values in the database? Also another example how to use this with LOAD CSV may help. Not sure yet which path to choose at this moment. – LDB Aug 06 '15 at 16:34
  • I would try the migration specified in the wiki first. – Brian Underwood Aug 06 '15 at 16:44
  • I am tempted to use this. You could also use the GraphAware UUID Module. All you would have to do is drop the framework jar and the uuid module jar into the plugins directory, add the following 2 lines into neo4j.properties, and restart Neo4j. com.graphaware.runtime.enabled=true com.graphaware.module.UIDM.1=com.graphaware.module.uuid.UuidBootstrapper Any new node (no matter how it is created) will automatically get a UUID. From this link: http://stackoverflow.com/questions/27082647/neo4j-cypher-load-csv-with-uuid – LDB Aug 06 '15 at 16:48
  • 1
    It's true, but we don't want to require that people install a server module just to use the gem – Brian Underwood Aug 06 '15 at 18:22