MCPcopy Create free account
hub / github.com/Permify/permify / PartialWrite

Method PartialWrite

internal/servers/schema_server.go:92–200  ·  view source on GitHub ↗

PartialWrite applies incremental updates to the schema of a specific tenant based on the provided request.

(ctx context.Context, request *v1.SchemaPartialWriteRequest)

Source from the content-addressed store, hash-verified

90
91// PartialWrite applies incremental updates to the schema of a specific tenant based on the provided request.
92func (r *SchemaServer) PartialWrite(ctx context.Context, request *v1.SchemaPartialWriteRequest) (*v1.SchemaPartialWriteResponse, error) {
93 // Start a new tracing span for monitoring and observability.
94 ctx, span := internal.Tracer.Start(ctx, "schemas.partial-write")
95 defer span.End() // Ensure the span is closed at the end of the function.
96
97 // Retrieve or default the schema version from the request.
98 version := request.GetMetadata().GetSchemaVersion()
99 if version == "" { // If not provided, fetch the latest version.
100 ver, err := r.sr.HeadVersion(ctx, request.GetTenantId())
101 if err != nil {
102 return nil, status.Error(GetStatus(err), err.Error()) // Return version error
103 }
104 version = ver
105 }
106
107 // Fetch the current schema definition as a string.
108 definitions, err := r.sr.ReadSchemaString(ctx, request.GetTenantId(), version)
109 if err != nil {
110 span.RecordError(err) // Log and record the error.
111 return nil, status.Error(GetStatus(err), err.Error())
112 }
113
114 // Parse the schema definitions into a structured format.
115 p := parser.NewParser(strings.Join(definitions, "\n"))
116 schema, err := p.Parse()
117 if err != nil {
118 span.RecordError(err) // Log and record the error.
119 return nil, status.Error(GetStatus(err), err.Error())
120 }
121
122 // Iterate through each partial update in the request and apply changes.
123 for entityName, partials := range request.GetPartials() {
124 for _, write := range partials.GetWrite() { // Handle new schema statements.
125 pr := parser.NewParser(write)
126 stmt, err := pr.ParsePartial(entityName)
127 if err != nil {
128 span.RecordError(err)
129 return nil, status.Error(GetStatus(err), err.Error())
130 }
131 err = schema.AddStatement(entityName, stmt)
132 if err != nil {
133 span.RecordError(err)
134 return nil, status.Error(GetStatus(err), err.Error())
135 }
136 }
137
138 for _, update := range partials.GetUpdate() { // Handle schema updates.
139 pr := parser.NewParser(update)
140 stmt, err := pr.ParsePartial(entityName)
141 if err != nil {
142 span.RecordError(err)
143 return nil, status.Error(GetStatus(err), err.Error())
144 }
145 err = schema.UpdateStatement(entityName, stmt)
146 if err != nil {
147 span.RecordError(err)
148 return nil, status.Error(GetStatus(err), err.Error())
149 }

Callers

nothing calls this directly

Implementers 1

UnimplementedSchemaServerpkg/pb/base/v1/service_grpc.pb.go

Calls 15

ParseMethod · 0.95
ParsePartialMethod · 0.95
NewParserFunction · 0.92
NewCompilerFunction · 0.92
GetStatusFunction · 0.85
StartMethod · 0.80
GetPartialsMethod · 0.80
GetWriteMethod · 0.80
AddStatementMethod · 0.80
GetUpdateMethod · 0.80
UpdateStatementMethod · 0.80
GetDeleteMethod · 0.80

Tested by

no test coverage detected