Documentation ¶
Index ¶
- Constants
- Variables
- type DefaultLogger
- func (l *DefaultLogger) Error(args ...any)
- func (l *DefaultLogger) Errorf(format string, args ...any)
- func (l *DefaultLogger) Fatal(args ...any)
- func (l *DefaultLogger) Fatalf(format string, args ...any)
- func (l *DefaultLogger) Info(args ...any)
- func (l *DefaultLogger) Infof(format string, args ...any)
- type Executor
- type ExecutorOption
- type LogWriter
- type Logger
- type Migration
- type MigrationItem
- type MigrationStatus
- type Operation
- type OperationFn
- func AddEdgeOperation(o *Operation) OperationFn
- func AddVertexOperation(o *Operation) OperationFn
- func CreateAnalyzerOperation(o *Operation) OperationFn
- func CreateCollectionOperation(o *Operation) OperationFn
- func CreateFulltextIndexOperation(o *Operation) OperationFn
- func CreateGeoSpatialIndexOperation(o *Operation) OperationFn
- func CreateGraphOperation(o *Operation) OperationFn
- func CreateHashIndexOperation(o *Operation) OperationFn
- func CreateInvertedIndexOperation(o *Operation) OperationFn
- func CreatePersistentIndexOperation(o *Operation) OperationFn
- func CreateSkipListIndexOperation(o *Operation) OperationFn
- func CreateTTLIndexOperation(o *Operation) OperationFn
- func CreateViewOperation(o *Operation) OperationFn
- func CreateZKDIndexOperation(o *Operation) OperationFn
- func DeleteAnalyzerOperation(o *Operation) OperationFn
- func DeleteCollectionOperation(o *Operation) OperationFn
- func DeleteGraphOperation(o *Operation) OperationFn
- func DeleteIndexOperation(o *Operation) OperationFn
- func DeleteViewOperation(o *Operation) OperationFn
- func ExecuteAQLOperation(o *Operation) OperationFn
- func RemoveEdgeOperation(o *Operation) OperationFn
- func RemoveVertexOperation(o *Operation) OperationFn
- func UpdateCollectionOperation(o *Operation) OperationFn
- func UpdateViewOperation(o *Operation) OperationFn
- type OperationKind
Constants ¶
const (
// DefaultMigrationCollection is the default collection name for the collection storing migrations.
DefaultMigrationCollection = "migrations"
)
Variables ¶
var ( // ErrNoCollection is returned when no collection is provided. ErrNoCollection = fmt.Errorf("no collection provided") // ErrNoDatabase is returned when no database is provided. ErrNoDatabase = fmt.Errorf("no database provided") )
var ( // ErrInvalidMigrationStatus is returned when an invalid migration status is provided. ErrInvalidMigrationStatus = fmt.Errorf("invalid migration status") // ErrNoMigrations is returned when no migrations are provided. ErrNoMigrations = fmt.Errorf("no migrations provided") // ErrMigrationFailed is returned when a migration has failed. ErrMigrationFailed = fmt.Errorf("migration failed") )
var ( // ErrInvalidOperationKind is returned when an invalid operation kind is // specified. ErrInvalidOperationKind = fmt.Errorf("invalid operation kind") )
var ( // ErrNoLogger is returned when no logger is provided. ErrNoLogger = fmt.Errorf("no logger provided") )
Functions ¶
This section is empty.
Types ¶
type DefaultLogger ¶
DefaultLogger is a logger that prints messages to stdout and exits on fatal messages.
func NewDefaultLogger ¶
func NewDefaultLogger() *DefaultLogger
NewDefaultLogger returns a new DefaultLogger.
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(args ...any)
func (*DefaultLogger) Errorf ¶
func (l *DefaultLogger) Errorf(format string, args ...any)
func (*DefaultLogger) Fatal ¶
func (l *DefaultLogger) Fatal(args ...any)
func (*DefaultLogger) Fatalf ¶
func (l *DefaultLogger) Fatalf(format string, args ...any)
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(args ...any)
func (*DefaultLogger) Infof ¶
func (l *DefaultLogger) Infof(format string, args ...any)
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor executes migrations on a database in order.
func NewExecutor ¶
func NewExecutor(opts ...ExecutorOption) (*Executor, error)
NewExecutor creates a new Executor. If no migrations are provided, an error is returned.
type ExecutorOption ¶
ExecutorOption is a function that sets configuration options on Executor.
func WithCollection ¶
func WithCollection(collection string) ExecutorOption
WithCollection sets the collection of the executor.
func WithDatabase ¶
func WithDatabase(db driver.Database) ExecutorOption
WithDatabase sets the database of the executor.
func WithLogger ¶
func WithLogger(logger Logger) ExecutorOption
WithLogger sets the logger of the executor.
func WithMigrations ¶
func WithMigrations(migrations []*Migration) ExecutorOption
WithMigrations sets the migrations of the executor.
type Logger ¶
type Logger interface { // Info logs an informational message. Info(args ...any) // Infof logs a formatted informational message. Infof(format string, args ...any) // Error logs an error message. Error(args ...any) // Errorf logs a formatted error message. Errorf(format string, args ...any) // Fatal logs a fatal message and exits. Fatal(args ...any) // Fatalf logs a formatted fatal message and exits. Fatalf(format string, args ...any) }
Logger is an interface that is used to log messages.
type Migration ¶
type Migration struct { ID int `yaml:"id"` Path string `yaml:"-"` Status MigrationStatus `yaml:"-"` Operations []*Operation `yaml:"operations"` }
Migration is a migration that can be run on a database.
func (*Migration) Checksum ¶
Checksum returns the checksum of the migration. The checksum is the SHA256 hash of the ID and operations of the migration file. It is used to determine if a migration has been run already.
type MigrationItem ¶
type MigrationItem struct { Key string `json:"_key"` Name string `json:"name"` Status MigrationStatus `json:"status"` AppliedAt time.Time `json:"appliedAt"` }
MigrationItem represents a migration in the collection.
type MigrationStatus ¶
type MigrationStatus int
MigrationStatus is the status of a migration.
const ( // MigrationStatusMissing is the status of a migration that is missing. MigrationStatusMissing MigrationStatus = iota // MigrationStatusRunning is the status of a migration that is currently running. MigrationStatusRunning // MigrationStatusDone is the status of a migration that has been run. MigrationStatusDone // MigrationStatusFailed is the status of a migration that has failed. MigrationStatusFailed )
func (*MigrationStatus) MarshalJSON ¶
func (s *MigrationStatus) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*MigrationStatus) UnmarshalJSON ¶
func (s *MigrationStatus) UnmarshalJSON(status []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type Operation ¶
type Operation struct { Kind OperationKind `yaml:"kind"` Collection string `yaml:"collection"` Options map[string]any `yaml:"options"` }
Operation is an operation to run in a migration.
func (*Operation) GetOperationFn ¶
func (o *Operation) GetOperationFn() (OperationFn, error)
GetOperationFn returns the operation function for the operation kind.
type OperationFn ¶
OperationFn runs an operation on a database.
func AddEdgeOperation ¶
func AddEdgeOperation(o *Operation) OperationFn
AddEdgeOperation adds an edge definition to a graph.
func AddVertexOperation ¶
func AddVertexOperation(o *Operation) OperationFn
AddVertexOperation adds a vertex collection to a graph.
func CreateAnalyzerOperation ¶ added in v0.3.0
func CreateAnalyzerOperation(o *Operation) OperationFn
func CreateCollectionOperation ¶
func CreateCollectionOperation(o *Operation) OperationFn
CreateCollectionOperation creates a collection.
func CreateFulltextIndexOperation ¶
func CreateFulltextIndexOperation(o *Operation) OperationFn
func CreateGeoSpatialIndexOperation ¶
func CreateGeoSpatialIndexOperation(o *Operation) OperationFn
func CreateGraphOperation ¶
func CreateGraphOperation(o *Operation) OperationFn
CreateGraphOperation creates a graph.
func CreateHashIndexOperation ¶
func CreateHashIndexOperation(o *Operation) OperationFn
func CreateInvertedIndexOperation ¶
func CreateInvertedIndexOperation(o *Operation) OperationFn
func CreatePersistentIndexOperation ¶
func CreatePersistentIndexOperation(o *Operation) OperationFn
func CreateSkipListIndexOperation ¶
func CreateSkipListIndexOperation(o *Operation) OperationFn
func CreateTTLIndexOperation ¶
func CreateTTLIndexOperation(o *Operation) OperationFn
func CreateViewOperation ¶
func CreateViewOperation(o *Operation) OperationFn
CreateViewOperation creates a search view.
func CreateZKDIndexOperation ¶
func CreateZKDIndexOperation(o *Operation) OperationFn
func DeleteAnalyzerOperation ¶ added in v0.3.0
func DeleteAnalyzerOperation(o *Operation) OperationFn
func DeleteCollectionOperation ¶
func DeleteCollectionOperation(o *Operation) OperationFn
DeleteCollectionOperation removes a collection.
func DeleteGraphOperation ¶
func DeleteGraphOperation(o *Operation) OperationFn
DeleteGraphOperation deletes a graph.
func DeleteIndexOperation ¶
func DeleteIndexOperation(o *Operation) OperationFn
func DeleteViewOperation ¶
func DeleteViewOperation(o *Operation) OperationFn
DeleteViewOperation removes a search view.
func ExecuteAQLOperation ¶
func ExecuteAQLOperation(o *Operation) OperationFn
ExecuteAQLOperation executes an AQL query.
func RemoveEdgeOperation ¶
func RemoveEdgeOperation(o *Operation) OperationFn
RemoveEdgeOperation removes an edge definition from a graph.
func RemoveVertexOperation ¶
func RemoveVertexOperation(o *Operation) OperationFn
RemoveVertexOperation removes a vertex collection from a graph.
func UpdateCollectionOperation ¶
func UpdateCollectionOperation(o *Operation) OperationFn
UpdateCollectionOperation updates a collection.
func UpdateViewOperation ¶
func UpdateViewOperation(o *Operation) OperationFn
UpdateViewOperation updates an existing search view.
type OperationKind ¶
type OperationKind int
OperationKind is the kind of operation to run.
const ( OperationKindAQLExecute OperationKind = iota + 1 // operation to execute an AQL query OperationKindCollectionCreate // operation to create a collection OperationKindCollectionUpdate // operation to update a collection OperationKindCollectionDelete // operation to delete a collection OperationKindGraphCreate // operation to create a graph OperationKindGraphAddVertex // operation to add a vertex collection to a graph OperationKindGraphRemoveVertex // operation to remove a vertex collection from a graph OperationKindGraphAddEdge // operation to add an edge definition to a graph OperationKindGraphRemoveEdge // operation to remove an edge definition from a graph OperationKindGraphDelete // operation to delete a graph OperationKindViewCreate // operation to create a view OperationKindViewUpdate // operation to update a view OperationKindViewDelete // operation to delete a view OperationKindFulltextIndexCreate // operation to create a fulltext index OperationKindGeoSpatialIndexCreate // operation to create a geospatial index OperationKindHashIndexCreate // operation to create a hash index OperationKindInvertedIndexCreate // operation to create an inverted index OperationKindPersistentIndexCreate // operation to create a persistent index OperationKindSkipListIndexCreate // operation to create a skiplist index OperationKindTTLIndexCreate // operation to create a TTL index OperationKindZKDIndexCreate // operation to create a ZKD index OperationKindIndexDelete // operation to delete an index OperationKindAnalyzerCreate // operation to delete an index OperationKindAnalyzerDelete // operation to delete an index )
func (*OperationKind) UnmarshalYAML ¶
func (o *OperationKind) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface.