#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 1 import sqlparse 2 1 3 from django.apps import apps 2 4 from django.core.management.base import BaseCommand, CommandError 3 5 from django.db import DEFAULT_DB_ALIAS, connections … … class Command(BaseCommand): 80 82 sql_statements = loader.collect_sql(plan) 81 83 if not sql_statements and options["verbosity"] >= 1: 82 84 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)
follow-up: 3 comment:1 by , 15 months ago
comment:2 by , 15 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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!
comment:3 by , 15 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 , 15 months ago
Did you mean that sqlmigrate's formatting is subpar, or that sqlparse's is?
oops! I meant sqlparse :)
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 🤷♂️