Documentation ¶
Index ¶
- Variables
- func TempFile(content, ext string) (string, func() error, error)
- type AppliedFile
- type Changes
- type Check
- type Client
- func (c *Client) Login(ctx context.Context, params *LoginParams) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) MigrateApply(ctx context.Context, params *MigrateApplyParams) (*MigrateApply, error)
- func (c *Client) MigrateApplySlice(ctx context.Context, params *MigrateApplyParams) ([]*MigrateApply, error)
- func (c *Client) MigrateDown(ctx context.Context, params *MigrateDownParams) (*MigrateDown, error)
- func (c *Client) MigrateLint(ctx context.Context, params *MigrateLintParams) (*SummaryReport, error)
- func (c *Client) MigrateLintError(ctx context.Context, params *MigrateLintParams) error
- func (c *Client) MigratePush(ctx context.Context, params *MigratePushParams) (string, error)
- func (c *Client) MigrateStatus(ctx context.Context, params *MigrateStatusParams) (*MigrateStatus, error)
- func (c *Client) MigrateTest(ctx context.Context, params *MigrateTestParams) (string, error)
- func (c *Client) SchemaApply(ctx context.Context, params *SchemaApplyParams) (*SchemaApply, error)
- func (c *Client) SchemaApplySlice(ctx context.Context, params *SchemaApplyParams) ([]*SchemaApply, error)
- func (c *Client) SchemaInspect(ctx context.Context, params *SchemaInspectParams) (string, error)
- func (c *Client) SchemaTest(ctx context.Context, params *SchemaTestParams) (string, error)
- func (c *Client) Version(ctx context.Context) (*Version, error)
- func (c *Client) WithWorkDir(dir string, fn func(*Client) error) error
- type DeployRunContext
- type Env
- type Error
- type File
- type FileChecks
- type FileReport
- type LoginParams
- type MigrateApply
- type MigrateApplyError
- type MigrateApplyParams
- type MigrateDown
- type MigrateDownParams
- type MigrateExecOrder
- type MigrateLintParams
- type MigratePushParams
- type MigrateStatus
- type MigrateStatusParams
- type MigrateTestParams
- type Option
- type RevertedFile
- type Revision
- type RunContext
- type SchemaApply
- type SchemaApplyError
- type SchemaApplyParams
- type SchemaInspectParams
- type SchemaTestParams
- type StepReport
- type StmtError
- type SummaryReport
- type TriggerType
- type Vars
- type Version
- type WorkingDir
- func (ce *WorkingDir) Close() error
- func (cs *WorkingDir) CopyFS(name string, src fs.FS) error
- func (ce *WorkingDir) CreateFile(name string, fn func(w io.Writer) error) error
- func (ce *WorkingDir) DirFS() fs.FS
- func (ce *WorkingDir) Path(elem ...string) string
- func (ce *WorkingDir) RunCommand(cmd *exec.Cmd) error
- func (ce *WorkingDir) WriteFile(name string, data []byte) (string, error)
Constants ¶
This section is empty.
Variables ¶
var LintErr = errors.New("lint error")
LintErr is returned when the 'migrate lint' finds a diagnostic that is configured to be reported as an error, such as destructive changes by default.
Functions ¶
Types ¶
type AppliedFile ¶
type AppliedFile struct { File Start time.Time End time.Time Skipped int // Amount of skipped SQL statements in a partially applied file. Applied []string // SQL statements applied with success Checks []*FileChecks // Assertion checks Error *struct { Stmt string // SQL statement that failed. Text string // Error returned by the database. } }
AppliedFile is part of a MigrateApply containing information about an applied file in a migration attempt.
type Changes ¶
type Changes struct { Applied []string `json:"Applied,omitempty"` // SQL changes applied with success Pending []string `json:"Pending,omitempty"` // SQL changes that were not applied Error *StmtError `json:"Error,omitempty"` // Error that occurred during applying }
Changes represents a list of changes that are pending or applied.
type Check ¶ added in v0.5.5
type Check struct { Stmt string `json:"Stmt,omitempty"` // Assertion statement. Error *string `json:"Error,omitempty"` // Assertion error, if any. }
Check represents an assertion and its status.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the Atlas CLI.
func (*Client) Login ¶ added in v0.2.0
func (c *Client) Login(ctx context.Context, params *LoginParams) error
Login runs the 'login' command.
func (*Client) MigrateApply ¶ added in v0.2.0
func (c *Client) MigrateApply(ctx context.Context, params *MigrateApplyParams) (*MigrateApply, error)
MigrateApply runs the 'migrate apply' command.
func (*Client) MigrateApplySlice ¶ added in v0.4.0
func (c *Client) MigrateApplySlice(ctx context.Context, params *MigrateApplyParams) ([]*MigrateApply, error)
MigrateApplySlice runs the 'migrate apply' command for multiple targets.
func (*Client) MigrateDown ¶ added in v0.5.3
func (c *Client) MigrateDown(ctx context.Context, params *MigrateDownParams) (*MigrateDown, error)
MigrateDown runs the 'migrate down' command.
func (*Client) MigrateLint ¶ added in v0.2.0
func (c *Client) MigrateLint(ctx context.Context, params *MigrateLintParams) (*SummaryReport, error)
MigrateLint runs the 'migrate lint' command.
func (*Client) MigrateLintError ¶ added in v0.2.0
func (c *Client) MigrateLintError(ctx context.Context, params *MigrateLintParams) error
MigrateLintError runs the 'migrate lint' command, the output is written to params.Writer and reports if an error occurred. If the error is a setup error, a Error is returned. If the error is a lint error, LintErr is returned.
func (*Client) MigratePush ¶ added in v0.2.0
MigratePush runs the 'migrate push' command.
func (*Client) MigrateStatus ¶ added in v0.2.0
func (c *Client) MigrateStatus(ctx context.Context, params *MigrateStatusParams) (*MigrateStatus, error)
MigrateStatus runs the 'migrate status' command.
func (*Client) MigrateTest ¶ added in v0.5.6
MigrateTest runs the 'migrate test' command.
func (*Client) SchemaApply ¶
func (c *Client) SchemaApply(ctx context.Context, params *SchemaApplyParams) (*SchemaApply, error)
SchemaApply runs the 'schema apply' command.
func (*Client) SchemaApplySlice ¶ added in v0.4.0
func (c *Client) SchemaApplySlice(ctx context.Context, params *SchemaApplyParams) ([]*SchemaApply, error)
SchemaApplySlice runs the 'schema apply' command for multiple targets.
func (*Client) SchemaInspect ¶
SchemaInspect runs the 'schema inspect' command.
func (*Client) SchemaTest ¶ added in v0.5.6
SchemaTest runs the 'schema test' command.
func (*Client) WithWorkDir ¶ added in v0.2.2
WithWorkDir creates a new client with the given working directory. It is useful to run multiple commands in the multiple directories.
Example:
client := atlasexec.NewClient("", "atlas") err := client.WithWorkDir("dir1", func(c *atlasexec.Client) error { _, err := c.MigrateApply(ctx, &atlasexec.MigrateApplyParams{ }) return err })
type DeployRunContext ¶ added in v0.2.0
type DeployRunContext struct { TriggerType TriggerType `json:"triggerType,omitempty"` TriggerVersion string `json:"triggerVersion,omitempty"` }
DeployRunContext describes what triggered this command (e.g., GitHub Action, v1.2.3)
type Env ¶
type Env struct { Driver string `json:"Driver,omitempty"` // Driver name. URL *sqlclient.URL `json:"URL,omitempty"` // URL to dev database. Dir string `json:"Dir,omitempty"` // Path to migration directory. }
Env holds the environment information.
type Error ¶ added in v0.5.4
type File ¶
type File struct { Name string `json:"Name,omitempty"` Version string `json:"Version,omitempty"` Description string `json:"Description,omitempty"` }
File wraps migrate.File to implement json.Marshaler.
type FileChecks ¶ added in v0.5.5
type FileChecks struct { Name string `json:"Name,omitempty"` // File/group name. Stmts []*Check `json:"Stmts,omitempty"` // Checks statements executed. Error *StmtError `json:"Error,omitempty"` // Assertion error. Start time.Time `json:"Start,omitempty"` // Start assertion time. End time.Time `json:"End,omitempty"` // End assertion time. }
FileChecks represents a set of checks to run before applying a file.
type FileReport ¶
type FileReport struct { Name string `json:"Name,omitempty"` // Name of the file. Text string `json:"Text,omitempty"` // Contents of the file. Reports []sqlcheck.Report `json:"Reports,omitempty"` // List of reports. Error string `json:"Error,omitempty"` // File specific error. }
FileReport contains a summary of the analysis of a single file.
type LoginParams ¶ added in v0.2.0
type LoginParams struct {
Token string
}
LoginParams are the parameters for the `login` command.
type MigrateApply ¶ added in v0.2.0
type MigrateApply struct { Env Pending []File `json:"Pending,omitempty"` // Pending migration files Applied []*AppliedFile `json:"Applied,omitempty"` // Applied files Current string `json:"Current,omitempty"` // Current migration version Target string `json:"Target,omitempty"` // Target migration version Start time.Time End time.Time // Error is set even then, if it was not caused by a statement in a migration file, // but by Atlas, e.g. when committing or rolling back a transaction. Error string `json:"Error,omitempty"` }
MigrateApply contains a summary of a migration applying attempt on a database.
func (*MigrateApply) Summary ¶ added in v0.5.5
func (a *MigrateApply) Summary(ident string) string
Summary of the migration attempt.
type MigrateApplyError ¶ added in v0.3.0
type MigrateApplyError struct {
Result []*MigrateApply
}
MigrateApplyError is returned when an error occurred during a migration applying attempt.
func (*MigrateApplyError) Error ¶ added in v0.3.0
func (e *MigrateApplyError) Error() string
Error implements the error interface.
type MigrateApplyParams ¶ added in v0.2.0
type MigrateApplyParams struct { Env string ConfigURL string Context *DeployRunContext DirURL string AllowDirty bool URL string RevisionsSchema string BaselineVersion string TxMode string ExecOrder MigrateExecOrder Amount uint64 DryRun bool Vars Vars }
MigrateApplyParams are the parameters for the `migrate apply` command.
type MigrateDown ¶ added in v0.5.3
type MigrateDown struct { Planned []File `json:"Planned,omitempty"` // Planned migration files Reverted []*RevertedFile `json:"Reverted,omitempty"` // Reverted files Current string `json:"Current,omitempty"` // Current migration version Target string `json:"Target,omitempty"` // Target migration version Total int `json:"Total,omitempty"` // Total number of migrations to revert Start time.Time End time.Time // URL and Status are set only when the migration is planned or executed in the cloud. URL string `json:"URL,omitempty"` Status string `json:"Status,omitempty"` // Error is set even then, if it was not caused by a statement in a migration file, // but by Atlas, e.g. when committing or rolling back a transaction. Error string `json:"Error,omitempty"` }
MigrateDown contains a summary of a migration down attempt on a database.
type MigrateDownParams ¶ added in v0.5.3
type MigrateDownParams struct { Env string ConfigURL string DevURL string Context *DeployRunContext DirURL string URL string RevisionsSchema string Amount uint64 ToVersion string ToTag string Vars Vars }
MigrateDownParams are the parameters for the `migrate down` command.
type MigrateExecOrder ¶ added in v0.2.1
type MigrateExecOrder string
MigrateExecOrder define how Atlas computes and executes pending migration files to the database. See: https://atlasgo.io/versioned/apply#execution-order
const ( ExecOrderLinear MigrateExecOrder = "linear" // Default ExecOrderLinearSkip MigrateExecOrder = "linear-skip" ExecOrderNonLinear MigrateExecOrder = "non-linear" )
ExecutionOrder values.
type MigrateLintParams ¶ added in v0.2.0
type MigrateLintParams struct { Env string ConfigURL string DevURL string DirURL string Context *RunContext Web bool Latest uint64 Vars Vars Writer io.Writer Base string Format string }
MigrateLintParams are the parameters for the `migrate lint` command.
type MigratePushParams ¶ added in v0.2.0
type MigratePushParams struct { Name string Tag string DevURL string DirURL string DirFormat string LockTimeout string Context *RunContext ConfigURL string Env string Vars Vars }
MigratePushParams are the parameters for the `migrate push` command.
type MigrateStatus ¶ added in v0.2.0
type MigrateStatus struct { Available []File `json:"Available,omitempty"` // Available migration files Pending []File `json:"Pending,omitempty"` // Pending migration files Applied []*Revision `json:"Applied,omitempty"` // Applied migration files Current string `json:"Current,omitempty"` // Current migration version Next string `json:"Next,omitempty"` // Next migration version Count int `json:"Count,omitempty"` // Count of applied statements of the last revision Total int `json:"Total,omitempty"` // Total statements of the last migration Status string `json:"Status,omitempty"` // Status of migration (OK, PENDING) Error string `json:"Error,omitempty"` // Last Error that occurred SQL string `json:"SQL,omitempty"` // SQL that caused the last Error }
MigrateStatus contains a summary of the migration status of a database.
func (MigrateStatus) Amount ¶ added in v0.2.0
func (r MigrateStatus) Amount(version string) (amount uint64, ok bool)
Amount returns the number of migrations need to apply for the given version.
The second return value is true if the version is found and the database is up-to-date.
If the version is not found, it returns 0 and the second return value is false.
func (MigrateStatus) LatestVersion ¶ added in v0.2.0
func (r MigrateStatus) LatestVersion() string
LatestVersion returns the latest version of the migration directory.
type MigrateStatusParams ¶ added in v0.2.0
type MigrateStatusParams struct { Env string ConfigURL string DirURL string URL string RevisionsSchema string Vars Vars }
MigrateStatusParams are the parameters for the `migrate status` command.
type MigrateTestParams ¶ added in v0.5.6
type MigrateTestParams struct { Env string ConfigURL string DirURL string Context *RunContext DevURL string DirFormat string Run string RevisionsSchema string Vars Vars }
MigrateTestParams are the parameters for the `migrate test` command.
type Option ¶ added in v0.2.0
type Option func(ce *WorkingDir) error
Option is a function that modifies a ContextExecer.
func WithAtlasHCL ¶ added in v0.2.0
WithAtlasHCL accept a function to create the atlas.hcl file.
func WithAtlasHCLPath ¶ added in v0.2.0
WithAtlasHCLPath creates the atlas.hcl file by copying the file at the given path.
func WithAtlasHCLString ¶ added in v0.2.0
WithAtlasHCLString creates the atlas.hcl file with the given string.
func WithMigrations ¶ added in v0.2.0
WithMigrations copies all files from dir to the migrations directory. If dir is nil, no files are copied.
type RevertedFile ¶ added in v0.5.3
type RevertedFile struct { File Start time.Time End time.Time Skipped int // Amount of skipped SQL statements in a partially applied file. Applied []string // SQL statements applied with success Scope string // Scope of the revert. e.g., statement, versions, etc. Error *struct { Stmt string // SQL statement that failed. Text string // Error returned by the database. } }
RevertedFile is part of a MigrateDown containing information about a reverted file in a downgrade attempt.
type Revision ¶
type Revision struct { Version string `json:"Version"` // Version of the migration. Description string `json:"Description"` // Description of this migration. Type string `json:"Type"` // Type of the migration. Applied int `json:"Applied"` // Applied amount of statements in the migration. Total int `json:"Total"` // Total amount of statements in the migration. ExecutedAt time.Time `json:"ExecutedAt"` // ExecutedAt is the starting point of execution. ExecutionTime time.Duration `json:"ExecutionTime"` // ExecutionTime of the migration. Error string `json:"Error,omitempty"` // Error of the migration, if any occurred. ErrorStmt string `json:"ErrorStmt,omitempty"` // ErrorStmt is the statement that raised Error. OperatorVersion string `json:"OperatorVersion"` // OperatorVersion that executed this migration. }
A Revision denotes an applied migration in a deployment. Used to track migration executions state of a database.
type RunContext ¶ added in v0.2.0
type RunContext struct { Repo string `json:"repo,omitempty"` Path string `json:"path,omitempty"` Branch string `json:"branch,omitempty"` Commit string `json:"commit,omitempty"` URL string `json:"url,omitempty"` Username string `json:"username,omitempty"` // The username that triggered the event that initiated the command. UserID string `json:"userID,omitempty"` // The user ID that triggered the event that initiated the command. SCMType string `json:"scmType,omitempty"` // Source control management system type. }
RunContext describes what triggered this command (e.g., GitHub Action).
type SchemaApply ¶
type SchemaApply struct { Env Changes Changes `json:"Changes,omitempty"` // General error that occurred during execution. // e.g., when committing or rolling back a transaction. Error string `json:"Error,omitempty"` }
SchemaApply contains a summary of a 'schema apply' execution on a database.
type SchemaApplyError ¶ added in v0.3.0
type SchemaApplyError struct {
Result []*SchemaApply
}
SchemaApplyError is returned when an error occurred during a schema applying attempt.
func (*SchemaApplyError) Error ¶ added in v0.3.0
func (e *SchemaApplyError) Error() string
Error implements the error interface.
type SchemaApplyParams ¶
type SchemaApplyParams struct { Env string ConfigURL string DevURL string DryRun bool TxMode string Exclude []string Schema []string To string URL string Vars Vars }
SchemaApplyParams are the parameters for the `schema apply` command.
type SchemaInspectParams ¶
type SchemaInspectParams struct { Env string ConfigURL string DevURL string Exclude []string Format string Schema []string URL string Vars Vars }
SchemaInspectParams are the parameters for the `schema inspect` command.
type SchemaTestParams ¶ added in v0.5.6
type SchemaTestParams struct { Env string ConfigURL string URL string DevURL string Run string Vars Vars }
SchemaTestParams are the parameters for the `schema test` command.
type StepReport ¶ added in v0.2.0
type StepReport struct { Name string `json:"Name,omitempty"` // Step name. Text string `json:"Text,omitempty"` // Step description. Error string `json:"Error,omitempty"` // Error that cause the execution to halt. Result *FileReport `json:"Result,omitempty"` // Result of the step. For example, a diagnostic. }
StepReport contains a summary of the analysis of a single step.
type StmtError ¶
type StmtError struct { Stmt string `json:"Stmt,omitempty"` // SQL statement that failed. Text string `json:"Text,omitempty"` // Error message as returned by the database. }
StmtError groups a statement with its execution error.
type SummaryReport ¶
type SummaryReport struct { URL string `json:"URL,omitempty"` // URL of the report, if exists. // Env holds the environment information. Env struct { Driver string `json:"Driver,omitempty"` // Driver name. URL *sqlclient.URL `json:"URL,omitempty"` // URL to dev database. Dir string `json:"Dir,omitempty"` // Path to migration directory. } // Schema versions found by the runner. Schema struct { Current string `json:"Current,omitempty"` // Current schema. Desired string `json:"Desired,omitempty"` // Desired schema. } // Steps of the analysis. Added in verbose mode. Steps []*StepReport `json:"Steps,omitempty"` // Files reports. Non-empty in case there are findings. Files []*FileReport `json:"Files,omitempty"` }
A SummaryReport contains a summary of the analysis of all files. It is used as an input to templates to report the CI results.
func (*SummaryReport) DiagnosticsCount ¶ added in v0.2.0
func (r *SummaryReport) DiagnosticsCount() int
DiagnosticsCount returns the total number of diagnostics in the report.
type TriggerType ¶ added in v0.2.0
type TriggerType string
TriggerType defines the type for the "trigger_type" enum field.
const ( TriggerTypeCLI TriggerType = "CLI" TriggerTypeKubernetes TriggerType = "KUBERNETES" TriggerTypeTerraform TriggerType = "TERRAFORM" TriggerTypeGithubAction TriggerType = "GITHUB_ACTION" TriggerTypeCircleCIOrb TriggerType = "CIRCLECI_ORB" )
TriggerType values.
type Version ¶ added in v0.2.0
type Version struct { Version string `json:"Version"` SHA string `json:"SHA,omitempty"` Canary bool `json:"Canary,omitempty"` }
Version contains the result of an 'atlas version' run.
type WorkingDir ¶ added in v0.2.0
type WorkingDir struct {
// contains filtered or unexported fields
}
WorkingDir is a temporary directory with a copy of the files from dir. It can be used to run commands in the temporary directory. The temporary directory is removed when Close is called.
func NewWorkingDir ¶ added in v0.2.0
func NewWorkingDir(opts ...Option) (*WorkingDir, error)
NewWorkingDir creates a new ContextExecer. It creates a temporary directory and copies all files from dir to the temporary directory. The atlasHCL function is called with a writer to create the atlas.hcl file. If atlasHCL is nil, no atlas.hcl file is created.
func (*WorkingDir) Close ¶ added in v0.2.0
func (ce *WorkingDir) Close() error
Close removes the temporary directory.
func (*WorkingDir) CopyFS ¶ added in v0.2.0
func (cs *WorkingDir) CopyFS(name string, src fs.FS) error
CopyFS copies all files from source FileSystem to the destination directory in the temporary directory. If source is nil, an error is returned.
func (*WorkingDir) CreateFile ¶ added in v0.2.0
CreateFile creates the file in the temporary directory.
func (*WorkingDir) DirFS ¶ added in v0.2.0
func (ce *WorkingDir) DirFS() fs.FS
DirFS returns a fs.FS for the temporary directory.
func (*WorkingDir) Path ¶ added in v0.2.0
func (ce *WorkingDir) Path(elem ...string) string
Dir returns the path to the temporary directory.
func (*WorkingDir) RunCommand ¶ added in v0.2.0
func (ce *WorkingDir) RunCommand(cmd *exec.Cmd) error
RunCommand runs the command in the temporary directory.