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
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
:type scriptparam: str
:type param: str
"""
options = ['init', 're_init', 'drop_db', 'drop_all']
if scriptparam == 'all':
if param == 'all':
for scriptname in options:
generate_sql(scriptname)
elif scriptparam == 'help':
message = "usage: fab database.generate:scriptparam='all'"\
elif param == 'help':
message = "usage: fab database.generate:param='all'"\
" or some value of {options} \n leave the parameter "\
"blank to generate all scripts. Exiting.".format(options=options)
print_console(message, exit_program=True)
elif scriptparam in options:
generate_sql(scriptparam)
elif param in options:
generate_sql(param)
else:
msg = "error - script parameters: " \
"{scriptparam} is not one of {options}".format(
scriptparam=scriptparam, options=options)
"{param} is not one of {options}".format(
param=param, options=options)
printerr(message=msg,
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
dbuser - set to "default" but can also be set to "admin"
backup_file - alternate name for the backup_file to restore from
reinitialize - if supervisor needs to be restarted, do it
:parameter dbuser: set to "default" but can also be set to "admin"
:type dbuser: str
: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
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):
"""
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
import initialize
@ -637,6 +647,10 @@ def edit(param='help'):
@task
def test():
"""
test connecting to database (probably better to just use
database.commandline)
"""
configuration = env.config
db_name = configuration.server.database.name