MCPcopy
hub / github.com/dgraph-io/dgraph / processSchemaFile

Method processSchemaFile

dgraph/cmd/live/run.go:219–257  ·  view source on GitHub ↗

processSchemaFile process schema for a given gz file.

(ctx context.Context, file string, key x.Sensitive,
	dgraphClient *dgo.Dgraph)

Source from the content-addressed store, hash-verified

217
218// processSchemaFile process schema for a given gz file.
219func (l *loader) processSchemaFile(ctx context.Context, file string, key x.Sensitive,
220 dgraphClient *dgo.Dgraph) error {
221 fmt.Printf("\nProcessing schema file %q\n", file)
222 if len(opt.authToken) > 0 {
223 md := metadata.New(nil)
224 md.Append("auth-token", opt.authToken)
225 ctx = metadata.NewOutgoingContext(ctx, md)
226 }
227
228 f, err := filestore.Open(file)
229 x.CheckfNoTrace(err)
230 defer func() {
231 if err := f.Close(); err != nil {
232 glog.Warningf("error while closing fd: %v", err)
233 }
234 }()
235
236 reader, err := enc.GetReader(key, f)
237 x.Check(err)
238 if strings.HasSuffix(strings.ToLower(file), ".gz") {
239 reader, err = gzip.NewReader(reader)
240 x.Check(err)
241 }
242
243 b, err := io.ReadAll(reader)
244 if err != nil {
245 x.Checkf(err, "Error while reading file")
246 }
247
248 op := &api.Operation{}
249 op.Schema = string(b)
250 if opt.preserveNs {
251 // Verify schema if we are loading into multiple namespaces.
252 if err := validateSchema(op.Schema, l.namespaces); err != nil {
253 return err
254 }
255 }
256 return dgraphClient.Alter(ctx, op)
257}
258
259func (l *loader) uid(val string, ns uint64) string {
260 // Attempt to parse as a UID (in the same format that dgraph outputs - a

Callers 1

runFunction · 0.80

Calls 9

OpenFunction · 0.92
CheckfNoTraceFunction · 0.92
GetReaderFunction · 0.92
CheckFunction · 0.92
CheckfFunction · 0.92
validateSchemaFunction · 0.85
WarningfMethod · 0.80
AlterMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected