Documentation ¶
Overview ¶
Package cmdext provides extensions to the Atlas configuration file such as schema loaders, data sources and cloud connectors.
Index ¶
- Constants
- Variables
- func Query(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)
- func RemoteDir(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)
- func RuntimeVar(c *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)
- func SchemaExternal(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)
- func SchemaHCL(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)
- func TemplateDir(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)
- type AtlasConfig
- type EntLoader
- type MemLoader
- type MigrateDiffOptions
- type MigrateDiffer
- type StateLoader
- type StateLoaderFunc
- type StateReadCloser
- type StateReaderConfig
Constants ¶
const DefaultProjectName = "default"
DefaultProjectName is the default name for projects.
Variables ¶
var DataSources = []schemahcl.Option{ schemahcl.WithDataSource("sql", Query), schemahcl.WithDataSource("runtimevar", RuntimeVar), schemahcl.WithDataSource("template_dir", TemplateDir), schemahcl.WithDataSource("remote_dir", RemoteDir), schemahcl.WithDataSource("hcl_schema", SchemaHCL), schemahcl.WithDataSource("external_schema", SchemaExternal), }
DataSources exposes the data sources provided by this package.
var ( // States is a global registry for external state loaders. States = registry{ "ent": EntLoader{}, "mem": memLoader, } )
Functions ¶
func Query ¶ added in v0.12.1
Query exposes the database/sql.Query as a schemahcl datasource.
data "sql" "tenants" { url = var.url query = <query> args = [<arg1>, <arg2>, ...] } env "prod" { for_each = toset(data.sql.tenants.values) url = urlsetpath(var.url, each.value) }
func RemoteDir ¶ added in v0.10.0
RemoteDir is a data source that reads a remote migration directory.
func RuntimeVar ¶ added in v0.12.1
RuntimeVar exposes the gocloud.dev/runtimevar as a schemahcl datasource.
data "runtimevar" "pass" { url = "driver://path?query=param" } locals { url = "mysql://root:${data.runtimevar.pass}@:3306/" }
func SchemaExternal ¶ added in v0.12.1
SchemaExternal is a data source that reads a SQL schema state from external program.
func SchemaHCL ¶ added in v0.12.1
SchemaHCL is a data source that reads an Atlas HCL schema file(s), evaluates it with the given variables and exposes its resulting schema as in-memory HCL file.
func TemplateDir ¶ added in v0.9.1
TemplateDir implements migrate.Dir interface for template directories.
data "template_dir" "name" { path = "path/to/directory" vars = { Env = atlas.env Seed = var.seed } } env "dev" { url = "driver://path?query=param" migration { dir = data.template_dir.name.url } }
Types ¶
type AtlasConfig ¶ added in v0.10.0
type AtlasConfig struct { Client *cloudapi.Client // Client attached to Atlas Cloud. Project string // Optional project. }
AtlasConfig exposes non-sensitive information returned by the "atlas" init-block. By invoking AtlasInitBlock() a new config is returned that is set by the init block defined and executed on schemahcl Eval functions.
func (*AtlasConfig) InitBlock ¶ added in v0.11.0
func (c *AtlasConfig) InitBlock() schemahcl.Option
InitBlock returns the handler for the "atlas" init block.
atlas { cloud { token = data.runtimevar.token // User token. url = var.cloud_url // Optional URL. project = var.project // Optional project. If set, cloud reporting is enabled. } }
type EntLoader ¶ added in v0.9.1
type EntLoader struct{}
EntLoader is a StateLoader for loading ent.Schema's as StateReader's.
func (EntLoader) LoadState ¶ added in v0.9.1
func (l EntLoader) LoadState(ctx context.Context, config *StateReaderConfig) (*StateReadCloser, error)
LoadState returns a migrate.StateReader that reads the schema from an ent.Schema.
func (EntLoader) MigrateDiff ¶ added in v0.9.1
func (l EntLoader) MigrateDiff(ctx context.Context, opts *MigrateDiffOptions) error
MigrateDiff returns the diff between ent.Schema and a directory.
type MemLoader ¶ added in v0.12.1
type MemLoader struct {
// contains filtered or unexported fields
}
MemLoader is a StateLoader for loading data-sources that were loaded into program memory.
func (MemLoader) LoadState ¶ added in v0.12.1
func (l MemLoader) LoadState(ctx context.Context, config *StateReaderConfig) (*StateReadCloser, error)
LoadState loads the state loaded from data-sources into memory.
type MigrateDiffOptions ¶ added in v0.9.1
type MigrateDiffOptions struct { Name string Indent string To []string Dir migrate.Dir Dev *sqlclient.Client Options []schema.DiffOption }
MigrateDiffOptions for external migration differ.
type MigrateDiffer ¶ added in v0.9.1
type MigrateDiffer interface { MigrateDiff(context.Context, *MigrateDiffOptions) error // contains filtered or unexported methods }
MigrateDiffer allows external sources to implement custom migration differs.
type StateLoader ¶ added in v0.9.1
type StateLoader interface {
LoadState(context.Context, *StateReaderConfig) (*StateReadCloser, error)
}
StateLoader allows loading StateReader's from external sources.
type StateLoaderFunc ¶ added in v0.12.1
type StateLoaderFunc func(context.Context, *StateReaderConfig) (*StateReadCloser, error)
The StateLoaderFunc type is an adapter to allow the use of ordinary function as StateLoader.
func (StateLoaderFunc) LoadState ¶ added in v0.12.1
func (f StateLoaderFunc) LoadState(ctx context.Context, opts *StateReaderConfig) (*StateReadCloser, error)
LoadState calls f(ctx, opts).
type StateReadCloser ¶ added in v0.12.1
type StateReadCloser struct { migrate.StateReader io.Closer // optional close function Schema string // in case we work on a single schema HCL bool // true if state was read from HCL files since in that case we always compare realms }
StateReadCloser is a migrate.StateReader with an optional io.Closer.
func StateReaderHCL ¶ added in v0.12.1
func StateReaderHCL(ctx context.Context, c *StateReaderConfig) (*StateReadCloser, error)
StateReaderHCL returns a StateReader that reads the state from the given HCL paths urls.
func StateReaderSQL ¶ added in v0.12.1
func StateReaderSQL(ctx context.Context, config *StateReaderConfig) (*StateReadCloser, error)
StateReaderSQL returns a migrate.StateReader from an SQL file or a directory of migrations.
func (*StateReadCloser) Close ¶ added in v0.12.1
func (r *StateReadCloser) Close()
Close redirects calls to Close to the enclosed io.Closer.
type StateReaderConfig ¶ added in v0.12.1
type StateReaderConfig struct { URLs []*url.URL // urls to create a migrate.StateReader from Client, Dev *sqlclient.Client // database connections, while dev is considered a dev database, client is not Schemas []string // schemas to work on Exclude []string // exclude flag values Vars map[string]cty.Value }
StateReaderConfig is given to stateReader.