Hi,
We are developing a custom app. The custom app has some patches defined in patches.txt.
Now, when we install the custom app on the site, say.
bench --site [sitename] install-app custom-app
The patches do not get executed even though the patchLog table has all the patch entries.
However, when we do bench migrate on an existing site
bench --site [sitename2] migrate
The patches get executed successfully.
Is this the normal behaviour in frappe? How do we get the patches executed when installing app?
Correct. The reason is that patches are typically used in the upgrade process to change the schema of already existing doctypes. If you’re installing a new app with new doctypes, you typically wouldn’t patch but just define everything the way you want it in the first place.
Can I ask what you are trying to accomplish with patches at installation time?
Ah, understood. Another approach for default data would be to use “fixtures”. They’re not very well documented, unfortunately, but there’s lots of discussion in the forum.
Please note that if your use case is to have initial data that can be then modified by the users, fixtures won’t work as they will sync and overwrite the data on every migrate.
To have initial data, but not static data, the only way I’ve found is to use both a patch and after_install hook, to cover existing and new installations.