You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

43 lines
1.3 KiB

  1. from django.contrib.postgres.signals import register_hstore_handler
  2. from django.db.migrations.operations.base import Operation
  3. class CreateExtension(Operation):
  4. reversible = True
  5. def __init__(self, name):
  6. self.name = name
  7. def state_forwards(self, app_label, state):
  8. pass
  9. def database_forwards(self, app_label, schema_editor, from_state, to_state):
  10. if schema_editor.connection.vendor != 'postgresql':
  11. return
  12. schema_editor.execute("CREATE EXTENSION IF NOT EXISTS %s" % self.name)
  13. def database_backwards(self, app_label, schema_editor, from_state, to_state):
  14. schema_editor.execute("DROP EXTENSION %s" % self.name)
  15. def describe(self):
  16. return "Creates extension %s" % self.name
  17. class HStoreExtension(CreateExtension):
  18. def __init__(self):
  19. self.name = 'hstore'
  20. def database_forwards(self, app_label, schema_editor, from_state, to_state):
  21. super(HStoreExtension, self).database_forwards(app_label, schema_editor, from_state, to_state)
  22. # Register hstore straight away as it cannot be done before the
  23. # extension is installed, a subsequent data migration would use the
  24. # same connection
  25. register_hstore_handler(schema_editor.connection)
  26. class UnaccentExtension(CreateExtension):
  27. def __init__(self):
  28. self.name = 'unaccent'