processSchemaFile process schema for a given gz file.
(ctx context.Context, file string, key x.Sensitive, dgraphClient *dgo.Dgraph)
| 217 | |
| 218 | // processSchemaFile process schema for a given gz file. |
| 219 | func (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 | |
| 259 | func (l *loader) uid(val string, ns uint64) string { |
| 260 | // Attempt to parse as a UID (in the same format that dgraph outputs - a |
no test coverage detected