Run some SQL files after Django's syncdb.
Usage:
- Add
post_syncdb_hookstoINSTALLED_APPS. - Add submodules you need (currently only
post_syncdb_hooks.partitioningis available) to yourINSTALLED_APPS. This will add functions to your DB after every syncdb. - Create a file
sql/post_syncdb-hook.sql(orsql/post_syncdb-hook.<last part of db-backend mame>.sql) in your app directory with calls to the functions. Now after everysyncdbthese SQL files will be sent to the DB engine.
If you have multiple DB configuration, Django will call this hook with DB-alias used to syncdb your app.
Partitioning is currently implemented only for PostgreSQL. Use db_index parameter in the fields of your models to automatically create indexes on partitions.
Apply post_syncdb_hooks.partitioning.to_partition decorator to save() method of models involved into partitioning:
from post_syncdb_hooks.partitioning import to_partition
from django.db.models import Model
class MyModel(Model):
#...
@to_partition
def save(self, *args, **kwargs):
#...
super(self.__class__, self).save(*args, **kwargs)Drawbacks:
- Empty indexes on master-table;
- Two queries per
INSERT INTOinstead of one in PostgreSQL; - Need to run
manage.py syncdbtwice since Django create indexes afterpost-syncdbhook.