cmdext

package
v0.0.0-...-73246df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package cmdext provides extensions to the Atlas CLI that may be moved to a separate repository in the future.

Index

Constants

View Source
const DefaultProjectName = "default"

DefaultProjectName is the default name for projects.

Variables

DataSources exposes the data sources provided by this package.

View Source
var States = registry{
	"ent": EntLoader{},
}

States is a global registry for external state loaders.

Functions

func QuerySrc

func QuerySrc(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)

QuerySrc 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

func RemoteDir(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)

RemoteDir is a data source that reads a remote migration directory.

func RuntimeVarSrc

func RuntimeVarSrc(c *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)

RuntimeVarSrc 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 TemplateDir

func TemplateDir(ctx *hcl.EvalContext, block *hclsyntax.Block) (cty.Value, error)

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

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

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

type EntLoader struct{}

EntLoader is a StateLoader for loading ent.Schema's as StateReader's.

func (EntLoader) LoadState

func (l EntLoader) LoadState(ctx context.Context, opts *LoadStateOptions) (migrate.StateReader, error)

LoadState returns a migrate.StateReader that reads the schema from an ent.Schema.

func (EntLoader) MigrateDiff

func (l EntLoader) MigrateDiff(ctx context.Context, opts *MigrateDiffOptions) error

MigrateDiff returns the diff between ent.Schema and a directory.

type LoadStateOptions

type LoadStateOptions struct {
	URLs []*url.URL
	Dev  *sqlclient.Client // Client for the dev database.
}

LoadStateOptions for external state loaders.

type MigrateDiffOptions

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

type MigrateDiffer interface {
	MigrateDiff(context.Context, *MigrateDiffOptions) error
	// contains filtered or unexported methods
}

MigrateDiffer allows external sources to implement custom migration differs.

type StateLoader

type StateLoader interface {
	LoadState(context.Context, *LoadStateOptions) (migrate.StateReader, error)
}

StateLoader allows loading StateReader's from external sources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL