top | item 29837205

(no title)

cessor | 4 years ago

Your're right, I felt the same way in that the article is clickbaity.

I found that django's naming scheme for migrations is good enough; here are some real ones that I pulled out of my current project:

    migrations/0006_add_modeltranslation.py
    migrations/0007_remove_temp_fields.py
    migrations/0008_remove_language_field.py
    migrations/0009_alter_page_slug.py
    migrations/0010_alter_menuitem_absolute_url.py
While they aren't semantically rich ('Why did you change absolute url on menu item?') I found that they are easy to distinguish and navigate.

discuss

order

yxhuvud|4 years ago

My biggest objection to that naming scheme would be the numbering. If you have multiple people working on an app, it is likely that you at some point get multiples of a number as people add models simultaneously. What happens if there are multiples using a single number?

I much prefer the timestamp based system that is used by Rails, it make the risk of that kind of conflict a lot lower.

Wilya|4 years ago

The number-based scheme is a leftover from old times. I don't think they are actually used for ordering how the migrations are applied anymore.

The migration file will contain explicit dependency information, something like:

  dependencies = [
    ('app', '0010_alter_menuitem_absolute_url')
  ]
The migration engine will order the dependencies at runtime, and it will bail (and suggest creating a "merge" migration) if you have diverging trees of migrations. I find it pretty robust in practice.

tzot|4 years ago

> My biggest objection to that naming scheme would be the numbering. If you have multiple people working on an app, it is likely that you at some point get multiples of a number as people add models simultaneously. What happens if there are multiples using a single number?

We have this happen at work, when merging branches; this is what `./manage.py makemigrations --merge` exists for.

Klonoar|4 years ago

The only thing that annoys me to this day is that they have the numbers first. I get the logic why: it means they're ordered in the directory properly.

That said, it's very annoying in that they're not tab-completable... any time I have to edit one, I have to stop and hunt in the entire list for what I'm looking for.

jmconfuzeus|4 years ago

You pulled only the good ones. Where are the migrations named 0019_auto_20181224.py?

MattGaiser|4 years ago

"Why" is something very hard to programmically answer.