Class: Neo4j::Migration::AddIdProperty

Inherits:
Neo4j::Migration show all
Includes:
Neo4j::Migrations::Helpers::IdProperty
Defined in:
lib/neo4j/migration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Neo4j::Migrations::Helpers::IdProperty

#populate_id_property

Methods inherited from Neo4j::Migration

#default_path, #joined_path, #output, #print_output

Constructor Details

#initialize(path = default_path) ⇒ AddIdProperty

Returns a new instance of AddIdProperty.



39
40
41
# File 'lib/neo4j/migration.rb', line 39

def initialize(path = default_path)
  @models_filename = File.join(joined_path(path), 'add_id_property.yml')
end

Instance Attribute Details

#models_filenameObject (readonly)

Returns the value of attribute models_filename.



37
38
39
# File 'lib/neo4j/migration.rb', line 37

def models_filename
  @models_filename
end

Instance Method Details

#execute(*args) ⇒ Object



61
62
63
# File 'lib/neo4j/migration.rb', line 61

def execute(*args)
  ActiveBase.query(*args)
end

#migrateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/neo4j/migration.rb', line 43

def migrate
  ActiveSupport::Deprecation.warn '`AddIdProperty` task is deprecated and may be removed from future releases. '\
                                  'Create a new migration and use the `populate_id_property` helper.', caller
  models = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(models_filename))[:models]
  output 'This task will add an ID Property every node in the given file.'
  output 'It may take a significant amount of time, please be patient.'
  models.each do |model|
    output
    output
    output "Adding IDs to #{model}"
    populate_id_property model
  end
end

#query(*args) ⇒ Object



57
58
59
# File 'lib/neo4j/migration.rb', line 57

def query(*args)
  ActiveBase.magic_query(*args)
end

#setupObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/neo4j/migration.rb', line 65

def setup
  super
  return if File.file?(models_filename)

  File.open(models_filename, 'w') do |file|
    message = <<MESSAGE
# Provide models to which IDs should be added.
# # It will only modify nodes that do not have IDs. There is no danger of overwriting data.
# # models: [Student,Lesson,Teacher,Exam]\nmodels: []
MESSAGE
    file.write(message)
  end
end