Documentation ¶
Index ¶
- Variables
- func TempFile(content, ext string) (string, func() error, error)
- type AppliedFile
- type ApplyParamsdeprecated
- type ApplyReportdeprecated
- type Changes
- type Client
- func (c *Client) Apply(ctx context.Context, params *MigrateApplyParams) (*MigrateApply, error)
- func (c *Client) Lint(ctx context.Context, params *MigrateLintParams) (*SummaryReport, error)
- 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) 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) SchemaApply(ctx context.Context, params *SchemaApplyParams) (*SchemaApply, error)
- func (c *Client) SchemaInspect(ctx context.Context, params *SchemaInspectParams) (string, error)
- func (c *Client) Status(ctx context.Context, params *MigrateStatusParams) (*MigrateStatus, error)
- func (c *Client) Version(ctx context.Context) (*Version, error)
- func (t Client) WithWorkDir(dir string, fn func(*Client) error) error
- type DeployRunContext
- type Env
- type File
- type FileReport
- type LintParamsdeprecated
- type LoginParams
- type MigrateApply
- type MigrateApplyParams
- type MigrateExecOrder
- type MigrateLintParams
- type MigratePushParams
- type MigrateStatus
- type MigrateStatusParams
- type Option
- type Revision
- type RunContext
- type SchemaApply
- type SchemaApplyParams
- type SchemaInspectParams
- type StatusParamsdeprecated
- type StatusReportdeprecated
- 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 Error *struct { SQL string // SQL statement that failed. Error string // Error returned by the database. } }
AppliedFile is part of an ApplyReport containing information about an applied file in a migration attempt.
type ApplyParams
deprecated
type ApplyParams = MigrateApplyParams
Deprecated: MigrateApplyParams instead.
type ApplyReport
deprecated
type ApplyReport = MigrateApply
Deprecated: use MigrateApply instead
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 Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the Atlas CLI.
func (*Client) Apply ¶
func (c *Client) Apply(ctx context.Context, params *MigrateApplyParams) (*MigrateApply, error)
Apply runs the 'migrate apply' command. Deprecated: use MigrateApply instead.
func (*Client) Lint ¶
func (c *Client) Lint(ctx context.Context, params *MigrateLintParams) (*SummaryReport, error)
Lint runs the 'migrate lint' command. Deprecated: use MigrateLint instead.
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. If the underlying command returns an error, but prints to stdout it will be returned as a MigrateApply with the error message in the Error field.
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 cliError 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) SchemaApply ¶
func (c *Client) SchemaApply(ctx context.Context, params *SchemaApplyParams) (*SchemaApply, error)
SchemaApply runs the 'schema apply' command.
func (*Client) SchemaInspect ¶
SchemaInspect runs the 'schema inspect' command.
func (*Client) Status ¶
func (c *Client) Status(ctx context.Context, params *MigrateStatusParams) (*MigrateStatus, error)
Status runs the 'migrate status' command. Deprecated: use MigrateStatus instead.
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 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 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 LintParams
deprecated
type LintParams = MigrateLintParams
Deprecated: use MigrateLintParams instead.
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 { 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.
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 MigrateExecOrder ¶ added in v0.2.1
type MigrateExecOrder string
ExecutionOrder 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 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 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"` }
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 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 StatusParams
deprecated
type StatusParams = MigrateStatusParams
Deprecated: use MigrateStatusParams instead.
type StatusReport
deprecated
type StatusReport = MigrateStatus
Deprecated: use MigrateStatus instead
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" )
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.