action

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ApplyFlags are the flags used in Apply command.
	ApplyFlags struct {
		DSN    string
		File   string
		Web    bool
		Addr   string
		DryRun bool
		Schema []string
	}
	// ApplyCmd represents the apply command.
	ApplyCmd = &cobra.Command{
		Use:   "apply",
		Short: "Apply an atlas schema to a target database.",
		Long: "`atlas schema apply`" + ` plans and executes a database migration to be bring a given database
to the state described in the Atlas schema file. Before running the migration, Atlas will print the migration
plan and prompt the user for approval.

If run with the "--dry-run" flag, atlas will exit after printing out the planned migration.`,
		Run: CmdApplyRun,
		Example: `atlas schema apply -d "mysql://user:pass@tcp(localhost:3306)/dbname" -f atlas.hcl
atlas schema apply -d "mysql://user:pass@tcp(localhost:3306)/" -f atlas.hcl --schema prod --schema staging
atlas schema apply -d "mysql://user:pass@tcp(localhost:3306)/dbname" -f atlas.hcl --dry-run 
atlas schema apply -d "mariadb://user:pass@tcp(localhost:3306)/dbname" -f atlas.hcl
atlas schema apply --dsn "postgres://user:pass@host:port/dbname" -f atlas.hcl
atlas schema apply -d "sqlite://file:ex1.db?_fk=1" -f atlas.hcl`,
	}
)
View Source
var (
	// DiffFlags are the flags used in the Diff command.
	DiffFlags struct {
		FromDSN string
		ToDSN   string
	}
	// DiffCmd represents the diff command.
	DiffCmd = &cobra.Command{
		Use:   "diff",
		Short: "Calculate and print the diff between two schemas.",
		Long: "`atlas schema diff`" + ` connects to two given databases, inspects
them, calculates the difference in their schemas, and prints a plan of
SQL queries to bring the "from" database to the schema of the "to" database.`,
		Run: CmdDiffRun,
	}
)
View Source
var (
	// InspectFlags are the flags used in Inspect command.
	InspectFlags struct {
		DSN    string
		Web    bool
		Addr   string
		Schema []string
	}
	// InspectCmd represents the inspect command.
	InspectCmd = &cobra.Command{
		Use:   "inspect",
		Short: "Inspect an a database's and print its schema in Atlas DDL syntax.",
		Long: "`atlas schema inspect`" + ` connects to the given database and inspects its schema.
It then prints to the screen the schema of that database in Atlas DDL syntax. This output can be 
saved to a file, commonly by redirecting the output to a file named with a ".hcl" suffix:

	atlas schema inspect -d "mysql://user:pass@tcp(localhost:3306)/dbname" > atlas.hcl

This file can then be edited and used with the` + " `atlas schema apply` " + `command to plan
and execute schema migrations against the given database. In cases where users wish to inspect
all multiple schemas in a given database (for instance a MySQL server may contain multiple named
databases), omit the relevant part from the dsn, e.g. "mysql://user:pass@tcp(localhost:3306)/".
To select specific schemas from the databases, users may use the "--schema" (or "-s" shorthand)
flag.
	`,
		Run: CmdInspectRun,
		Example: `
atlas schema inspect -d "mysql://user:pass@tcp(localhost:3306)/dbname"
atlas schema inspect -d "mariadb://user:pass@tcp(localhost:3306)/" --schema=schemaA,schemaB -s schemaC
atlas schema inspect --dsn "postgres://user:pass@host:port/dbname"
atlas schema inspect -d "sqlite://file:ex1.db?_fk=1"`,
	}
)
View Source
var (
	// FmtCmd represents the fmt command.
	FmtCmd = &cobra.Command{
		Use:   "fmt [path ...]",
		Short: "Formats Atlas HCL files",
		Long: "`atlas schema fmt`" + ` formats all ".hcl" files under the given path using
cannonical HCL layout style as defined by the github.com/hashicorp/hcl/v2/hclwrite package. 
Unless stated otherwise, the fmt command will use the current directory.

After running, the command will print the names of the files it has formatted. If all
files in the directory are formatted, no input will be printed out.
`,
		Run: CmdFmtRun,
	}
)
View Source
var RootCmd = &cobra.Command{
	Use:   "atlas",
	Short: "A database toolkit.",
}

RootCmd represents the base command when called without any subcommands

Functions

func CheckForUpdate

func CheckForUpdate()

CheckForUpdate exposes internal update logic to CLI

func CmdApplyRun

func CmdApplyRun(cmd *cobra.Command, args []string)

CmdApplyRun is the command used when running CLI.

func CmdDiffRun added in v0.3.2

func CmdDiffRun(cmd *cobra.Command, args []string)

CmdDiffRun connects to the given databases, and prints an SQL plan to get from the "from" schema to the "to" schema.

func CmdFmtRun added in v0.3.2

func CmdFmtRun(cmd *cobra.Command, args []string)

CmdFmtRun formats all HCL files in a given directory using canonical HCL formatting rules.

func CmdInspectRun

func CmdInspectRun(_ *cobra.Command, _ []string)

CmdInspectRun is the command used when running CLI.

func SchemaNameFromDSN

func SchemaNameFromDSN(url string) (string, error)

SchemaNameFromDSN parses the dsn the returns schema name

Types

type Driver

Driver implements the Atlas interface.

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux is used for routing dsn to correct provider.

func NewMux

func NewMux() *Mux

NewMux returns a new Mux.

func (*Mux) OpenAtlas

func (u *Mux) OpenAtlas(dsn string) (*Driver, error)

OpenAtlas is used for opening an atlas driver on a specific data source.

func (*Mux) RegisterProvider

func (u *Mux) RegisterProvider(key string, p func(string) (*Driver, error))

RegisterProvider is used to register a Driver provider by key.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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