Database patch is not applied during install-app

I’m just new to Frappe/ERPNext. I am developing a custom app. I want to add a new business domain whenever my app is installed. I mean a business domain like Agriculture, Distribution, Education… not a domain name (btw, I find it’s very confusing by the term “Domain”. Every time I want to google it, all the results are about the web site domain name, the thing that comes after bench --site!)

To do that, I currently make a patch which inserts a row in the doctype Domain (DB table tabDomain) if it does not exist. The patch works correctly: when I run bench --site ... migrate a row is inserted into the table as I expect.

However, when my app is installed from scratch (bench --site ... install-app ...), the row that I expect was not inserted into table tabDomain. I then check the table tabPatch Log, my patch is there! It seems the bench command just marks my patch as executed but doesn’t really execute it. I delete the corresponding line in table tabPatch Log and return bench ... migrate, my row is inserted correctly.

I event made my patch syntax error but the bench ... install-app still went well without any error. And the tabPatch Log contains my erroneous patch!

What could I do wrong? What is the correct way to have patches executed upon install-app?

I am using source code of frappe and erpnext on branch version-13. Version of bench is 5.0.0-dev

Thanks for you help!
Bao

use fixtures in hooks.py.

export fixtures and use filters for data that you need to be installed with your app.

use filters Export Fixtures for doctype - #2 by Sayed_Hameed_Ebrahim

Thanks a lot @revant_one ! This is what I am looking for

What about dependent data like I want to export data items and items groups but it fails as It throw message that item group is not available. Is any present workaround to tackle this . Is there any way to define order in hook.py ? I am talking about data which are in general masters for ERP and not transactional .Thanks in advance !

Check if install hooks help Hooks