Projection detect changes

Hello dear

I’m trying to list custom projection that have been created. Is there a way to list the definition.

So what i’m trying to do is to detect if a change has been made. I generate the projection using c# code and want to check if the existing projection has been changed and if has been change update the projection…

So far it seems the projection sdk only list the existing projection but not list the existing javascript implementation

Thanks

Not directly answering your question, but we had a similar problem and couldn’t work out how to detect a change either, so in our release package we included the new projection. When we deployed to the Evenstore, if a file is detected, we simply update the projection.
It’s moving the problem to the deployment package building, rather than trying to make the Evenstore assist.

So, the short version of that. Only include the projection in your release if there is a change.

@steven.blair

do you what is the different between a projection result and state? At the moment I’m using result…

I am not entirely sure.
My guess is result is a further transformation performed on your state (so the the output from transformBy)

I remember doing it once with the TCP client, and it worked just fine. I was getting the source code of the existing projection, then comparing it with the current version and replacing it if necessary. I will check if I can find the code.

do you have an example with the grpc client? I can list the projection but not the source code

It doesn’t seem possible with gRPC client, looking at the API surface. You can only get the status object, not the projection itself.

With the TCP client the code was:

try
{
    var query = await projectionsManager.GetQueryAsync(projection.Name, credentials);
    if (query != projection.Query)
    {
        Log.Info("Projection {Name} exist but the query has changed, updating", projection.Name);
        await projectionsManager.UpdateQueryAsync(projection.Name, projection.Query, credentials);
    }
    else
    {
        Log.Info("Projection {Name} is up to date", projection.Name);
    }
}
catch (ProjectionCommandFailedException e) when (e.HttpStatusCode == 404)
{
    Log.Info("Projection {Name} doesn't exist, creating", projection.Name);
    await projectionsManager.CreateContinuousAsync(projection.Name, projection.Query, credentials);
}

still not possible with the gRPC client? It would be nice if GetStatusAsync would return a hash representing the query or something like that.

Yeah, it’s not possible at the moment, but we are aware of the issue.

Personally, I consider those things more Ops related rather than Dev. My thought is that we should have some Ops tooling like IaC providers to handle cases like custom projection management. Kind of similar to managing the schema and stored procedures in relational databases using migrations.

Btw, although gRPC API doesn’t return the query, you can use the HTTP API.

GET /projection/{name}/query
$ curl -X GET https://mynode-0.mesdb.eventstore.cloud:2113/projection/test1/query -u "admin:changeit"

fromAll()
.when({
    $init: function(){
        return {
            count: 0
        }
    },
    ItemAdded: function(s,e){
        if(e.body.Description.indexOf("Xbox One S") >= 0){
            s.count += 1;
        }
    }
})%