Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neo4J Support in Go Migrate [WIP] #1

Merged
merged 7 commits into from
Jan 7, 2020
Merged

Neo4J Support in Go Migrate [WIP] #1

merged 7 commits into from
Jan 7, 2020

Conversation

mvid
Copy link
Owner

@mvid mvid commented Jan 6, 2020

My attempt at providing an implementation of migrate for Neo4J. Based on previous work by @axiomzen here

  • Implement this interface.
  • Optionally, add a function named WithInstance. This function should accept an existing DB instance and a Config{} struct and return a driver instance.
  • Add a test that calls database/testing.go:Test()
  • Add own tests for Open(), WithInstance() (when provided) and Close(). All other functions are tested by tests in database/testing. Saves you some time and makes sure all database drivers behave the same way.
  • Call Register in init().
  • Create a internal/cli/build_<driver-name>.go file
  • Add driver name in 'DATABASE' variable in Makefile

@mvid mvid changed the title Neo4J Support in Go Migrate Neo4J Support in Go Migrate [WIP] Jan 6, 2020
@mvid
Copy link
Owner Author

mvid commented Jan 6, 2020

Some current issues I am dealing with:

  • The official Neo4J Go driver requires a c library called seabolt to be installed on the user system. That probably isn't acceptable for everyone who wants to work on go-migrate, so I will need to find some solution, maybe a feature flag to keep the neo code from being loaded in the full test suite, or have it run in a docker container with the library built.
  • Neo4J doesn't have a DB locking mechanism, though that isn't required for go-migrate
  • Neo4J's official driver doesn't pull auth information from the URL, so I am doing that in the Open() function. Ideally the driver would handle this itself.

@mvid mvid self-assigned this Jan 6, 2020
@mvid
Copy link
Owner Author

mvid commented Jan 6, 2020

The Driver definition file mentions that you can return nil if locking isn't supported, but the test for locking/unlocking then fails. This might be an oversight in the spec. This is something I will need to discuss with the go migrate maintainers

@mvid
Copy link
Owner Author

mvid commented Jan 6, 2020

@ACPrice and @jomarquez

Copy link

@EricLin2004 EricLin2004 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments, keep in mind I haven't touched neo4j in a long time nor have I messed with go migrate in awhile so might not be too relevant.

}

func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
ip, port, err := c.Port(7687)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded port?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for a test, the function asks the docker test suite which docker port has been mapped to 7687, which is the bolt exposed port in the neo docker container. In real usage, the port would be provided by the URL the user gives


func (n *Neo4J) Unlock() error {
return nil
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these? Just to fulfill interface methods?

doesn't seem like we need a sync.Mutex for Neo4J struct.

Also now that I see it, did you mean to have capital J for Neo4J?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is a generic Driver interface that go migrate has you fill out, and requests you return nil if the database isn't capable of locking (which Neo isn't).

You are correct about the J, I have replaced it with lowercase

defer session.Close()

_, err = session.Run("MERGE (sm:$migration {version: $version, dirty: $dirty})",
map[string]interface{}{"migration": n.config.MigrationsLabel, "version": version, "dirty": dirty})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm with this, wouldn't it be possible to get two nodes with same version but differing dirty bool state?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be because we run a ensureVersionConstraint function during driver creation that enforces a unique constraint on version number

version = -1
}

return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't return version here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the variable are named in the function signature, they will all be returned with an empty return statement. I have changed it to return explicitly for consistency

@mvid mvid merged commit 85e0676 into master Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants