1""" 

2Database 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 

8Update scripts have to ``import psycopg2`` and 

9``from daklib.dak_exceptions import DBUpdateError``. 

10 

11There has to be **at least** the function ``do_update(self)`` to be 

12defined. It should take all neccessary steps to update the 

13database. If the update fails the changes have to be rolled back and the 

14:exc:`~daklib.dak_exceptions.DBUpdateError` exception raised to properly 

15halt the execution of any other update. 

16 

17Example:: 

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 

31This function can do whatever it wants and use everything from dak and 

32daklib. 

33 

34"""