Documentation ¶
Overview ¶
Package migrator is responsible for planning and executing cypher migrations.
Index ¶
- type Batch
- type Builder
- type DatabaseGraphVersion
- type DatabaseModel
- func (dbm DatabaseModel) ContainsHigherVersion(folder string, version *semver.Version) bool
- func (dbm DatabaseModel) GetFileTimestamps(folder string, version *semver.Version) map[int64]bool
- func (dbm DatabaseModel) HasAnyVersion() bool
- func (dbm DatabaseModel) MarshalJSON() ([]byte, error)
- func (dbm DatabaseModel) String() string
- type ExecutionStep
- type ExecutionSteps
- type FileType
- type LocalFolders
- type LocalVersionFolder
- type MigrationFile
- type MigrationScripts
- type Neo4jSession
- type Planner
- func (p *Planner) CreateBuilder(steps *ExecutionSteps, abs bool) Builder
- func (p *Planner) NewScanner(root string) (*Scanner, error)
- func (p *Planner) Plan(localFolders LocalFolders, dbModel DatabaseModel, targetVersion *TargetVersion, ...) error
- func (p *Planner) Version(ctx context.Context, session neo4j.SessionWithContext) (DatabaseModel, error)
- type Scanner
- type TargetVersion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder func(cf *MigrationFile, version *semver.Version) error
type DatabaseGraphVersion ¶
DatabaseGraphVersion holds all executed files per version.
type DatabaseModel ¶
type DatabaseModel map[string][]DatabaseGraphVersion
DatabaseModel holds database version of all migrations of all folders. Key is folder name and value contains all applied versions with all executed files.
func (DatabaseModel) ContainsHigherVersion ¶
func (dbm DatabaseModel) ContainsHigherVersion(folder string, version *semver.Version) bool
ContainsHigherVersion check if there is folder with higher version than specified.
func (DatabaseModel) GetFileTimestamps ¶
func (dbm DatabaseModel) GetFileTimestamps(folder string, version *semver.Version) map[int64]bool
GetFileTimestamps returns all executed files from DB.
func (DatabaseModel) HasAnyVersion ¶
func (dbm DatabaseModel) HasAnyVersion() bool
HasAnyVersion checks if there is any version stored in DB.
func (DatabaseModel) MarshalJSON ¶
func (dbm DatabaseModel) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of DatabaseModel.
func (DatabaseModel) String ¶
func (dbm DatabaseModel) String() string
String converts DatabaseModel into JSON which is shrink.
type ExecutionStep ¶
type ExecutionStep struct {
// contains filtered or unexported fields
}
func (ExecutionStep) Command ¶
func (s ExecutionStep) Command() []string
Command returns current command with all parameters.
func (ExecutionStep) Cypher ¶
func (s ExecutionStep) Cypher() *bytes.Buffer
Cypher returns buffer with all cyphers in current step.
func (ExecutionStep) IsCypher ¶
func (s ExecutionStep) IsCypher() bool
IsCypher returns true if current step is Cypher. But does not check if cypher really contains something. So returns true for empty Cypher too.
type ExecutionSteps ¶
type ExecutionSteps []ExecutionStep
func (*ExecutionSteps) AddCommand ¶
func (e *ExecutionSteps) AddCommand(args []string)
AddCommand adds command with parameters to step list.
func (*ExecutionSteps) AddCypher ¶
func (e *ExecutionSteps) AddCypher(cypher ...string)
AddCypher adds all Cyphers into one buffer. If current step is Cypher as well, it is reused. Otherwise new buffer is created.
func (ExecutionSteps) IsEmpty ¶
func (e ExecutionSteps) IsEmpty() bool
IsEmpty checks if there are steps to do.
func (ExecutionSteps) String ¶
func (e ExecutionSteps) String() string
String converts all cyphers and command calls into single long string. Is not really suitable for Cypher shell, but can be used for debug print.
type LocalFolders ¶
type LocalFolders []*LocalVersionFolder
LocalFolders handles all migration files for all versions across all folders.
func (LocalFolders) SortByVersion ¶
func (lc LocalFolders) SortByVersion()
SortByVersion all folders in ascending order.
type LocalVersionFolder ¶
type LocalVersionFolder struct { Version *semver.Version // SchemaFolder contains all up/down files of base schema folder. SchemaFolder *MigrationScripts // ExtraFolders contains all up/down files per folder, which name is key of the map. ExtraFolders map[string]*MigrationScripts // Snapshots contains all snapshot files for given version per batch, which name is key of the map. Snapshots map[Batch]*MigrationFile }
LocalVersionFolder handles all migration files for single version across all folders.
type MigrationFile ¶
type MigrationFile struct { FolderName string Path string FileType FileType Timestamp int64 IsDowngrade bool IsSnapshot bool }
MigrationFile specify all details about single file to run during migration.
type MigrationScripts ¶
type MigrationScripts struct { Up []*MigrationFile Down []*MigrationFile }
MigrationScripts handles all up and potentially down files. If folder is 'change' type, only up files are used as this is only applied during up action.
func (*MigrationScripts) Add ¶
func (ms *MigrationScripts) Add(in *MigrationScripts)
Add merge migrations scripts with in scripts.
func (*MigrationScripts) ContainsMigrations ¶
func (ms *MigrationScripts) ContainsMigrations() bool
ContainsMigrations verify if there is at least some up or down migration.
func (*MigrationScripts) SortDownFiles ¶
func (ms *MigrationScripts) SortDownFiles()
SortDownFiles in descending order.
func (*MigrationScripts) SortUpFiles ¶
func (ms *MigrationScripts) SortUpFiles()
SortUpFiles in ascending order.
type Neo4jSession ¶ added in v0.1.1
type Neo4jSession struct {
neo4j.SessionWithContext
}
type Planner ¶
type Planner struct {
// contains filtered or unexported fields
}
func NewPlanner ¶
NewPlanner creates Planner instance and returns error if provided config is not valid.
func (*Planner) CreateBuilder ¶
func (p *Planner) CreateBuilder(steps *ExecutionSteps, abs bool) Builder
CreateBuilder creates default Cypher builder.
func (*Planner) NewScanner ¶
NewScanner creates file scanner.
func (*Planner) Plan ¶
func (p *Planner) Plan( localFolders LocalFolders, dbModel DatabaseModel, targetVersion *TargetVersion, batch Batch, builder Builder, ) error
Plan prepares execution plan with given builder.
func (*Planner) Version ¶
func (p *Planner) Version(ctx context.Context, session neo4j.SessionWithContext) (DatabaseModel, error)
Version retrieves version of current state of DB.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
func (*Scanner) GenerateMigrationFiles ¶
func (s *Scanner) GenerateMigrationFiles( folderName string, version *TargetVersion, migrationName string, upType, downType FileType, ) ([]string, error)
GenerateMigrationFiles creates empty files based on config and passed arguments.
func (*Scanner) ScanFolders ¶
func (s *Scanner) ScanFolders() (LocalFolders, error)
ScanFolders start scanning and returns all up and down files divided per version and revision. Result is not sorted by default, use SortByVersion() to sort it by semver version.
type TargetVersion ¶
type TargetVersion struct { Version *semver.Version `json:"version,omitempty"` Revision int64 `json:"rev,omitempty"` }
TargetVersion holds version of a graph.
func ParseTargetVersion ¶
func ParseTargetVersion(v string) (*TargetVersion, error)
ParseTargetVersion parse string as semver version with revision.
func (*TargetVersion) Set ¶
func (a *TargetVersion) Set(v string) error
Set sets version from string. Can be used with flag package.
func (*TargetVersion) String ¶
func (a *TargetVersion) String() string
func (*TargetVersion) Type ¶
func (*TargetVersion) Type() string
Type returns type name, so it can be used with flag package.