Documentation ¶
Index ¶
- Constants
- Variables
- func Register(name string, driver Driver)
- type CustomList
- type Database
- type Driver
- type HasuraOpts
- type MetadataDriver
- type MigrationVersion
- type Migrations
- func (m *Migrations) Append(migrationVersion MigrationVersion)
- func (m *Migrations) First() (migrationVersion *MigrationVersion, ok bool)
- func (m *Migrations) Last() (*MigrationVersion, bool)
- func (m *Migrations) Next(version uint64) (migrationVersion *MigrationVersion, ok bool)
- func (m *Migrations) Prev(version uint64) (prevVersion *MigrationVersion, ok bool)
- func (m *Migrations) Read(version uint64) (ok bool)
- type SchemaDriver
- type SettingsDriver
Constants ¶
View Source
const NilVersion int64 = -1
Variables ¶
View Source
var (
ErrLocked = fmt.Errorf("can't acquire lock")
)
Functions ¶
Types ¶
type CustomList ¶
func (*CustomList) Iterate ¶
func (c *CustomList) Iterate() linq.Iterator
type Driver ¶
type Driver interface { // Open returns a new driver instance configured with parameters // coming from the URL string. Migrate will call this function // only once per instance. Open(url string, isCMD bool, logger *log.Logger, hasuraOpts *HasuraOpts) (Driver, error) // Close closes the underlying database instance managed by the driver. // Migrate will call this function only once per instance. Close() error Scan() error // Lock should acquire a database lock so that only one migration process // can run at a time. Migrate will call this function before Run is called. // If the implementation can't provide this functionality, return nil. // Return database.ErrLocked if database is already locked. Lock() error // Unlock should release the lock. Migrate will call this function after // all migrations have been run. UnLock() error // RunSeq applies a migration to the database in a sequential fashion. migration is guaranteed to be not nil. Run(migration io.Reader, fileType, fileName string) error // Reset Migration Query Args ResetQuery() // InsertVersion saves version // Migrate will call this function before and after each call to Run. // version must be >= -1. -1 means NilVersion. InsertVersion(version int64) error // SetVersion saves version and dirty state. // Migrate will call this function before and after each call to Run. // version must be >= -1. -1 means NilVersion. SetVersion(version int64, dirty bool) error RemoveVersion(version int64) error // Version returns the currently active version and if the database is dirty. // When no migration has been applied, it must return version -1. // Dirty means, a previous migration failed and user interaction is required. Version() (version int64, dirty bool, err error) // First returns the very first migration version available to the driver. // Migrate will call this function multiple times First() (migrationVersion *MigrationVersion, ok bool) // Last returns the latest version available in database Last() (*MigrationVersion, bool) // Prev returns the previous version for a given version available to the driver. // Migrate will call this function multiple times. // If there is no previous version available, it must return os.ErrNotExist. Prev(version uint64) (prevVersion *MigrationVersion, ok bool) // Next returns the next version for a given version available to the driver. // Migrate will call this function multiple times. // If there is no next version available, it must return os.ErrNotExist. Next(version uint64) (migrationVersion *MigrationVersion, ok bool) Read(version uint64) (ok bool) PushToList(migration io.Reader, fileType string, list *CustomList) error Squash(list *CustomList, ret chan<- interface{}) MetadataDriver SchemaDriver SettingsDriver Query(data interface{}) error }
Driver is the interface every database driver must implement.
How to implement a database driver?
- 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 migrate/cli/build_<driver-name>.go file
- Add driver name in 'DATABASE' variable in Makefile
Guidelines:
- Don't try to correct user input. Don't assume things. When in doubt, return an error and explain the situation to the user.
- All configuration input must come from the URL string in func Open() or the Config{} struct in WithInstance. Don't os.Getenv().
type HasuraOpts ¶
type HasuraOpts struct { HasMetadataV3 bool SourceName string SourceKind hasura.SourceKind Client *hasura.Client PGSourceOps hasura.PGSourceOps MSSQLSourceOps hasura.MSSQLSourceOps CitusSourceOps hasura.CitusSourceOps MetadataOps hasura.CommonMetadataOperations V2MetadataOps hasura.V2CommonMetadataOperations GenericQueryRequest hasura.GenericSend PGDumpClient hasura.PGDump MigrationsStateStore statestore.MigrationsStateStore SettingsStateStore statestore.SettingsStateStore }
type MetadataDriver ¶
type MetadataDriver interface {
EnableCheckMetadataConsistency(bool)
}
type MigrationVersion ¶
type Migrations ¶
type Migrations struct {
// contains filtered or unexported fields
}
Migrations wraps Migration and has an internal index to keep track of Migration order in database.
func NewMigrations ¶
func NewMigrations() *Migrations
func (*Migrations) Append ¶
func (m *Migrations) Append(migrationVersion MigrationVersion)
func (*Migrations) First ¶
func (m *Migrations) First() (migrationVersion *MigrationVersion, ok bool)
func (*Migrations) Last ¶
func (m *Migrations) Last() (*MigrationVersion, bool)
func (*Migrations) Next ¶
func (m *Migrations) Next(version uint64) (migrationVersion *MigrationVersion, ok bool)
func (*Migrations) Prev ¶
func (m *Migrations) Prev(version uint64) (prevVersion *MigrationVersion, ok bool)
func (*Migrations) Read ¶
func (m *Migrations) Read(version uint64) (ok bool)
type SchemaDriver ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.