X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/21f878e8112cf1f9b732a6dbb77e70efa68a01aa..b7d5131321533374cdcb85542ef4dcb53269863d:/apps/south/db/postgresql_psycopg2.py?ds=sidebyside diff --git a/apps/south/db/postgresql_psycopg2.py b/apps/south/db/postgresql_psycopg2.py index 278eb3e9f..839b4b16f 100644 --- a/apps/south/db/postgresql_psycopg2.py +++ b/apps/south/db/postgresql_psycopg2.py @@ -16,6 +16,7 @@ class DatabaseOperations(generic.DatabaseOperations): self.execute('ALTER TABLE %s RENAME COLUMN %s TO %s;' % params) def rename_table(self, old_table_name, table_name): + "will rename the table and an associated ID sequence and primary key index" # First, rename the table generic.DatabaseOperations.rename_table(self, old_table_name, table_name) # Then, try renaming the ID sequence @@ -25,8 +26,27 @@ class DatabaseOperations(generic.DatabaseOperations): try: generic.DatabaseOperations.rename_table(self, old_table_name+"_id_seq", table_name+"_id_seq") except: - print " ~ No such sequence (ignoring error)" + if self.debug: + print " ~ No such sequence (ignoring error)" self.rollback_transaction() else: self.commit_transaction() - self.start_transaction() \ No newline at end of file + self.start_transaction() + + # Rename primary key index, will not rename other indices on + # the table that are used by django (e.g. foreign keys). Until + # figure out how, you need to do this yourself. + try: + generic.DatabaseOperations.rename_table(self, old_table_name+"_pkey", table_name+ "_pkey") + except: + if self.debug: + print " ~ No such primary key (ignoring error)" + self.rollback_transaction() + else: + self.commit_transaction() + self.start_transaction() + + + def rename_index(self, old_index_name, index_name): + "Rename an index individually" + generic.DatabaseOperations.rename_table(self, old_index_name, index_name)