NorDBManagement¶
This module contains all basic functions of the database which do not fit quite to the other modules.
Functions and Classes¶
-
active_and_backup_databases_are_in_sync()¶ Function for checking whether the active database and backup database are in sync, i.e. their content is the same. :returns boolean: True if in sync, False if not (or unable to check)
-
alterUser(username, new_username=None, new_user_role=None, new_password=None, db_conn=None)¶ Alters user in the database. If you modify your own user, this is allowed for default_users, otherwise admin rights required. NOT DONE YET! :param username str: the username of the user which will be modified :param new_username str: The username which will be the new username of the user :param new_user_role str: The role which will be the new role of the user. Options: guests, default_users, station_managers and admins :param new_password str: The new password to the database
-
checkPermissions(required_role, db_conn=None)¶ Function that checks the owner level of the current user and returns this.
Parameters: str (required_role) – the required role level of the user Returns: boolean value if the current_user has access rights of the required role
-
connection_to_active_db_is_working(test_reading=False)¶ Function for checking that the connection to the ‘active_database’ is working.
-
connection_to_backup_db_is_working(test_reading=False)¶ Function for checking that the connection to the ‘backup_database’ is working.
-
countEvents(solution_type=None, db_conn=None)¶ Function for returning the number of all events in the database.
Parameters: str (solution_type) – If solution_type is defined, countEvents will only count all events of the chosen type. Otherwise it will return the amount of all events in the database. Returns: The number of events of the chosen type or number of all events
-
countStations(network=None, db_conn=None)¶ Function for returning the number of all stations in the database
Parameters: str (network) – If network is given, the function will only return the amount of stations in the given network. Returns: The number of stations in given network or number of all stations.
-
createBackup(backup_name='', backup_dir='', backup_path='')¶ Function that creates a backup of the database in its current form and saves it to the backups folder. Default path format of the backup file: ‘<settings.backup_dir>/backup_<dbname of the active database>_<timestamp>’
Parameters: Returns: Tuple consisting of return code of the backup file creation (int) and the path of the backup file (str)
-
createDatabase()¶ Method for creating the database if the database doesn’t exist. Postgres createdb rights required. You will be automatically the owner of the database.
-
createUser(username, abbreviation, user_role, password, db_conn=None)¶ Creates a new user to the database. Admin rights required. :param username str: the username of the new user :param abbreviation str: abbreviated 3 characters long form of the username, shown e.g. in Nordic files :param user_role str: the role of the new user :param password str: the password of the new user
-
databaseIsRunning()¶ Function for checking out if database is running and can be connected to
Returns: True if database is running
-
destroyDatabase()¶ Method for destroying the database if the database exists
-
getRoleLevel(role_str)¶ Helper function to calculate role level from the role string :param role_str str: The role level string :returns: the level of the role as a integer
-
loadBackup(backup_path)¶ Function that destroys the database and loads a backup of the database into a new one.
Parameters: backup_path (str) – path to the database backup
-
removeUser(username, db_conn=None)¶ Removes a user from the database and postgres system. Admin rights required. :param username str:
-
setPIDconf(pid_pf, pid_if, pid_tl)¶ Function for overwriting the default persistent ID parameters in the table ‘conf’. If an argument has value None or ‘’ the corresponding conf value is not altered.
Parameters:
-
set_opmode_to_backup()¶ Function for setting the operating mode to be ‘backup’.
-
set_opmode_to_normal()¶ Function for setting the operating mode to be ‘normal’.
-
sync_backup_to_active_with_checks(check_operating_mode=True)¶ Function for syncing all differences in ‘backup_database’ to ‘active_database’. Intended use: to sync the changes made to backup database during backup mode into active database when switching back to normal mode.