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

Function CopyDBResources

db/db.go:196–243  ·  view source on GitHub ↗

CopyDBResources copies resources from input database to output database

(input, output DB, overrideExisting bool)

Source from the content-addressed store, hash-verified

194
195//CopyDBResources copies resources from input database to output database
196func 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
246func CreateFromConfig(config *util.Config) (DB, error) {

Callers

nothing calls this directly

Calls 10

WithinFunction · 0.85
OrderedSchemasMethod · 0.80
IsAbstractMethod · 0.80
PopulateDefaultsMethod · 0.80
InfoMethod · 0.65
ListMethod · 0.65
IDMethod · 0.65
FetchMethod · 0.65
CreateMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected