#NEWLINE# def db_alter( name , user = None , host = None , port = None , maintenance_db = None , password = None , tablespace = None , owner = None , owner_recurse = False , runas = None ) : #NEWLINE# #INDENT# "\n    Change tablespace or/and owner of database.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' postgres.db_alter dbname owner=otheruser\n    " #NEWLINE# if ( not any ( ( tablespace , owner ) ) ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# if ( owner and owner_recurse ) : #NEWLINE# #INDENT# ret = owner_to ( name , owner , user = user , host = host , port = port , password = password , runas = runas ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# queries = [ ] #NEWLINE# if owner : #NEWLINE# #INDENT# queries . append ( 'ALTER DATABASE "{0}" OWNER TO "{1}"' . format ( name , owner ) ) #NEWLINE# #UNINDENT# if tablespace : #NEWLINE# #INDENT# queries . append ( 'ALTER DATABASE "{0}" SET TABLESPACE "{1}"' . format ( name , tablespace ) ) #NEWLINE# #UNINDENT# for query in queries : #NEWLINE# #INDENT# ret = _psql_prepare_and_run ( [ '-c' , query ] , user = user , host = host , port = port , maintenance_db = maintenance_db , password = password , runas = runas ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ret [ 'retcode' ] != 0 ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# return True