<commit_before>package cmd

import (
	"fmt"

	"github.com/freneticmonkey/migrate/go/config"
	"github.com/freneticmonkey/migrate/go/git"
	"github.com/freneticmonkey/migrate/go/id"
	"github.com/freneticmonkey/migrate/go/mysql"
	"github.com/freneticmonkey/migrate/go/table"
	"github.com/freneticmonkey/migrate/go/util"
	"github.com/freneticmonkey/migrate/go/yaml"
	"github.com/urfave/cli"
)

// GetDiffCommand Configure the validate command
func GetDiffCommand() (setup cli.Command) {
	setup = cli.Command{
		Name:  "diff",
		Usage: "Diff the MySQL target database and the YAML schema.",
		Flags: []cli.Flag{
			cli.StringFlag{
				Name:  "project",
				Value: "",
				Usage: "The target project",
			},
			cli.StringFlag{
				Name:  "version",
				Value: "",
				Usage: "The target git version",
			},
		},
		Action: func(ctx *cli.Context) error {

			var version string
			var project string

			// Parse global flags
			parseGlobalFlags(ctx)

			// Setup the management database and configuration settings
			conf, err := configureManagement()

			if err != nil {
				return cli.NewExitError("Configuration Load failed.", 1)
			}

			// Override the project settings with the command line flags
			if ctx.IsSet("version") {
				version = ctx.String("version")
			}

			if ctx.IsSet("project") {
				project = ctx.String("project")
			}

			return diff(version, project, conf)
		},
	}
	return setup
}

func diff(project, version string, conf config.Config) *cli.ExitError {
	var forwardDiff table.Differences
	var problems int
	var err error

	// Override the project settings with the command line flags
	if version != "" {
		conf.Project.Schema.Version = version
	}

	if project != "" {
		conf.Project.Name = project
		git.Clone(conf.Project)
	} else {
		util.LogInfo("No project specified.  Comparing the current state of the YAML schema in working path.")
	}

	// Read the YAML files cloned from the repo
	err = yaml.ReadTables(conf.Options.WorkingPath)
	if util.ErrorCheck(err) {
		return cli.NewExitError("Diff failed. Unable to read YAML Tables", 1)
	}
	problems, err = id.ValidateSchema(yaml.Schema, "YAML Schema")
	if util.ErrorCheck(err) {
		return cli.NewExitError("Validation failed. YAML Errors found", problems)
	}

	// Read the MySQL tables from the target database
	err = mysql.ReadTables()
	if util.ErrorCheck(err) {
		return cli.NewExitError("Diff failed. Unable to read MySQL Tables", 1)
	}
	problems, err = id.ValidateSchema(mysql.Schema, "Target Database Schema")
	if util.ErrorCheck(err) {
		return cli.NewExitError("Validation failed. Problems with Target Database Detected", problems)
	}

	forwardDiff, err = table.DiffTables(yaml.Schema, mysql.Schema, true)
	if util.ErrorCheck(err) {
		return cli.NewExitError("Validation failed. Problems determining differences", 1)
	}
	mysql.GenerateAlters(forwardDiff)<commit_msg>Diff will now display differences without verbose output enabled.<commit_after>package cmd

import (
	"fmt"

	"github.com/freneticmonkey/migrate/go/config"
	"github.com/freneticmonkey/migrate/go/git"
	"github.com/freneticmonkey/migrate/go/id"
	"github.com/freneticmonkey/migrate/go/mysql"
	"github.com/freneticmonkey/migrate/go/table"
	"github.com/freneticmonkey/migrate/go/util"
	"github.com/freneticmonkey/migrate/go/yaml"
	"github.com/urfave/cli"
)

// GetDiffCommand Configure the validate command
func GetDiffCommand() (setup cli.Command) {
	setup = cli.Command{
		Name:  "diff",
		Usage: "Diff the MySQL target database and the YAML schema.",
		Flags: []cli.Flag{
			cli.StringFlag{
				Name:  "project",
				Value: "",
				Usage: "The target project",
			},
			cli.StringFlag{
				Name:  "version",
				Value: "",
				Usage: "The target git version",
			},
		},
		Action: func(ctx *cli.Context) error {

			var version string
			var project string

			// Parse global flags
			parseGlobalFlags(ctx)

			// Setup the management database and configuration settings
			conf, err := configureManagement()

			if err != nil {
				return cli.NewExitError("Configuration Load failed.", 1)
			}

			// Override the project settings with the command line flags
			if ctx.IsSet("version") {
				version = ctx.String("version")
			}

			if ctx.IsSet("project") {
				project = ctx.String("project")
			}

			return diff(version, project, conf)
		},
	}
	return setup
}

func diff(project, version string, conf config.Config) *cli.ExitError {
	var forwardDiff table.Differences
	var problems int
	var err error

	// Override the project settings with the command line flags
	if version != "" {
		conf.Project.Schema.Version = version
	}

	if project != "" {
		conf.Project.Name = project
		git.Clone(conf.Project)
	} else {
		util.LogInfo("No project specified.  Comparing the current state of the YAML schema in working path.")
	}

	// Read the YAML files cloned from the repo
	err = yaml.ReadTables(conf.Options.WorkingPath)
	if util.ErrorCheck(err) {
		return cli.NewExitError("Diff failed. Unable to read YAML Tables", 1)
	}
	problems, err = id.ValidateSchema(yaml.Schema, "YAML Schema")
	if util.ErrorCheck(err) {
		return cli.NewExitError("Validation failed. YAML Errors found", problems)
	}

	// Read the MySQL tables from the target database
	err = mysql.ReadTables()
	if util.ErrorCheck(err) {
		return cli.NewExitError("Diff failed. Unable to read MySQL Tables", 1)
	}
	problems, err = id.ValidateSchema(mysql.Schema, "Target Database Schema")
	if util.ErrorCheck(err) {
		return cli.NewExitError("Validation failed. Problems with Target Database Detected", problems)
	}

	forwardDiff, err = table.DiffTables(yaml.Schema, mysql.Schema, true)
	if util.ErrorCheck(err) {
		return cli.NewExitError("Validation failed. Problems determining differences", 1)
	}
	util.VerboseOverrideSet(true)
	mysql.GenerateAlters(forwardDiff)
	util.VerboseOverrideRestore()
{'fraction_non_alphanumeric': 0.11538461538461539, 'fraction_numerical': 0.0013797861331493618, 'mean_word_length': 3.873109243697479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4375234', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1866, 'n_words': 501}