CopyDBResources copies resources from input database to output database
(input, output DB, overrideExisting bool)
| 194 | |
| 195 | //CopyDBResources copies resources from input database to output database |
| 196 | func CopyDBResources(input, output DB, overrideExisting bool) error { |
| 197 | schemaManager := schema.GetManager() |
| 198 | schemas := schemaManager.OrderedSchemas() |
| 199 | |
| 200 | if len(schemas) == 0 { |
| 201 | return errNoSchemasInManager |
| 202 | } |
| 203 | |
| 204 | if errInputTx := Within(input, func(inputTx transaction.Transaction) error { |
| 205 | if errorOutputTx := Within(output, func(outputTx transaction.Transaction) error { |
| 206 | for _, s := range schemas { |
| 207 | if s.IsAbstract() { |
| 208 | continue |
| 209 | } |
| 210 | log.Info("Populating resources for schema %s", s.ID) |
| 211 | resources, _, err := inputTx.List(s, nil, nil, nil) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | |
| 216 | for _, resource := range resources { |
| 217 | log.Info("Creating resource %s", resource.ID()) |
| 218 | destResource, _ := outputTx.Fetch(s, transaction.IDFilter(resource.ID()), nil) |
| 219 | if destResource == nil { |
| 220 | resource.PopulateDefaults() |
| 221 | err := outputTx.Create(resource) |
| 222 | if err != nil { |
| 223 | return err |
| 224 | } |
| 225 | } else if overrideExisting { |
| 226 | err := outputTx.Update(resource) |
| 227 | if err != nil { |
| 228 | return err |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | return nil |
| 234 | }); errorOutputTx != nil { |
| 235 | return errorOutputTx |
| 236 | } |
| 237 | return nil |
| 238 | }); errInputTx != nil { |
| 239 | return errInputTx |
| 240 | } |
| 241 | |
| 242 | return nil |
| 243 | } |
| 244 | |
| 245 | // CreateFromConfig creates db connection from config |
| 246 | func CreateFromConfig(config *util.Config) (DB, error) { |
nothing calls this directly
no test coverage detected