Package dak :: Package dakdb
[hide private]
[frames] | no frames]

Source Code for Package dak.dakdb

 1  """ 
 2  Database update scripts for usage with ``dak update-db`` 
 3   
 4  @contact: Debian FTP Master <ftpmaster@debian.org> 
 5  @copyright: 2008  Michael Casadevall <mcasadevall@debian.org> 
 6  @license: GNU General Public License version 2 or later 
 7   
 8  Update scripts have to ``import psycopg2`` and 
 9  ``from daklib.dak_exceptions import DBUpdateError``. 
10   
11  There has to be **at least** the function ``do_update(self)`` to be 
12  defined. It should take all neccessary steps to update the 
13  database. If the update fails the changes have to be rolled back and the 
14  :exc:`~daklib.dak_exceptions.DBUpdateError` exception raised to properly 
15  halt the execution of any other update. 
16   
17  Example:: 
18   
19   def do_update(self): 
20       print("Doing something") 
21   
22       try: 
23           c = self.db.cursor() 
24           c.execute("SOME SQL STATEMENT") 
25           self.db.commit() 
26   
27       except psycopg2.ProgrammingError as msg: 
28           self.db.rollback() 
29           raise DBUpdateError(f"Unable to do whatever, rollback issued. Error message: {msg}") 
30   
31  This function can do whatever it wants and use everything from dak and 
32  daklib. 
33   
34  """ 
35