MCPcopy Create free account
hub / github.com/cloudwan/gohan / getConvertCommand

Function getConvertCommand

cli/cli.go:258–315  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

256}
257
258func getConvertCommand() cli.Command {
259 return cli.Command{
260 Name: "convert",
261 ShortName: "conv",
262 Usage: "Convert DB",
263 Description: `
264Gohan convert can be used to migrate Gohan resources between different types of databases.
265
266Setting meta-schema option will additionally convert meta-schema table with schema resources.
267Useful for development purposes.`,
268 Flags: []cli.Flag{
269 cli.StringFlag{Name: "in-type, it", Value: "", Usage: "Input db type (yaml, json, sqlite3, mysql)"},
270 cli.StringFlag{Name: "in, i", Value: "", Usage: "Input db connection spec (or filename)"},
271 cli.StringFlag{Name: "out-type, ot", Value: "", Usage: "Output db type (yaml, json, sqlite3, mysql)"},
272 cli.StringFlag{Name: "out, o", Value: "", Usage: "Output db connection spec (or filename)"},
273 cli.StringFlag{Name: "schema, s", Value: "", Usage: "Schema file"},
274 cli.StringFlag{Name: "meta-schema, m", Value: "embed://etc/schema/gohan.json", Usage: "Meta-schema file (optional)"},
275 },
276 Action: func(c *cli.Context) {
277 inType, in := c.String("in-type"), c.String("in")
278 if inType == "" || in == "" {
279 util.ExitFatal("Need to provide input database specification")
280 }
281 outType, out := c.String("out-type"), c.String("out")
282 if outType == "" || out == "" {
283 util.ExitFatal("Need to provide output database specification")
284 }
285
286 schemaFile := c.String("schema")
287 if schemaFile == "" {
288 util.ExitFatal("Need to provide schema file")
289 }
290 metaSchemaFile := c.String("meta-schema")
291
292 schemaManager := schema.GetManager()
293 err := schemaManager.LoadSchemasFromFiles(schemaFile, metaSchemaFile)
294 if err != nil {
295 util.ExitFatal("Error loading schema:", err)
296 }
297
298 inDB, err := db.ConnectDB(inType, in, db.DefaultMaxOpenConn, db_options.Default())
299 if err != nil {
300 util.ExitFatal(err)
301 }
302 outDB, err := db.ConnectDB(outType, out, db.DefaultMaxOpenConn, db_options.Default())
303 if err != nil {
304 util.ExitFatal(err)
305 }
306
307 err = db.CopyDBResources(inDB, outDB, true)
308 if err != nil {
309 util.ExitFatal(err)
310 }
311
312 fmt.Println("Conversion complete")
313 },
314 }
315}

Callers 1

RunFunction · 0.85

Calls 3

LoadSchemasFromFilesMethod · 0.80
DefaultMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected