Documentation
¶
Overview ¶
Package fmt provides the `spirit fmt` subcommand, which canonicalizes CREATE TABLE .sql files by round-tripping them through a real MySQL server.
MySQL normalizes many SQL constructs internally. For example:
- BOOLEAN becomes TINYINT(1)
- SERIAL becomes BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE
- NVARCHAR becomes VARCHAR with utf8mb3 charset
These normalizations cause spurious diffs when comparing schema files against a live database. `spirit fmt` solves this by applying each .sql file to a local MySQL server, reading back the canonical form via SHOW CREATE TABLE, and updating the file if it differs.
Modelled on `go fmt`: if changes were made, the filename is printed to stdout. If no changes were needed, nothing is printed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FmtCmd ¶
type FmtCmd struct {
// Files is the list of .sql files (or directories) to format.
Files []string `arg:"" help:"SQL files or directories to format." type:"path"`
// MySQL connection options
Host string `name:"host" help:"MySQL server host:port" default:"127.0.0.1:3306" env:"MYSQL_SERVER"`
Username string `name:"username" help:"MySQL username" default:"root" env:"MYSQL_USER"`
Password string `name:"password" help:"MySQL password" default:"" env:"MYSQL_PASSWORD"`
Database string `name:"database" help:"Temporary database to use for formatting" default:"spirit_fmt" env:"MYSQL_DATABASE"`
}
FmtCmd is the Kong CLI struct for the fmt command. It canonicalizes CREATE TABLE .sql files by round-tripping them through MySQL.