{"modulePath":"github.com/unity-technologies/migrate","version":"v3.5.4+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package database\n\nPackage database provides the Database interface. All database drivers must implement this interface, register themselves, optionally provide a \\`WithInstance\\` function and pass the tests in package database/testing.\n\n## Constants\n\n```go\nconst NilVersion int = -1\n```\n\n## Variables\n\n```go\nvar (\n\tErrLocked = fmt.Errorf(\"can't acquire lock\")\n)\n```\n\n## Functions\n\n```go\nfunc GenerateAdvisoryLockId(databaseName string) (string, error)\n```\nGenerateAdvisoryLockId inspired by rails migrations, see [https://goo.gl/8o9bCT](https://goo.gl/8o9bCT)\n\n```go\nfunc List() []string\n```\nList lists the registered drivers\n\n```go\nfunc Register(name string, driver Driver)\n```\nRegister globally registers a driver.\n\n## Types\n\n```go\ntype Driver interface {\n\t// Open returns a new driver instance configured with parameters\n\t// coming from the URL string. Migrate will call this function\n\t// only once per instance.\n\tOpen(url string) (Driver, error)\n\n\t// Close closes the underlying database instance managed by the driver.\n\t// Migrate will call this function only once per instance.\n\tClose() error\n\n\t// Lock should acquire a database lock so that only one migration process\n\t// can run at a time. Migrate will call this function before Run is called.\n\t// If the implementation can't provide this functionality, return nil.\n\t// Return database.ErrLocked if database is already locked.\n\tLock() error\n\n\t// Unlock should release the lock. Migrate will call this function after\n\t// all migrations have been run.\n\tUnlock() error\n\n\t// Run applies a migration to the database. migration is garantueed to be not nil.\n\tRun(migration io.Reader) error\n\n\t// SetVersion saves version and dirty state.\n\t// Migrate will call this function before and after each call to Run.\n\t// version must be \u003e= -1. -1 means NilVersion.\n\tSetVersion(version int, dirty bool) error\n\n\t// Version returns the currently active version and if the database is dirty.\n\t// When no migration has been applied, it must return version -1.\n\t// Dirty means, a previous migration failed and user interaction is required.\n\tVersion() (version int, dirty bool, err error)\n\n\t// Drop deletes everything in the database.\n\tDrop() error\n}\n```\nDriver is the interface every database driver must implement.\n\nHow to implement a database driver?\n\n 1. Implement this interface.\n 2. Optionally, add a function named \\`WithInstance\\`. This function should accept an existing DB instance and a Config{} struct and return a driver instance.\n 3. Add a test that calls database/testing.go:Test()\n 4. 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.\n 5. Call Register in init().\n 6. Create a migrate/cli/build\\_\\\u003cdriver-name\u003e.go file\n 7. Add driver name in 'DATABASE' variable in Makefile\n\nGuidelines:\n\n  - Don't try to correct user input. Don't assume things. When in doubt, return an error and explain the situation to the user.\n  - All configuration input must come from the URL string in func Open() or the Config{} struct in WithInstance. Don't os.Getenv().\n\n```go\nfunc Open(url string) (Driver, error)\n```\nOpen returns a new driver instance.\n\n```go\ntype Error struct {\n\t// Optional: the line number\n\tLine uint\n\n\t// Query is a query excerpt\n\tQuery []byte\n\n\t// Err is a useful/helping error message for humans\n\tErr string\n\n\t// OrigErr is the underlying error\n\tOrigErr error\n}\n```\nError should be used for errors involving queries ran against the database\n\n```go\nfunc (e Error) Error() string\n```\n\n","path":"github.com/unity-technologies/migrate/database","name":"database","synopsis":"Package database provides the Database interface.","isRedistributable":true}
