Sha256: adbf2446312b6d6b9ac37a07c274036b6c0c4a79a9d6f7d4da58a514ffd82f88

Contents?: true

Size: 1.51 KB

Versions: 55

Compression:

Stored size: 1.51 KB

Contents

module Neo4j
  module Migrations
    module Schema
      class << self
        def fetch_schema_data(session)
          {constraints: fetch_constraint_descriptions(session).sort,
           indexes: fetch_index_descriptions(session).sort}
        end

        def synchronize_schema_data(session, schema_data, remove_missing)
          queries = []
          queries += drop_and_create_queries(fetch_constraint_descriptions(session), schema_data[:constraints], remove_missing)
          queries += drop_and_create_queries(fetch_index_descriptions(session), schema_data[:indexes], remove_missing)
          session.queries do
            queries.each { |query| append query }
          end
        end

        private

        def fetch_constraint_descriptions(session)
          session.query('CALL db.constraints()').map(&:description)
        end

        def fetch_index_descriptions(session)
          session.query('CALL db.indexes()').reject do |row|
            # These indexes are created automagically when the corresponding constraints are created
            row.type == 'node_unique_property'
          end.map(&:description)
        end

        def drop_and_create_queries(existing, specified, remove_missing)
          [].tap do |queries|
            if remove_missing
              (existing - specified).each { |description| queries << "DROP #{description}" }
            end

            (specified - existing).each { |description| queries << "CREATE #{description}" }
          end
        end
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 2 rubygems

Version Path
neo4j-9.6.2 lib/neo4j/migrations/schema.rb
activegraph-10.0.0.pre.alpha.7 lib/neo4j/migrations/schema.rb
activegraph-10.0.0.pre.alpha.6 lib/neo4j/migrations/schema.rb
neo4j-10.0.0.pre.alpha.5 lib/neo4j/migrations/schema.rb
neo4j-10.0.0.pre.alpha.4 lib/neo4j/migrations/schema.rb
neo4j-10.0.0.pre.alpha.3 lib/neo4j/migrations/schema.rb
neo4j-10.0.0.pre.alpha.2 lib/neo4j/migrations/schema.rb
neo4j-10.0.0.pre.alpha.1 lib/neo4j/migrations/schema.rb
neo4j-9.6.1 lib/neo4j/migrations/schema.rb
neo4j-9.6.0 lib/neo4j/migrations/schema.rb
neo4j-9.5.3 lib/neo4j/migrations/schema.rb
neo4j-9.5.2 lib/neo4j/migrations/schema.rb
neo4j-9.5.0 lib/neo4j/migrations/schema.rb
neo4j-9.4.0 lib/neo4j/migrations/schema.rb
neo4j-9.3.0 lib/neo4j/migrations/schema.rb
neo4j-9.2.4 lib/neo4j/migrations/schema.rb
neo4j-9.2.3 lib/neo4j/migrations/schema.rb
neo4j-9.2.2 lib/neo4j/migrations/schema.rb
neo4j-9.2.1 lib/neo4j/migrations/schema.rb
neo4j-9.2.0 lib/neo4j/migrations/schema.rb