[Django] #29026: Make makemigrations scriptable / script-friendly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #29026: Make makemigrations scriptable / script-friendly

Django
#29026: Make makemigrations scriptable / script-friendly
-------------------------------------+-------------------------------------
               Reporter:  Chris      |          Owner:  nobody
  Jerdonek                           |
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:             |        Version:  master
  Migrations                         |       Keywords:
               Severity:  Normal     |  makemigrations,scripting,stderr,stdout
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Currently, the `makemigrations` management command doesn't lend itself
 well to scripting. For example, it writes its progress output to `stdout`
 rather than `stderr`. Also, there doesn't appear to be a structured /
 programmatic way to figure out what files it has created.

 My use case is that in my development environment, I'd like to be able to
 run `makemigrations` in a Docker container, find out what files were added
 (e.g. from `makemigrations`'s output), and then copy those files from the
 Docker container to my development machine so they can be added to source
 control.

 Currently, there doesn't seem to be an easy way to do this. One way, for
 example, is to manually read `makemigrations`'s output to find out what
 apps were affected, and then inspect the directories yourself for the new
 files.

 Better, for example, would be if `makemigrations` could write the paths to
 the created files to `stdout`.

--
Ticket URL: <https://code.djangoproject.com/ticket/29026>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.854774bf5383e3c1dd0a7d27292f61f2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29026: Make makemigrations scriptable / script-friendly

Django
#29026: Make makemigrations scriptable / script-friendly
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  makemigrations,scripting,stderr,stdout|  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by astandley):

 The current makemigrations command would seem to allow for everything you
 have asked.

 {{{
 >> python -m manage makemigrations
 Migrations for 'newspaper':
   newspaper\migrations\0001_initial.py
     - Create model People
 >> python -m manage makemigrations
 Migrations for 'newspaper':
   newspaper\migrations\0001_initial.py
     - Create model People
 }}}

 Addressing each point:

     Output written to stdout rather than stderr.
 You can redirect stdout to stderr for the execution of the command if you
 want the output in stderr. (Using sys in python, or pipes for a shell
 script)

     A structured / programmatic way to figure out what files it has
 created.
 Run a regex on the output of the migration command. Example pattern:
 {{{r'Migrations for '(?P<app_name>[^']*)':\n
 (?P<migration_file>[^\n]*)'}}}

 Is there a reason this would not meet your needs?

--
Ticket URL: <https://code.djangoproject.com/ticket/29026#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.cc7841be03105725c4ec8a5234627a34%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29026: Make makemigrations scriptable / script-friendly

Django
In reply to this post by Django
#29026: Make makemigrations scriptable / script-friendly
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  makemigrations,scripting,stderr,stdout|  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

 I don't consider parsing log output with regexes to be structured output
 or a programmatic API. That seems brittle and unnecessarily complicated,
 and also would be hard for Django to make backwards compatibility
 guarantees about.

 What I had in mind was something like log output going to stderr, and the
 paths of the created files going to stdout -- one per line. If something
 fancier was needed, json could be outputted. With something like that,
 there wouldn't be any need for regex parsing and the API would be well-
 defined.

--
Ticket URL: <https://code.djangoproject.com/ticket/29026#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.533b86c5df809183575516cd518126b0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29026: Make makemigrations scriptable / script-friendly

Django
In reply to this post by Django
#29026: Make makemigrations scriptable / script-friendly
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  makemigrations,scripting,stderr,stdout|  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

 It seems complicated. For example, what if `makemigrations` requires
 interactive input from the questioner?

--
Ticket URL: <https://code.djangoproject.com/ticket/29026#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.d2d6e0ae0bb7e2961f289d1401d26dae%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29026: Make makemigrations scriptable / script-friendly

Django
In reply to this post by Django
#29026: Make makemigrations scriptable / script-friendly
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  makemigrations,scripting,stderr,stdout|  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

 My original use case was a non-interactive one (inside a container). But
 again, you raise a good point. Obviously, piping to `stdout` won't work if
 interactivity is required (because you'd want user prompts to go to
 `stdout`). This is true of any script, not just Django management
 commands. Other than that, I don't think the changes I've described would
 ''hurt'' things in that case, aside from possibly the "reliability" issue
 you mentioned [https://code.djangoproject.com/ticket/29040#comment:3
 here]. That though could be addressed by my
 [https://code.djangoproject.com/ticket/29040#comment:4 follow-up comment]
 to yours. If we wanted a fancier solution, the "structured" `stdout` could
 be outputted only in non-interactive mode.

--
Ticket URL: <https://code.djangoproject.com/ticket/29026#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.e89350eef731c0a0b1b643ce06dac57e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29026: Make makemigrations scriptable / script-friendly

Django
In reply to this post by Django
#29026: Make makemigrations scriptable / script-friendly
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
  makemigrations,scripting,stderr,stdout|
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * stage:  Unreviewed => Accepted


Comment:

 I'm skeptical, but I guess if you have a patch to propose, we can evaluate
 it.

--
Ticket URL: <https://code.djangoproject.com/ticket/29026#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.a74c4a89946423af6dc5ae5aecd6775f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.