Displaying links to Wikipedia in templates.
[wolnelektury.git] / apps / south / db / postgresql_psycopg2.py
1
2 from django.db import connection
3 from south.db import generic
4
5 class DatabaseOperations(generic.DatabaseOperations):
6
7     """
8     PsycoPG2 implementation of database operations.
9     """
10
11     def rename_column(self, table_name, old, new):
12         if old == new:
13             return []
14         qn = connection.ops.quote_name
15         params = (qn(table_name), qn(old), qn(new))
16         self.execute('ALTER TABLE %s RENAME COLUMN %s TO %s;' % params)
17     
18     def rename_table(self, old_table_name, table_name):
19         "will rename the table and an associated ID sequence and primary key index"
20         # First, rename the table
21         generic.DatabaseOperations.rename_table(self, old_table_name, table_name)
22         # Then, try renaming the ID sequence
23         # (if you're using other AutoFields... your problem, unfortunately)
24         self.commit_transaction()
25         self.start_transaction()
26         try:
27             generic.DatabaseOperations.rename_table(self, old_table_name+"_id_seq", table_name+"_id_seq")
28         except:
29             if self.debug:
30                 print "   ~ No such sequence (ignoring error)"
31             self.rollback_transaction()
32         else:
33             self.commit_transaction()
34         self.start_transaction()
35
36         # Rename primary key index, will not rename other indices on
37         # the table that are used by django (e.g. foreign keys). Until
38         # figure out how, you need to do this yourself.
39         try:
40             generic.DatabaseOperations.rename_table(self, old_table_name+"_pkey", table_name+ "_pkey")
41         except:
42             if self.debug:
43                 print "   ~ No such primary key (ignoring error)"
44             self.rollback_transaction()
45         else:
46             self.commit_transaction()
47         self.start_transaction()
48
49
50     def rename_index(self, old_index_name, index_name):
51         "Rename an index individually"
52         generic.DatabaseOperations.rename_table(self, old_index_name, index_name)