south.db.postgresql_psycopg2: 44 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/south/db/postgresql_psycopg2.py

Stats: 0 executed, 41 missed, 3 excluded, 45 ignored

  1. import uuid
  2. from django.db.backends.util import truncate_name
  3. from south.db import generic
  4. class DatabaseOperations(generic.DatabaseOperations):
  5. """
  6. PsycoPG2 implementation of database operations.
  7. """
  8. backend_name = "postgres"
  9. def create_index_name(self, table_name, column_names, suffix=""):
  10. """
  11. Generate a unique name for the index
  12. Django's logic for naming field indexes is different in the
  13. postgresql_psycopg2 backend, so we follow that for single-column
  14. indexes.
  15. """
  16. if len(column_names) == 1:
  17. return truncate_name(
  18. '%s_%s%s' % (table_name, column_names[0], suffix),
  19. self._get_connection().ops.max_name_length()
  20. )
  21. return super(DatabaseOperations, self).create_index_name(table_name, column_names, suffix)
  22. @generic.copy_column_constraints
  23. @generic.delete_column_constraints
  24. def rename_column(self, table_name, old, new):
  25. if old == new:
  26. # Short-circuit out
  27. return []
  28. self.execute('ALTER TABLE %s RENAME COLUMN %s TO %s;' % (
  29. self.quote_name(table_name),
  30. self.quote_name(old),
  31. self.quote_name(new),
  32. ))
  33. @generic.invalidate_table_constraints
  34. def rename_table(self, old_table_name, table_name):
  35. "will rename the table and an associated ID sequence and primary key index"
  36. # First, rename the table
  37. generic.DatabaseOperations.rename_table(self, old_table_name, table_name)
  38. # Then, try renaming the ID sequence
  39. # (if you're using other AutoFields... your problem, unfortunately)
  40. self.commit_transaction()
  41. self.start_transaction()
  42. try:
  43. generic.DatabaseOperations.rename_table(self, old_table_name + "_id_seq", table_name + "_id_seq")
  44. except:
  45. if self.debug:
  46. print " ~ No such sequence (ignoring error)"
  47. self.rollback_transaction()
  48. else:
  49. self.commit_transaction()
  50. self.start_transaction()
  51. # Rename primary key index, will not rename other indices on
  52. # the table that are used by django (e.g. foreign keys). Until
  53. # figure out how, you need to do this yourself.
  54. try:
  55. generic.DatabaseOperations.rename_table(self, old_table_name + "_pkey", table_name + "_pkey")
  56. except:
  57. if self.debug:
  58. print " ~ No such primary key (ignoring error)"
  59. self.rollback_transaction()
  60. else:
  61. self.commit_transaction()
  62. self.start_transaction()
  63. def rename_index(self, old_index_name, index_name):
  64. "Rename an index individually"
  65. generic.DatabaseOperations.rename_table(self, old_index_name, index_name)
  66. def _default_value_workaround(self, value):
  67. "Support for UUIDs on psql"
  68. if isinstance(value, uuid.UUID):
  69. return str(value)
  70. else:
  71. return super(DatabaseOperations, self)._default_value_workaround(value)
  72. def _db_type_for_alter_column(self, field):
  73. return self._db_positive_type_for_alter_column(DatabaseOperations, field)
  74. def _alter_add_column_mods(self, field, name, params, sqls):
  75. return self._alter_add_positive_check(DatabaseOperations, field, name, params, sqls)