Can you provide the operations that users can then import into their 
migrations, similarly to how contrib.postgres provides the HStoreExtension 
operation [0]? The import could even be a function taking the extended 
model that returns the appropriate operation. This might be a bit more 
lo-fi than hooking the pre-migrate signal, and require users to do the 
right thing, but it sounds better than copy/pasting templates.

[0] 
https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/operations/#creating-extension-using-migrations

On Wednesday, 7 June 2017 06:45:05 UTC+10, Craig de Stigter wrote:
>
> Hi there
>
> I'm in the early stages of developing a third party app which makes heavy 
> use of postgres extensions. The app provides an abstract model, so I won't 
> have direct control of user's models or migrations. I'm having trouble 
> getting it to generate sensible migrations for users.
>
> At present the migration process for users is going to be "copy and paste 
> my migration file template into your project, and change the model names to 
> match your app". As far as I can tell there is no way to generate 
> migrations with anything custom.
>
> The operations I need to generate are:
>
>    - CreateExtension()
>    - RunSQL() - (to create slightly non-standard constraints)
>
> e.g. perhaps my model could supply a couple of methods:
>
>    - Model.Meta.pre_creation_operations() - returns a list of operations 
>    to apply before the auto-detected model operations, e.g. creating 
>    extensions etc
>    - Model.Meta.post_creation_operations() - the same but applied after 
>    the auto-detected operations, e.g. adding constraints/indexes.
>
> I'm envisaging that the operations returned from both methods would be 
> deconstructed and copied into migration files when makemigrations is run.
>
> Has there been any discussion about this previously? I haven't found any.
>
> Thanks
> Craig de Stigter
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/138eeec1-5719-4295-8161-85b04ea2e6e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to