Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Commit = cli.Command{ Name: "commit", ShortName: "ci", Usage: "<database> <snapfile> <message>", Description: `Commit a new schema revision to a managed database. A schema revision is defined within a snap file which follows the format described below. This file is then applied to the database. ARGUMENTS: database The managed database to apply the snap file to. snapfile The file holding the changes to be applied. message The message to store against the commit. SNAPFILE: A snap file is a simple text file holding SQL statements to be applied to the database. Two SQL comments are required in the file to act as delimiters. The first, marked '-- SNAP_UP', is used to mark the start of SQL making any required changes to the database schema. The second, marked '-- SNAP_DOWN', is used to mark the start of SQL reversing the changes made in the first section. Both comments must be on their own line. Here is a sample file: -- SNAP_UP CREATE TABLE IF NOT EXISTS foo ( bar TINYINT UNSIGNED NOT NULL, baz VARCHAR(32) NOT NULL, PRIMARY KEY (bar) ) ENGINE = InnoDB; -- SNAP_DOWN DROP TABLE IF EXISTS foo; Once a commit is successful the snap file can be discarded as it is saved to the snap configuration database. EXAMPLE: snap my_database changes.txt "Added table foo." `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 2 { database := args.Get(0) fileName := args.Get(1) message := args.Get(2) action.CommitFile(database, fileName, message) return } log.Println("Not enough arguments supplied.") log.Fatalf("Run '%s help commit' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var Copy = cli.Command{ Name: "copy", ShortName: "cp", Usage: "<source-database> <destination-database> [revision]", Description: `Copy a database schema to a new database. ARGUMENTS: source-database The name of the managed database which holds the source schema. destination-database The new database which will be created with the schema of the source database. This new database will not be initially managed by snap. revision (optional) The schema revision of the source database to use for creating the new database. This will default to the latest schema revision if not specified. EXAMPLE: snap copy my_database my_new_database 12 `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 1 { source := args.Get(0) destination := args.Get(1) revision, _ := strconv.ParseUint(args.Get(2), 10, 64) action.CopyDatabase(source, destination, revision) return } log.Println("Both source and destination databases must be specified.") log.Fatalf("Run '%s help copy' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var Diff = cli.Command{ Name: "diff", Usage: "<database> <from-revision>[..<to-revision>]", Description: `Show an SQL diff between two schema revisions. The diff will be in unified format and be written to stdout. ARGUMENTS: database The name of the managed database to generate the schema diff for. from-revision A schema revision to generate the diff from. This is usually the start point in history where you would like the diff to be calculated from. to-revision (optional) The schema revision to generate the diff to. This marks the finish point in history where you would like the diff to be calculated to. This will default to the latest schema revision if not specified. EXAMPLE: snap diff my_database 10..12 `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 1 { database := args.Get(0) revisionString := args.Get(1) action.Diff(database, revisionString) return } log.Println("Both database and a revision must be specified.") log.Fatalf("Run '%s help diff' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var Dump = cli.Command{ Name: "dump", Usage: "<database> [revision]", Description: `Dump a managed database schema to stdout. ARGUMENTS: database The name of the managed database to dump the schema from. revision (optional) The schema revision from which to dump the schema. This will default to the latest schema revision if not specified. EXAMPLE: snap dump my_database 10 `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 0 { database := args.Get(0) revision, _ := strconv.ParseUint(args.Get(1), 10, 64) action.ShowFullSql(database, revision) return } log.Println("No database name specified.") log.Fatalf("Run '%s help dump' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var Help = cli.Command{ Name: "help", Usage: "[command]", Description: `Shows a list of commands or extended help for one command. ARGUMENTS: command (optional) The command to view extended help for. EXAMPLE: snap help commit `, Action: func(ctx *cli.Context) { args := ctx.Args() if args.Present() { cli.ShowCommandHelp(ctx, args.First()) } else { cli.ShowAppHelp(ctx) } }, }
Command.
View Source
var Init = cli.Command{ Name: "init", Usage: "<database>", Description: `Initialise a database to be managed. ARGUMENTS: database The name of the database to be managed by snap. EXAMPLE: snap init my_database `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 0 { name := args.First() action.InitialiseDatabase(name) return } log.Println("No database name specified.") log.Fatalf("Run '%s help init' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var List = cli.Command{ Name: "list", ShortName: "ls", Usage: "", Description: `List the name of all databases snap is currently managing. EXAMPLE: snap list `, Action: func(ctx *cli.Context) { action.ListManagedDatabases() }, }
Command.
View Source
var Log = cli.Command{ Name: "log", Usage: "<database>", Description: `Display a log of all schema update commits. ARGUMENTS: database The name of the managed database to list commits for. EXAMPLE: snap log my_database `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 0 { action.ShowLog(args.First()) return } log.Println("No database name specified.") log.Fatalf("Run '%s help log' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var Show = cli.Command{ Name: "show", Usage: "<database> [revision]", Description: `Show the update SQL for a particular revision. This is the SQL that appeared in the original snap file within the UP section. ARGUMENTS: database The name of the managed database. revision (optional) The schema revision to show the update SQL of. This will default to the latest schema revision if not specified. EXAMPLE: snap show my_database 10 `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 0 { database := args.Get(0) revision, _ := strconv.ParseUint(args.Get(1), 10, 64) action.ShowUpdateSql(database, revision) return } log.Println("No database name specified.") log.Fatalf("Run '%s help show' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var Update = cli.Command{ Name: "update", ShortName: "up", Usage: "<database> [revision]", Description: `Update the database to a particular revision. ARGUMENTS: database The name of the managed database to be updated to a particular schema revision. revision (optional) The schema revision to update the specified database to. This will default to the latest schema revision if not specified. EXAMPLE: snap update my_database 10 `, Action: func(ctx *cli.Context) { args := ctx.Args() if len(args) > 0 { database := args.Get(0) revision, _ := strconv.ParseUint(args.Get(1), 10, 64) action.UpdateSchemaToRevision(database, revision) return } log.Println("No database name specified.") log.Fatalf("Run '%s help update' for more information.\n", ctx.App.Name) }, }
Command.
View Source
var Version = cli.Command{ Name: "version", Usage: "", Description: `Displays version information about the executable. EXAMPLE: snap version `, Action: func(ctx *cli.Context) { fmt.Println(ctx.App.Name, ctx.App.Version) }, }
Command.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.