updated the database module to have better documentation

This commit is contained in:
ronny abraham 2023-07-20 14:49:03 +03:00
parent ba75800fb6
commit 6afd1ee99b

View file

@ -149,35 +149,37 @@ def execute_sql(script_name, add_dbname=True, is_admin=False):
@task @task
def generate(scriptparam='all'): def generate(param='all'):
""" """
helper function to generate and upload the scripts helper function to generate and upload the scripts.
:parameter scriptparam: the name of the script we want to generate script options = 'init', 're_init', 'drop_db', 'drop_all'
:parameter param: the name of the script we want to generate.
defaults to all, in which case, all scripts are generated defaults to all, in which case, all scripts are generated
:type scriptparam: str :type param: str
""" """
options = ['init', 're_init', 'drop_db', 'drop_all'] options = ['init', 're_init', 'drop_db', 'drop_all']
if scriptparam == 'all': if param == 'all':
for scriptname in options: for scriptname in options:
generate_sql(scriptname) generate_sql(scriptname)
elif scriptparam == 'help': elif param == 'help':
message = "usage: fab database.generate:scriptparam='all'"\ message = "usage: fab database.generate:param='all'"\
" or some value of {options} \n leave the parameter "\ " or some value of {options} \n leave the parameter "\
"blank to generate all scripts. Exiting.".format(options=options) "blank to generate all scripts. Exiting.".format(options=options)
print_console(message, exit_program=True) print_console(message, exit_program=True)
elif scriptparam in options: elif param in options:
generate_sql(scriptparam) generate_sql(param)
else: else:
msg = "error - script parameters: " \ msg = "error - script parameters: " \
"{scriptparam} is not one of {options}".format( "{param} is not one of {options}".format(
scriptparam=scriptparam, options=options) param=param, options=options)
printerr(message=msg, printerr(message=msg,
errcode=DATABASE_ERROR_CODE_BAD_SCRIPT_PARAM, errcode=DATABASE_ERROR_CODE_BAD_SCRIPT_PARAM,
@ -374,9 +376,15 @@ def restore(dbuser='default', backup_file=None, reinitialize=True):
""" """
creates a dump of the database for backup and storage creates a dump of the database for backup and storage
dbuser - set to "default" but can also be set to "admin" :parameter dbuser: set to "default" but can also be set to "admin"
backup_file - alternate name for the backup_file to restore from :type dbuser: str
reinitialize - if supervisor needs to be restarted, do it
:parameter backup_file: alternate name for the backup_file to restore from.
defaults to None
:type backup_file: str
:parameter reinitialize: if supervisor needs to be restarted, do it
:type reinitialize: bool
the admin user is what it says, I have both of these in case I need to the admin user is what it says, I have both of these in case I need to
switch between the master user for the entire postgres install or the owner switch between the master user for the entire postgres install or the owner
@ -436,7 +444,9 @@ def restore(dbuser='default', backup_file=None, reinitialize=True):
def sync(src): def sync(src):
""" """
sync database from source branch to current branch sync database from source branch to current branch
src - the database source branch
:parameter src: the database source branch
:type src: str
""" """
configuration = env.config configuration = env.config
import initialize import initialize
@ -637,6 +647,10 @@ def edit(param='help'):
@task @task
def test(): def test():
"""
test connecting to database (probably better to just use
database.commandline)
"""
configuration = env.config configuration = env.config
db_name = configuration.server.database.name db_name = configuration.server.database.name