MCPcopy
hub / github.com/sqldef/sqldef / Run

Function Run

sqldef.go:64–134  ·  view source on GitHub ↗

Main function shared by all commands

(generatorMode schema.GeneratorMode, db database.Database, sqlParser database.Parser, options *Options)

Source from the content-addressed store, hash-verified

62
63// Main function shared by all commands
64func Run(generatorMode schema.GeneratorMode, db database.Database, sqlParser database.Parser, options *Options) {
65 // Set the generator config on the database for privilege filtering
66 // Note: MySQL will populate MysqlLowerCaseTableNames from the server
67 db.SetGeneratorConfig(options.Config)
68 options.Config = db.GetGeneratorConfig()
69
70 currentDDLs, err := db.ExportDDLs()
71 if err != nil {
72 log.Fatalf("Error on ExportDDLs: %s", err)
73 }
74
75 defaultSchema := db.GetDefaultSchema()
76
77 var ddlSuffix string
78 if generatorMode == schema.GeneratorModeMssql {
79 ddlSuffix = "GO\n"
80 } else {
81 ddlSuffix = ""
82 }
83
84 if options.Export {
85 if currentDDLs == "" {
86 fmt.Printf("-- No table exists --\n")
87 } else {
88 ddls, err := schema.ParseDDLs(generatorMode, sqlParser, currentDDLs, defaultSchema)
89 if err != nil {
90 log.Fatal(err)
91 }
92 ddls = schema.FilterTables(ddls, options.Config)
93 ddls = schema.FilterViews(ddls, options.Config)
94 ddls = schema.FilterPrivileges(ddls, options.Config)
95 for i, ddl := range ddls {
96 if i > 0 {
97 fmt.Println()
98 }
99 fmt.Printf("%s;\n", ddl.Statement())
100 fmt.Print(ddlSuffix)
101 }
102 }
103 return
104 }
105
106 ddls, err := schema.GenerateIdempotentDDLs(generatorMode, sqlParser, options.DesiredDDLs, currentDDLs, options.Config, defaultSchema)
107 if err != nil {
108 fmt.Fprintln(os.Stderr, err)
109 os.Exit(1)
110 }
111 if len(ddls) == 0 {
112 fmt.Println("-- Nothing is modified --")
113 return
114 }
115
116 if options.DryRun || options.Check || len(options.CurrentFile) > 0 {
117 dryRunDB, err := database.NewDryRunDatabase(db)
118 if err != nil {
119 log.Fatal(err)
120 }
121 defer dryRunDB.Close()

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ParseDDLsFunction · 0.92
FilterTablesFunction · 0.92
FilterViewsFunction · 0.92
FilterPrivilegesFunction · 0.92
GenerateIdempotentDDLsFunction · 0.92
NewDryRunDatabaseFunction · 0.92
RunDDLsFunction · 0.92
SetGeneratorConfigMethod · 0.65
GetGeneratorConfigMethod · 0.65
ExportDDLsMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected