Documentation
¶
Overview ¶
Package cmdapi holds the atlas commands used to build an atlas distribution.
Index ¶
- Constants
- Variables
- func AbortErrorf(format string, a ...any) error
- func EnvByName(cmd *cobra.Command, name string, vars map[string]cty.Value) (*Project, []*Env, error)
- func RunE(f func(*cobra.Command, []string) error) func(*cobra.Command, []string) error
- func Version() string
- type AbortError
- type Aborter
- type Diff
- type Env
- func (e *Env) DiffOptions() []schema.DiffOption
- func (e *Env) LintReview() string
- func (e *Env) MigrationExclude() []string
- func (e *Env) MigrationRepo() (s string)
- func (e *Env) SchemaRepo() (s string)
- func (e *Env) Sources() ([]string, error)
- func (e *Env) VarFromURL(s string) (string, error)
- func (e *Env) Vars() map[string]cty.Value
- type ErrorFormatter
- type Format
- type FormattedError
- type Lint
- type LocalState
- type MigrateReport
- func (r *MigrateReport) CloudEnabled(ctx context.Context) bool
- func (r *MigrateReport) DirName(flags migrateApplyFlags) string
- func (r *MigrateReport) Done(cmd *cobra.Command, flags migrateApplyFlags) error
- func (r *MigrateReport) Init(c *sqlclient.Client, l *cmdlog.MigrateApply, rrw cmdmigrate.RevisionReadWriter)
- func (r *MigrateReport) RecordPlanError(cmd *cobra.Command, flags migrateApplyFlags, planerr string)
- func (r *MigrateReport) RecordTargetID(ctx context.Context) error
- type MigrateReportSet
- func (s *MigrateReportSet) Flush(cmd *cobra.Command, cmdErr error)
- func (*MigrateReportSet) RedactedURL(u string) string
- func (s *MigrateReportSet) ReportFor(flags migrateApplyFlags, e *Env) *MigrateReport
- func (s *MigrateReportSet) Step(format string, args ...interface{})
- func (s *MigrateReportSet) StepLog(text string)
- func (s *MigrateReportSet) StepLogError(text string)
- func (s *MigrateReportSet) StepLogf(format string, args ...interface{})
- type Migration
- type Project
- type Repo
- type Schema
- type SkipChanges
- type Test
- type Vars
Constants ¶
const ( ReviewAlways = "ALWAYS" // Always review changes. The default mode. ReviewWarning = "WARNING" // Review changes only if there are any diagnostics (including warnings). ReviewError = "ERROR" // Review changes only if there are severe diagnostics (error level). )
Review modes for 'schema apply'.
Variables ¶
var ( // Root represents the root command when called without any subcommands. Root = &cobra.Command{ Use: "atlas", Short: "Manage your database schema as code", SilenceUsage: true, } // GlobalFlags contains flags common to many Atlas sub-commands. GlobalFlags struct { // Config defines the path to the Atlas project/config file. ConfigURL string // SelectedEnv contains the environment selected from the active project via the --env flag. SelectedEnv string // Vars contains the input variables passed from the CLI to Atlas DDL or project files. Vars Vars } )
var ReviewModes = []string{ReviewAlways, ReviewWarning, ReviewError}
Functions ¶
func AbortErrorf ¶
AbortErrorf is like fmt.Errorf for creating AbortError.
func EnvByName ¶
func EnvByName(cmd *cobra.Command, name string, vars map[string]cty.Value) (*Project, []*Env, error)
EnvByName parses and returns the project configuration with selected environments.
Types ¶
type AbortError ¶
type AbortError struct {
Err error
}
AbortError returns a command error that is formatted as "Abort: ..." when the execution is aborted by the user.
func (*AbortError) Error ¶
func (e *AbortError) Error() string
func (*AbortError) FormatError ¶
func (e *AbortError) FormatError(cmd *cobra.Command)
func (*AbortError) Unwrap ¶
func (e *AbortError) Unwrap() error
type Aborter ¶
type Aborter interface {
error
IsAbort()
}
Aborter allows errors to signal if the error is an abort error.
type Diff ¶
type Diff struct {
// SkipChanges configures the skip changes policy.
SkipChanges *SkipChanges `spec:"skip"`
schemahcl.DefaultExtension
}
Diff represents the schema diffing policy.
func (*Diff) Extend ¶
Extend allows extending environment blocks with a global one. For example:
diff {
skip {
drop_schema = true
}
}
env "local" {
...
diff {
concurrent_index {
create = true
drop = true
}
}
}
func (*Diff) Options ¶
func (d *Diff) Options() (opts []schema.DiffOption)
Options converts the diff policy into options.
type Env ¶
type Env struct {
// Name for this environment.
Name string `spec:"name,name"`
// URL of the database.
URL string `spec:"url"`
// URL of the dev-database for this environment.
// See: https://atlasgo.io/dev-database
DevURL string `spec:"dev"`
// List of schemas in this database that are managed by Atlas.
Schemas []string `spec:"schemas"`
// Exclude defines a list of glob patterns used to filter
// resources on inspection.
Exclude []string `spec:"exclude"`
// Include defines a list of glob patterns used to keep
// resources on inspection.
Include []string `spec:"include"`
// Schema containing the schema configuration of the env.
Schema *Schema `spec:"schema"`
// Migration containing the migration configuration of the env.
Migration *Migration `spec:"migration"`
// Diff policy of the environment.
Diff *Diff `spec:"diff"`
// Lint policy of the environment.
Lint *Lint `spec:"lint"`
// Format of the environment.
Format Format `spec:"format"`
// Test configuration of the environment.
Test *Test `spec:"test"`
schemahcl.DefaultExtension
// contains filtered or unexported fields
}
Env represents an Atlas environment.
func (*Env) DiffOptions ¶
func (e *Env) DiffOptions() []schema.DiffOption
DiffOptions returns the diff options configured for the environment, or nil if no environment or diff policy were set.
func (*Env) LintReview ¶
LintReview returns the review mode for the lint command.
func (*Env) MigrationExclude ¶
MigrationExclude returns the exclusion patterns of the migration directory.
func (*Env) MigrationRepo ¶
MigrationRepo returns the migration repository name, if set.
func (*Env) SchemaRepo ¶
SchemaRepo returns the desired schema repository name, if set.
func (*Env) Sources ¶
Sources returns the paths containing the Atlas desired schema. The "src" attribute predates the "schema" block. If the "schema" is defined, it takes precedence over the "src" attribute.
func (*Env) VarFromURL ¶
VarFromURL returns the string variable (env attribute) from the URL.
type ErrorFormatter ¶
ErrorFormatter implemented by the errors below to allow them format command output on error.
type Format ¶
type Format struct {
Migrate struct {
// Apply configures the formatting for 'migrate apply'.
Apply string `spec:"apply"`
// Down configures the formatting for 'migrate down'.
Down string `spec:"down"`
// Lint configures the formatting for 'migrate lint'.
Lint string `spec:"lint"`
// Status configures the formatting for 'migrate status'.
Status string `spec:"status"`
// Apply configures the formatting for 'migrate diff'.
Diff string `spec:"diff"`
} `spec:"migrate"`
Schema struct {
// Clean configures the formatting for 'schema clean'.
Clean string `spec:"clean"`
// Inspect configures the formatting for 'schema inspect'.
Inspect string `spec:"inspect"`
// Apply configures the formatting for 'schema apply'.
Apply string `spec:"apply"`
// Apply configures the formatting for 'schema diff'.
Diff string `spec:"diff"`
// Push configures the formatting for 'schema push'.
Push string `spec:"push"`
} `spec:"schema"`
schemahcl.DefaultExtension
}
Format represents the output formatting configuration of an environment.
type FormattedError ¶
type FormattedError struct {
Err error
Prefix string // Prefix to use on error.
Silent bool // Silent errors are not printed.
}
FormattedError is an error that format the command output when returned.
func (*FormattedError) Error ¶
func (e *FormattedError) Error() string
func (*FormattedError) FormatError ¶
func (e *FormattedError) FormatError(cmd *cobra.Command)
type Lint ¶
type Lint struct {
// Format configures the --format option.
Format string `spec:"log"`
// Latest configures the --latest option.
Latest int `spec:"latest"`
Git struct {
// Dir configures the --git-dir option.
Dir string `spec:"dir"`
// Base configures the --git-base option.
Base string `spec:"base"`
} `spec:"git"`
// Review defines when Atlas will ask the user to review and approve the changes.
Review string `spec:"review"`
schemahcl.DefaultExtension
}
Lint represents the configuration of migration linting.
type LocalState ¶
LocalState keeps track of local state to enhance developer experience.
type MigrateReport ¶
type MigrateReport struct {
// contains filtered or unexported fields
}
MigrateReport responsible for reporting 'migrate apply' reports.
func (*MigrateReport) CloudEnabled ¶
func (r *MigrateReport) CloudEnabled(ctx context.Context) bool
CloudEnabled reports if cloud reporting is enabled.
func (*MigrateReport) DirName ¶
func (r *MigrateReport) DirName(flags migrateApplyFlags) string
DirName returns the directory name for the report.
func (*MigrateReport) Done ¶
func (r *MigrateReport) Done(cmd *cobra.Command, flags migrateApplyFlags) error
Done closes and flushes this report.
func (*MigrateReport) Init ¶
func (r *MigrateReport) Init(c *sqlclient.Client, l *cmdlog.MigrateApply, rrw cmdmigrate.RevisionReadWriter)
Init the report if the necessary dependencies.
func (*MigrateReport) RecordPlanError ¶
func (r *MigrateReport) RecordPlanError(cmd *cobra.Command, flags migrateApplyFlags, planerr string)
RecordPlanError records any errors that occurred during the planning phase. i.e., when calling to ex.Pending.
func (*MigrateReport) RecordTargetID ¶
func (r *MigrateReport) RecordTargetID(ctx context.Context) error
RecordTargetID asks the revisions-table to allow or provide the target identifier if cloud reporting is enabled.
type MigrateReportSet ¶
type MigrateReportSet struct {
cloudapi.ReportMigrationSetInput
// contains filtered or unexported fields
}
MigrateReportSet is a set of reports.
func NewReportProvider ¶
func NewReportProvider(ctx context.Context, p *Project, envs []*Env, flags *migrateApplyFlags) (*MigrateReportSet, error)
NewReportProvider returns a new ReporterProvider.
func (*MigrateReportSet) Flush ¶
func (s *MigrateReportSet) Flush(cmd *cobra.Command, cmdErr error)
Flush report the migration deployment to the cloud. The current implementation is simplistic and sends each report separately without marking them as part of a group.
Note that reporting errors are logged, but not cause Atlas to fail.
func (*MigrateReportSet) RedactedURL ¶
func (*MigrateReportSet) RedactedURL(u string) string
RedactedURL returns the redacted URL of the given environment at index i.
func (*MigrateReportSet) ReportFor ¶
func (s *MigrateReportSet) ReportFor(flags migrateApplyFlags, e *Env) *MigrateReport
ReportFor returns a new MigrateReport for the given environment.
func (*MigrateReportSet) Step ¶
func (s *MigrateReportSet) Step(format string, args ...interface{})
Step starts a new reporting step.
func (*MigrateReportSet) StepLog ¶
func (s *MigrateReportSet) StepLog(text string)
StepLog logs a line to the current reporting step.
func (*MigrateReportSet) StepLogError ¶
func (s *MigrateReportSet) StepLogError(text string)
StepLogError logs a line to the current reporting step.
func (*MigrateReportSet) StepLogf ¶
func (s *MigrateReportSet) StepLogf(format string, args ...interface{})
StepLogf logs a line to the current reporting step with formatting.
type Migration ¶
type Migration struct {
Dir string `spec:"dir"`
Exclude []string `spec:"exclude"`
Format string `spec:"format"`
Baseline string `spec:"baseline"`
ExecOrder string `spec:"exec_order"`
LockTimeout string `spec:"lock_timeout"`
RevisionsSchema string `spec:"revisions_schema"`
Repo *Repo `spec:"repo"`
}
Migration represents the migration directory for the Env.
type Project ¶
type Project struct {
Envs []*Env `spec:"env"` // List of environments
Lint *Lint `spec:"lint"` // Optional global lint policy
Diff *Diff `spec:"diff"` // Optional global diff policy
Test *Test `spec:"test"` // Optional test configuration
// contains filtered or unexported fields
}
Project represents an atlas.hcl project config file.
type Repo ¶
type Repo struct {
Name string `spec:"name"` // Name of the repository.
}
Repo represents a repository in the schema registry for a schema or migrations directory.
type Schema ¶
type Schema struct {
// The extension holds the "src" attribute.
// It can be a string, or a list of strings.
schemahcl.DefaultExtension
Repo *Repo `spec:"repo"`
}
Schema represents a schema in the registry.
type SkipChanges ¶
type SkipChanges struct {
AddSchema bool `spec:"add_schema"`
DropSchema bool `spec:"drop_schema"`
ModifySchema bool `spec:"modify_schema"`
AddTable bool `spec:"add_table"`
DropTable bool `spec:"drop_table"`
ModifyTable bool `spec:"modify_table"`
RenameTable bool `spec:"rename_table"`
AddColumn bool `spec:"add_column"`
DropColumn bool `spec:"drop_column"`
ModifyColumn bool `spec:"modify_column"`
AddIndex bool `spec:"add_index"`
DropIndex bool `spec:"drop_index"`
ModifyIndex bool `spec:"modify_index"`
AddForeignKey bool `spec:"add_foreign_key"`
DropForeignKey bool `spec:"drop_foreign_key"`
ModifyForeignKey bool `spec:"modify_foreign_key"`
RenameConstraint bool `spec:"rename_constraint"`
schemahcl.DefaultExtension
}
SkipChanges represents the skip changes policy.
type Test ¶
type Test struct {
// Schema represents the 'schema test' configuration.
Schema struct {
Src []string `spec:"src"`
Vars Vars `spec:"vars"`
} `spec:"schema"`
// Migrate represents the 'migrate test' configuration.
Migrate struct {
Src []string `spec:"src"`
Vars Vars `spec:"vars"`
} `spec:"migrate"`
}
Test represents the test configuration of a project or environment.