Documentation ¶
Index ¶
- Constants
- type Change
- type Command
- type Config
- type Diff
- type Fig
- type FigMigrator
- type FigStager
- type GoFig
- type Migration
- type Migrator
- func (m *Migrator) LoadMigration() error
- func (m *Migrator) PrepMigration() error
- func (m *Migrator) PresentMigration()
- func (m *Migrator) RunMigration()
- func (m *Migrator) SetDeleteFlag(flag string)
- func (m *Migrator) Stage() FigStager
- func (m *Migrator) Store(target any, tag string) error
- func (m *Migrator) StoreMigration() error
- type Stager
- func (s Stager) Add(colPath string, data map[string]any) error
- func (s Stager) Delete(docPath string) error
- func (s Stager) Set(docPath string, data map[string]any) error
- func (s Stager) Unknown(docPath string, data map[string]any) error
- func (s Stager) Update(docPath string, data map[string]any) error
- type WorkUnit
Constants ¶
const ( Serialize transformMode = iota DeSerialize Exclude )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
// contains filtered or unexported fields
}
Change represents one change on one document. A change must contain enough data points to be solved. For example, given a before and a patch, we can solve for the after value.
func NewChange ¶
func NewChange(docPath string, before map[string]any, patch map[string]any, command Command, database figFirestore) *Change
NewChange is a Change factory.
func (*Change) Present ¶
Present returns a pretty representation of the change for printing to stdout.
func (*Change) SolveChange ¶
SolveChange will attempt to solve for all needed Change values given the current state.
type Command ¶
type Command int
Command is an enum of supported Change command types for example 'Update'.
type Diff ¶ added in v0.1.1
type Diff struct {
Diff string `json:"diff" firestore:"diff,omitempty"`
}
Diff represents how we want to store our diffs
type Fig ¶
type Fig struct {
// contains filtered or unexported fields
}
Fig is meant to orchestrate Migrator functionality.
func (*Fig) Close ¶
func (c *Fig) Close()
Close should be deferred on initialization to handle any database session cleanup.
func (*Fig) DeleteField ¶
DeleteField is a shortcut to the controlled database DeleteField.
func (*Fig) LoadFromStorage ¶ added in v0.1.1
LoadFromStorage attempts to load a pre staged migration from a file if it exists in the storagePath folder
func (*Fig) ManageStagedMigration ¶
func (c *Fig) ManageStagedMigration()
ManageStagedMigration launches the interactive CLI script.
func (*Fig) SaveToStorage ¶ added in v0.1.1
SaveToStorage attempts to save a migration staged in runtime memory to a file in the storagePath folder
type FigMigrator ¶
type FigMigrator interface { SetDeleteFlag(flag string) PrepMigration() error PresentMigration() RunMigration() LoadMigration() error StoreMigration() error Stage() FigStager // contains filtered or unexported methods }
FigMigrator described what a GoFig Migrator implementeation should do.
type FigStager ¶
type FigStager interface { Update(docPath string, data map[string]any) error Set(docPath string, data map[string]any) error Add(colPath string, data map[string]any) error Delete(docPath string) error Unknown(docPath string, data map[string]any) error }
FigStager represents the staging API.
type GoFig ¶
type GoFig interface { Close() Stage() FigStager LoadFromStorage() error SaveToStorage() error ManageStagedMigration() DeleteField() any RefField(docPath string) any }
GoFig represents the main Fig API.
type Migration ¶
type Migration struct { DatabaseName string `json:"databaseName" firestore:"databaseName,omitempty"` Timestamp time.Time `json:"timestamp" firestore:"timestamp,omitempty"` ChangeUnits []WorkUnit `json:"changeUnits" firestore:"changeUnits,omitempty"` Executed bool `json:"executed" firestore:"executed,omitempty"` }
Migration represents all the instructions needed by the migrator to orchestrate a job. All migration jobs including rollbacks take this form.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is the API for performing migration tasks within a job it implements FigMigrator.
func NewMigrator ¶
NewMigrator is a Migrator factory.
func (*Migrator) LoadMigration ¶
LoadMigration will look for an existing migration file matching this Migrator's name. If a file exists, the state of the migrator will be replaced by the contents of the file. This is the preferred workflow for loading a rollback.
func (*Migrator) PrepMigration ¶
PrepMigration is run after all changes are staged. This function validates and solves all of the changes. No changes are pushed to the database.
func (*Migrator) PresentMigration ¶
func (m *Migrator) PresentMigration()
PresentMigration prints all the staged changes to stdout for review.
func (*Migrator) RunMigration ¶
func (m *Migrator) RunMigration()
RunMigration executes all of the staged changes against the database.
func (*Migrator) SetDeleteFlag ¶
SetDeleteFlag updates the Migrator delete flag with a new string value. When this value is on a Change field, that field is deleted from the database document when the change is pushed.
func (*Migrator) StoreMigration ¶
StoreMigration converts the Migrator state to a Migration file and stores it to disc.
type Stager ¶
type Stager struct {
// contains filtered or unexported fields
}
Stager is an abstraction on top of Migrator which is used as an API to stage new Change units on the Migrator.
type WorkUnit ¶
type WorkUnit struct { DocPath string `json:"docPath" firestore:"docpath,omitempty"` Patch map[string]any `json:"patch,omitempty" patch:"executed,omitempty"` Command Command `json:"command,omitempty" firestore:"command,omitempty"` }
WorkUnit is one change mapped to one document within a migration. You cannot have multiple work units pointing to the same document in a migration.