Run some SQL files after Django's syncdb.
Usage:
- Add
post_syncdb_hooks
toINSTALLED_APPS
. - Add submodules you need (currently only
post_syncdb_hooks.partitioning
is 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 everysyncdb
these 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 INTO
instead of one in PostgreSQL; - Need to run
manage.py syncdb
twice since Django create indexes afterpost-syncdb
hook.