()
| 209 | } |
| 210 | |
| 211 | func getInitDbCommand() cli.Command { |
| 212 | return cli.Command{ |
| 213 | Name: "init-db", |
| 214 | ShortName: "idb", |
| 215 | Usage: "Initialize DB backend with given schema file", |
| 216 | Description: ` |
| 217 | Initialize empty database with given schema. |
| 218 | |
| 219 | Setting meta-schema option will additionally populate meta-schema table with schema resources. |
| 220 | Useful for development purposes.`, |
| 221 | Flags: []cli.Flag{ |
| 222 | cli.StringFlag{Name: "database-type, t", Value: "sqlite3", Usage: "Backend datebase type"}, |
| 223 | cli.StringFlag{Name: "database, d", Value: "gohan.db", Usage: "DB connection string"}, |
| 224 | cli.StringFlag{Name: "schema, s", Value: "embed://etc/schema/gohan.json", Usage: "Schema definition"}, |
| 225 | cli.BoolFlag{Name: "drop-on-create", Usage: "If true, old database will be dropped"}, |
| 226 | cli.BoolFlag{Name: "cascade", Usage: "If true, FOREIGN KEYS in database will be created with ON DELETE CASCADE"}, |
| 227 | cli.StringFlag{Name: "meta-schema, m", Value: "", Usage: "Meta-schema file (optional)"}, |
| 228 | cli.StringFlag{Name: "multiple-schemas", Value: "", Usage: "Multiple schema files separated by semicolon (;)"}, |
| 229 | }, |
| 230 | Action: func(c *cli.Context) { |
| 231 | dbType := c.String("database-type") |
| 232 | dbConnection := c.String("database") |
| 233 | schemaFile := c.String("schema") |
| 234 | metaSchemaFile := c.String("meta-schema") |
| 235 | multipleSchemaFiles := c.String("multiple-schemas") |
| 236 | dropOnCreate := c.Bool("drop-on-create") |
| 237 | cascade := c.Bool("cascade") |
| 238 | manager := schema.GetManager() |
| 239 | if err := manager.LoadSchemasFromFiles(schemaFile, metaSchemaFile); err != nil { |
| 240 | util.ExitFatal(err) |
| 241 | } |
| 242 | if err := manager.OrderedLoadSchemasFromFiles(strings.Split(multipleSchemaFiles, ";")); err != nil { |
| 243 | util.ExitFatal(err) |
| 244 | } |
| 245 | if err := db.InitDBWithSchemas(dbType, dbConnection, db.InitDBParams{ |
| 246 | DropOnCreate: dropOnCreate, |
| 247 | Cascade: cascade, |
| 248 | AutoMigrate: false, |
| 249 | AllowEmpty: false, |
| 250 | }); err != nil { |
| 251 | util.ExitFatal(err) |
| 252 | } |
| 253 | fmt.Println("DB is initialized") |
| 254 | }, |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | func getConvertCommand() cli.Command { |
| 259 | return cli.Command{ |
no test coverage detected