func rewriteSQLFile(file *fs.TokenizedSQLFile) error {
	exists, _ := file.Exists()
	if bytesWritten, err := file.Rewrite(); err != nil {
		return err
	} else if bytesWritten == 0 {
		log.Infof("Deleted %s", file)
	} else if exists {
		log.Infof("Wrote %s (%d bytes)", file, bytesWritten)
	} else {
		log.Infof("Created %s (%d bytes)", file, bytesWritten)
	}
	return nil
}
rewriteSQLFile rewrites a TokenizedSQLFile.
package dumper
import (
	"errors"
	"fmt"
	"strings"
	log "github.com/sirupsen/logrus"
	"github.com/skeema/skeema/internal/fs"
	"github.com/skeema/tengo"
)
func DumpSchema(schema *tengo.Schema, dir *fs.Dir, opts Options) (int, error) {
	if namedSchemaStmts := dir.NamedSchemaStatements(); len(namedSchemaStmts) > 0 {
		if len(namedSchemaStmts) == 1 {
			log.Warnf("This directory contains a statement referencing a specific schema name at %s line %d.", namedSchemaStmts[0].File, namedSchemaStmts[0].LineNo)
		} else {
			log.Warnf("This directory contains %d statements referencing specific schema names, for example %s line %d.", len(namedSchemaStmts), namedSchemaStmts[0].File, namedSchemaStmts[0].LineNo)
		}
		log.Warn("Most Skeema commands do not support USE statements or schema-prefixed table names yet.")
		log.Warn("Please configure schema names only in .skeema files.")
		return 0, errors.New("unsupported format of .sql files")
	}
	filesWithDiffs := modifiedFiles(schema, dir, opts)
	for n, file := range filesWithDiffs {
		if opts.CountOnly {
			log.Infof("File %s requires formatting changes", file)
		} else if err := rewriteSQLFile(file); err != nil {
			return n, err
		}
	}
	return len(filesWithDiffs), nil
}