Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#34859 closed New feature (wontfix)

Format SQL code prodcued by sqlmigrate

Reported by: Paolo Melchiorre Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords: sql, sqlmigrate, migrations
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I propose to use sqlparse, which is already a Django dependency, to format the SQL code generated by the sqlmigrate command.

  • django/core/management/commands/sqlmigrate.py

    diff --git a/django/core/management/commands/sqlmigrate.py b/django/core/management/commands/sqlmigrate.py
    index 2f6993682f..158bcf722b 100644
    a b  
     1import sqlparse
     2
    13from django.apps import apps
    24from django.core.management.base import BaseCommand, CommandError
    35from django.db import DEFAULT_DB_ALIAS, connections
    class Command(BaseCommand):  
    8082        sql_statements = loader.collect_sql(plan)
    8183        if not sql_statements and options["verbosity"] >= 1:
    8284            self.stderr.write("No operations found.")
    83         return "\n".join(sql_statements)
     85        return sqlparse.format("\n".join(sql_statements), reindent=True)

Change History (4)

comment:1 by David Sanders, 14 months ago

Personally I'm not sure it's worth formatting… it's kinda nice to have the current format have 1 line per ddl statement. Additionally in my experience sqlmigrate's formatting of ddl is lack lustre 🤷‍♂️

comment:2 by Natalia Bidart, 14 months ago

Resolution: wontfix
Status: newclosed

Thanks Paolo for your ticket!

I personally think that if we were to do this, it should be via a dedicated CLI switch, I wouldn't change the default formatting because there may be tools that parse this output and assume one command per line.

Having said that, I would suggest/like that this feature request is proposed in the Django forum to reach a wider audience, Trac notifications are receive by a small subset of people from the community.

Following the triage procedure, I'll close as wontfix pending the conversation in the forum, happy to re-open later!

in reply to:  1 comment:3 by Natalia Bidart, 14 months ago

Replying to David Sanders:

Personally I'm not sure it's worth formatting… it's kinda nice to have the current format have 1 line per ddl statement. Additionally in my experience sqlmigrate's formatting of ddl is lack lustre 🤷‍♂️

Did you mean that sqlmigrate's formatting is subpar, or that sqlparse's is?

comment:4 by David Sanders, 14 months ago

Did you mean that sqlmigrate's formatting is subpar, or that sqlparse's is?

oops! I meant sqlparse :)

Note: See TracTickets for help on using tickets.
Back to Top