Skip to content

Commit

Permalink
Merge pull request #49 from mindstand/v4-update
Browse files Browse the repository at this point in the history
updated to support neo4j v4
  • Loading branch information
nikitawootten authored Nov 6, 2020
2 parents 2c3db67 + f422687 commit 84fe1ac
Show file tree
Hide file tree
Showing 9 changed files with 833 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ version: '3'
networks:
lan:
services:
core1:
image: neo4j:3.5.17-enterprise
core:
image: neo4j:3.5-enterprise
networks:
- lan
ports:
Expand Down
24 changes: 24 additions & 0 deletions .github/docker-compose-v4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'
networks:
lan:
services:
core1:
image: neo4j:4.1-enterprise
networks:
- lan
ports:
- 7474:7474
- 6477:6477
- 7687:7687
environment:
- NEO4J_apoc_export_file_enabled=true
- NEO4J_apoc_import_file_enabled=true
- NEO4J_dbms_security_procedures_unrestricted=apoc.*,algo.*
- NEO4J_dbms_memory_heap_initial__size=512m
- NEO4J_dbms_memory_heap_max__size=2G
- NEO4J_apoc_uuid_enabled=true
- NEO4J_dbms_default__listen__address=0.0.0.0
- NEO4J_dbms_allow__upgrade=true
- NEO4J_dbms_default__database=neo4j
- NEO4J_AUTH=neo4j/changeme
- NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
24 changes: 18 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,27 @@ jobs:
run: go build -v .
- name: Run Unit Tests
run: go test ./... -cover -short
- name: Start Neo4j Docker

- name: Start Neo4j V3 Docker
run: |
docker-compose -f .github/docker-compose.yaml up -d
- name: Wait for neo4j to be ready
docker-compose -f .github/docker-compose-v3.yaml up -d
- name: Wait for neo4j v3 to be ready
run: |
sleep 45
- name: Run Integration Test
- name: Run Integration Test on V3
run: go test ./... -cover -run Integration
- name: Stop Neo4j Docker
- name: Stop Neo4j Docker on v3
run: |
docker-compose -f .github/docker-compose.yaml down --remove-orphans
docker-compose -f .github/docker-compose-v3.yaml down --remove-orphans
- name: Start Neo4j V4 Docker
run: |
docker-compose -f .github/docker-compose-v4.yaml up -d
- name: Wait for neo4j v4 to be ready
run: |
sleep 45
- name: Run Integration Test on V4
run: go test ./... -cover -run Integration
- name: Stop Neo4j Docker on v4
run: |
docker-compose -f .github/docker-compose-v4.yaml down --remove-orphans
47 changes: 47 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import (
"github.com/neo4j/neo4j-go-driver/neo4j"
"github.com/sirupsen/logrus"
"reflect"
"strconv"
"strings"
)

var externalLog *logrus.Entry
var neoVersion float64

var log = getLogger()

Expand All @@ -52,6 +55,10 @@ func SetLogger(logger *logrus.Entry) error {
return nil
}

func getIsV4() bool {
return true
}

// Config Defined GoGM config
type Config struct {
// Host is the neo4j host
Expand All @@ -76,6 +83,7 @@ type Config struct {

// Index Strategy defines the index strategy for GoGM
IndexStrategy IndexStrategy `yaml:"index_strategy" json:"index_strategy" mapstructure:"index_strategy"`
TargetDbs []string `yaml:"target_dbs" json:"target_dbs" mapstructure:"target_dbs"`
}

// ConnectionString builds the neo4j bolt/bolt+routing connection string
Expand Down Expand Up @@ -132,6 +140,8 @@ func Reset() {
isSetup = false
}

var internalConfig *Config

// internal setup logic for gogm
func setupInit(isTest bool, conf *Config, mapTypes ...interface{}) error {
if isSetup && !isTest {
Expand All @@ -146,6 +156,18 @@ func setupInit(isTest bool, conf *Config, mapTypes ...interface{}) error {
}
}

if conf != nil {
if conf.TargetDbs == nil || len(conf.TargetDbs) == 0 {
conf.TargetDbs = []string{"neo4j"}
}

internalConfig = conf
} else {
internalConfig = &Config{
TargetDbs: []string{"neo4j"},
}
}

log.Debug("mapping types")
for _, t := range mapTypes {
name := reflect.TypeOf(t).Elem().Name()
Expand Down Expand Up @@ -176,6 +198,31 @@ func setupInit(isTest bool, conf *Config, mapTypes ...interface{}) error {
if err != nil {
return err
}

// get neoversion
sess, err := driver.Session(neo4j.AccessModeRead)
if err != nil {
return err
}

res, err := sess.Run("return 1", nil)
if err != nil {
return err
} else if err = res.Err(); err != nil {
return err
}

sum, err := res.Summary()
if err != nil {
return err
}

// grab version
version := strings.Split(strings.Replace(strings.ToLower(sum.Server().Version()), "neo4j/", "", -1), ".")
neoVersion, err = strconv.ParseFloat(version[0], 64)
if err != nil {
return err
}
}

log.Debug("starting index verification step")
Expand Down
Loading

0 comments on commit 84fe1ac

Please sign in to comment.