Skip to content

Commit

Permalink
fixed index issue
Browse files Browse the repository at this point in the history
  • Loading branch information
erictg committed Sep 18, 2019
1 parent 798b573 commit fcde285
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
32 changes: 22 additions & 10 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ func dropAllIndexesAndConstraints() error{
if err != nil {
return err
}
driverPool.Reclaim(conn)
defer driverPool.Reclaim(conn)

constraintRows, err := dsl.QB().Cypher("CALL db.constraints").WithNeo(conn).Query(nil)
if err != nil{
return err
}

defer constraintRows.Close()

constraints, err := dsl.RowsToStringArray(constraintRows)
if err != nil{
return err
}

err = constraintRows.Close()
if err != nil {
return err
}

//if there is anything, get rid of it
if len(constraints) != 0{
tx, err := conn.Begin()
Expand Down Expand Up @@ -61,13 +64,16 @@ func dropAllIndexesAndConstraints() error{
return err
}

defer indexRows.Close()

indexes, err := dsl.RowsTo2DInterfaceArray(indexRows)
if err != nil{
return err
}

err = indexRows.Close()
if err != nil {
return err
}

//if there is anything, get rid of it
if len(indexes) != 0{
tx, err := conn.Begin()
Expand Down Expand Up @@ -104,7 +110,7 @@ func createAllIndexesAndConstraints(mappedTypes *hashmap.HashMap) error{
if err != nil {
return err
}
driverPool.Reclaim(conn)
defer driverPool.Reclaim(conn)

//validate that we have to do anything
if mappedTypes == nil || mappedTypes.Len() == 0{
Expand Down Expand Up @@ -235,27 +241,33 @@ func verifyAllIndexesAndConstraints(mappedTypes *hashmap.HashMap) error{
return err
}

defer constRows.Close()

foundConstraints, err := dsl.RowsToStringArray(constRows)
if err != nil{
return err
}

err = constRows.Close()
if err != nil {
return err
}

var foundIndexes []string

indexRows, err := dsl.QB().WithNeo(conn).Cypher("CALL db.indexes()").Query(nil)
if err != nil{
return err
}

defer indexRows.Close()

findexes, err := dsl.RowsTo2DInterfaceArray(indexRows)
if err != nil{
return err
}

err = indexRows.Close()
if err != nil {
return err
}

if len(findexes) != 0{
for _, index := range findexes{
if len(index) == 0{
Expand Down
30 changes: 21 additions & 9 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestDropAllIndexesAndConstraints(t *testing.T){
if err != nil {
require.Nil(t, err)
}
driverPool.Reclaim(conn)
defer driverPool.Reclaim(conn)
require.Nil(t, err)

err = dropAllIndexesAndConstraints()
Expand All @@ -44,19 +44,31 @@ func TestDropAllIndexesAndConstraints(t *testing.T){

func TestIndexManagement(t *testing.T){
//requires connection
if !testing.Short(){
t.SkipNow()
return
}
//if !testing.Short(){
// t.SkipNow()
// return
//}

req := require.New(t)

var err error

conf := Config{
Username: "neo4j",
Password: "password",
Host: "0.0.0.0",
Port: 7687,
PoolSize: 15,
}

driverPool, err = driver.NewClosableDriverPool(conf.ConnectionString(), conf.PoolSize)
req.Nil(err)

//init
conn, err := driverPool.Open(driver.ReadWriteMode)
if err != nil {
require.Nil(t, err)
}
driverPool.Reclaim(conn)
require.Nil(t, err)

defer driverPool.Reclaim(conn)
req.Nil(err)

//delete everything
Expand Down

0 comments on commit fcde285

Please sign in to comment.