Hi Annsi

Yes, the AddIndex operation would detect the changes and the user would not 
have full control over the generated SQL.

I don't know if it would be a good idea to mix index definitions with 
fields while creating models. Users have traditionally been defining fields 
that way and indexes feel more like a "Meta" property to me. Constraints 
can also be added to Meta (maybe merged together with indexes) whenever 
they arrive, but I don't how soon they will be included.

Regards
Akshesh Doshi
(akki)

On Monday, 14 March 2016 12:53:30 UTC+5:30, Anssi Kääriäinen wrote:
>
> On Thu, Mar 10, 2016 at 8:17 AM, Markus Holtermann 
> <in...@markusholtermann.eu <javascript:>> wrote: 
> > Hi Akshesh, 
> > 
> > thank you for your proposal! Sounds like a good plan. 
> > 
> > On Thursday, March 10, 2016 at 8:16:10 AM UTC+11, akki wrote: 
> > 
> >>> Once the index is added to a model, the model can inject itself into 
> the 
> >>> index, or the schema editor can use the originating model to get data 
> it 
> >>> needs. No need to pass the model into the index type I think. 
> Regarding the 
> >>> name, I'm unsure if I prefer a name=Index() or an Index(name='') 
> approach. 
> >>> It'd be good to see that choice in your proposal with a couple of pros 
> and 
> >>> cons. 
> >> 
> >> 
> >> Well, since we are defining these indexes in a list (to be stored in 
> >> Meta.indexes) I would go with the Index(name='') approach. 
> > 
> > 
> > I'd prefer the Index(name='') approach 
> > 
> > class MyModel(models.Model): 
> >     field1 = models.CharField() 
> >     field2 = models.CharField() 
> > 
> >     class Meta: 
> >         indexes = [ 
> >             Index('field1', 'field2', 
> name='some_index_across_two_columns'), 
> >             'field2',  # Would be the same as Index('field2'), an index 
> on 
> > this one column -- name derived from field name: field2_index 
> >             Index(ToLower('field1')),  # A functional index on field1 -- 
> > name derived from field name and functions: field1_tolower_index 
> >         ] 
> > 
> > That way you should also be able to check for duplicate index names. 
>
> How about 
>
> class MyModel(models.Model): 
>     field1 = models.CharField() 
>     field2 = models.CharField() 
>
>     field1_idx = models.Index('field1') 
>     field2_lower_idx = models.Index(ToLower('field2')) 
>
> The main advantage is that the same syntax can be used for custom 
> indexes, constraints, composite fields and so on. Internally we could 
> of course have the same representation for indexes as before. 
>
>  - Anssi 
>

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/f07f1303-fd25-43b9-b50f-353da0c69ad3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • P... akki
    • ... Josh Smeaton
      • ... Anssi Kääriäinen
        • ... akki
          • ... Markus Holtermann
          • ... Anssi Kääriäinen
            • ... 'Moritz Sichert' via Django developers (Contributions to Django itself)

Reply via email to