Reputation: 65600
I am working in Django 1.8 with a Postgres database.
My site contains a large dataset and I want to create some extra Postgres indices to speed up certain queries (above and beyond what you can do with db_index
in the models file). I also need to create some materialised views.
I have SQL commands to do this, in a psql script.
My question is where to store these SQL commands so they're easy to run as part of the overall site setup (I want to make it easy to deploy and initialise the site).
Right now I just have a README saying "don't forget to run setup.psql after creating your database!!!" which isn't ideal.
When reading this article, I spotted that the author suggests putting index creation commands into a migration file, so they're run as as part of the initial python manage.py migrate
to set up the database.
Is this sensible? Are there any drawbacks?
Upvotes: 3
Views: 64
Reputation: 2022
Maybe you can use a post migrate signal to run your commands. I never used it but I used post syncdb signal in a previous project but it's deprecated now. In my case there where no drawbacks.
Upvotes: 0
Reputation: 1081
It is sensible, this is how I do it.
I don't see any drawbacks except maybe (since this is an existing project as I understand) if you run the new migration on a database which already has the indexes and views, this might crash your migration, so make sure to catch the exception.
Upvotes: 3