2 from django.db import connection
3 from south.db import generic
5 class DatabaseOperations(generic.DatabaseOperations):
8 PsycoPG2 implementation of database operations.
11 def rename_column(self, table_name, old, new):
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)
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()
27 generic.DatabaseOperations.rename_table(self, old_table_name+"_id_seq", table_name+"_id_seq")
30 print " ~ No such sequence (ignoring error)"
31 self.rollback_transaction()
33 self.commit_transaction()
34 self.start_transaction()
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.
40 generic.DatabaseOperations.rename_table(self, old_table_name+"_pkey", table_name+ "_pkey")
43 print " ~ No such primary key (ignoring error)"
44 self.rollback_transaction()
46 self.commit_transaction()
47 self.start_transaction()
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)