9. Automate deployment using runscripts management command
9.1. Overview:
The idea is to make the deployment process easier by running one management command responsible for
running all scripts in one release. The runscript management command
checks the current version of the release settings.CODE_VERSION, determines all non-applied scripts
specific to that version then, applies them.
9.2. Adding a new script to be run:
Make sure to update
settings.CODE_VERSIONbefore running the script.Go to the following path:
pearlcertification/core/management/commands/runscripts.pyand write the list of scripts to apply in thescriptslist under Command class (make sure to add any arguments or kwargs the script needs):
scripts = [
Script("testscript", "v3.25.0", database="resnet", site="cert"),
Script("import", "v3.25.0", "file.txt", database="resnet", site="pqs"),
]
To execute the
runscriptscommand use the following code:
python manage.py runscripts
Any script that was successfully applied will be stored in the database under the
ManagementCommandmodel whose data can be viewed under django admin page/cert_admin/core/managementcommand/.To make scripts run only in one specific site (cert, green_door, pqs, rea) set
sitekwarg inScript()as following:
Script("testscript", "v3.25.0", database="resnet", site="cert")