Feature(s) impacted
Unable to deploy a local (empty) dev branch due to schem diff with origin env (production)
Observed behavior
The command:
``
fails - and a schema diff shown only including the following difference:
{
attributes: {
fields: [
{
- hook: "onFeeChange"
}
...
...
]
}
}
Expected behavior
Since the same .forestadmin-schema.json
file was deployed (verified to be deployed correctly) to both envs - there should be no schema diffs.
Context
- Project name: WescoverContentAdmin
- Environment name: Production (44638) and the local one id is (104873)
- Agent (forest package) name & version:
"meta": {
"liana": "forest-express-mongoose",
"liana_version": "8.7.6",
"stack": {
"database_type": "multiple",
"engine": "nodejs",
"engine_version": "16.18.0",
"orm_version": "5.3.16"
}
}
forest-cli/4.2.0 darwin-arm64 node-v16.18.0
- Database type: mongoose
- Recent changes made on your end if any: Ensures reset envs of Dev, cleaned old branches, rebuilt using node 16 (used to be 12) and ensured same schame json file used on all envs. Created a new clean empty branch that we try to deploy.
performing the schema:diff
command shows the same schema for Production, Test (72395), Dev (72437) And all have that same āhookā diff with the local dev env (104873).
Not sure what could cause such a difference in schemas.
Hello @Yoad_Snapir, and welcome back to the community,
the hook: āonFeeChangeā is added to your schema due to a change hook detected in your customization:
(please find the documentation here),
Please check that your action definition for āModify Commissionā is the same in production and local environments, especially regarding change hooks as per the documentation linked.
If you still encounter issues, please share your action definition in each environment so we can help you troubleshoot (via MP if sensitive).
Regards,
@Nicolas.M
Thank you @Nicolas.M!
I suspected this is the why we have this hook in the schema.
Indeed the action definition has this:
{
field: 'Application Fee',
description: 'Please provide new Application Fee (in Cents)',
type: 'Number',
hook: 'onFeeChange',
isRequired: true,
},
And then this:
hooks: {
...,
change: {
onFeeChange: async ({ fields, request, changedField }) => {
const mpCom = fields.find(
(field) => field.field === 'MP Commission'
);
const proFee = fields.find(
(field) => field.field === 'Processing Fee'
);
mpCom.value = changedField.value - proFee.value;
return fields;
},
},
}
BUT the same code was deployed to the local env and the live env.
This is the strange part - it is as if the prod/test/dev envs, (which are sent the same schema file generated locally) do not āacceptā and store that hook in the internal schema.
Then - this difference shows up when we try to push a layout branch.
@Nicolas.M making sure you saw my reply.
Thanks.
Hello @Yoad_Snapir,
Sorry for the delay, your issue is a little hard to troubleshoot.
A couple things you can try/check while we investigate further:
- make sure that your local branch contain changes. I donāt think that you are supposed to push an empty branch.
- contrary to the dev environments, the production schema is NOT recomputed automatically by the agent on startup, even if your code changes. You might want to make sure that your prod schema is in sync with the code.
Regards
@Nicolas.M I will not be concerned about the empty branch deployment.
The schema:diff shows that problem already without even thinking about branch deployments.
The schema file is the same - the local dev puts it into the source report (checkin) and the production pulls it fro that same repo, same branch - they are identical.
I am now seeing this difference though - production uses forest-cli v3.x to push the schema the local env uses forest-cli v4.x
Could that cause the difference?
After all the forest-cli is not the one generating the schema, only pushes it rather - but still - do you think this could be the cause?
Hello @Yoad_Snapir,
I have escalated the question and we are still looking into it. Thanks for your patience, we will keep you updated shortly.
Looking through your schemas, it not clear why the production is missing the
hook: "onFeeChange"
, which should be there according to the code you shared.
Can you please share the value of your NODE_ENV
variable in the different envs ?
If this is an option for you, could you please update your production schema to match the local one ? (with the expected hook
property).
This should allow you to deploy the local branch.
Thanks @Nicolas.M - As you would expect my local dev (where the schema is generated) has the value ādevelopmentā for āNODE_ENVā (itās empty, development is the default afaik).
and the Production (and all remote) env has āproductionā.
To double check schema is the same:
I have done the following:
- Copied the schema from the local dev env (which is == to the one in the repo and == to the one already on the remote server)
- Used that schema on the remote server (just in case, although diff shows they are identical)
- installed on the server the forest-cli tool (version 3, and also did the same with version 4)
- did
forest schema:apply
- got this result:
Reading ā.forestadmin-schema.jsonā from current directoryā¦
Using the forest environment secret found in the environment variable āFOREST_ENV_SECRETā
Sending ā.forestadmin-schema.jsonāā¦
The schema is the same as before, nothing changed.
- Ran again locally
forest schema:diff
- got again the hook as a difference.
Hi @Yoad_Snapir
small question, I wonder why you use forest schema:apply instead of restarting your server after synchronizing the code (with forestadmin-schema.json)?
Good question!
We deploy to production using blue/green - so we deploy to a staging env, and them swap servers.
Thus - I need to be in control of the schema apply.
I I leave it to the server - the swapped out āold versionā is started as the new āstagingā and overrides the schema with the old one.
So the flow using auto apply looks like this:
- existing version X0 on live
- deploy version X1 to staging - applies X1 schema
- Swap in - starts staging with X1 as āliveā - applies X1 to live (as we want)
- Swap out - starts live as with X0 as āstagingā - applies X0 to live (we donāt want that)
we tries setting up the env of the staging to point at another āremote envā - but we cannot control how many restarts happens and with which env - itās not a ācleanā process.
we need tight control on schema apply thus.
Let me know if you need more info on this.
Found it ! Oh wouah after a deep research I found the culprit.
There is a missing serialization attribute inside the forest cli, who remove the hook property, on the schema:apply command.
I will fix that right away and keep you updated.
Thankās for your feedback 
1 Like
Hey @Yoad_Snapir
the fix has been released now.
Can you upgrade forest-cli to the latest version (v4.2.2) and re-apply the schema of your remote env ? 
Let me know.
1 Like
This solved it!
Thanks for the help here, Forest cli after all was the cause - good to know.
2 Likes