Class: ActiveCypher::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cypher/migrator.rb

Overview

Runs pending graph database migrations.

Constant Summary collapse

MIGRATE_DIR =
File.join('graphdb', 'migrate')

Instance Method Summary collapse

Constructor Details

#initialize(connection = ActiveCypher::Base.connection) ⇒ Migrator

Returns a new instance of Migrator.



8
9
10
# File 'lib/active_cypher/migrator.rb', line 8

def initialize(connection = ActiveCypher::Base.connection)
  @connection = connection
end

Instance Method Details

#migrate!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_cypher/migrator.rb', line 12

def migrate!
  ensure_schema_migration_constraint
  applied = existing_versions

  migration_files.each do |file|
    version = File.basename(file)[0, 14]
    next if applied.include?(version)

    require file
    class_name = File.basename(file, '.rb').split('_', 2).last.camelize
    klass = Object.const_get(class_name)
    klass.new(@connection).run

    @connection.execute_cypher("      CREATE (:SchemaMigration { version: '\#{version}', executed_at: datetime() })\n    CYPHER\n  end\nend\n")

#statusObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_cypher/migrator.rb', line 31

def status
  ensure_schema_migration_constraint
  applied = existing_versions
  migration_files.map do |file|
    version = File.basename(file)[0, 14]
    {
      status: (applied.include?(version) ? 'up' : 'down'),
      version: version,
      name: File.basename(file)
    }
  end
end