Schema modification export (custom fields)

We have 2 ERP Next environements, staging and productions. Sometimes we create some new custom fields in the staging environement and we need to deploy theese changes to the production environement, is it possible to export the “schema” or the updates to the fields to import them to another environement?

Thank you

ERPNext provides Fixtures just for that.

You can directly export fixtures in ERPnext app, but those will be lost when you update or will show up as conflicts. Hence you create a new app and export those changes to that app which will remain untouched by ERPNext update routines.

https://frappe.io/docs/user/en/tutorial/new-app

Step One : Create new app (say new-app) and initialize a new git repo for this app.

Step Two : Find hooks.py file in your new-app folder

Step Three : Mention which DocType you would like to export to fixtures in the fixtures list like this:

# Fixtures

fixtures = ['Report', 'Role Profile', 'Role', 'Custom Field', 'Custom Script', 'Property Setter', 'Workflow', 'Workflow State', 'Workflow Action']

Include Custom Field and Property Setter in your fixtures list.

Step Three : Customize a document via the Customize Form route.

Step Four : Export fixtures by running this command in your frappe-bench folder

bench export-fixtures

This command will export all the data for the doctypes you mentioned in the fixtures list.

Finally commit your changes (setup a seperate git repository for this app alone) and push it. Pull your app onto your production server. Migrate and Restart your server (bench migrate and bench restart)


Tips

  • Ensure that your SQL process is running. bench export-fixtures requires the mysql service to be active. If not, get that service up and running.

  • Also, take care that fixtures remain in sync at all the times when you are going to deploy on the production server. You don’t want to run into conflicts when you migrate on production server.

  • Include other doctypes as you require, because it may save time in case you create certain things in development server and don’t wish to do it again on the production server because it consumes more time and may lead to mistakes due to the eleventh hour rush. Doctypes like Role, Report, Role Profile etc. are recommended to be included in stuff like this.

  • Most importantly, before committing these changes, CHECK, CHECK and RECHECK. Make sure they are exactly the required and relevant changes for the feature you wish to push to production server since ALL uncommitted fixtures present in Database but NOT in the fixtures JSON will be exported.

21 Likes