summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/operations.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-04-17 10:44:27 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-17 10:46:19 +0200
commit8005829bb9d9e0a14d73c9375bb55eb05daa46e1 (patch)
tree2c1bd56b5a885b0332bd0c65889bd8bf1d4f5b22 /django/db/backends/postgresql/operations.py
parent8bcca47e8356521f52f0738d9633befd53007cae (diff)
Simplified DatabaseOperations.sql_flush() on Oracle and PostgreSQL.
Added early return to decrease an indentation level.
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r--django/db/backends/postgresql/operations.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index ec87b61f49..dd422af1af 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -118,28 +118,28 @@ class DatabaseOperations(BaseDatabaseOperations):
return "SET TIME ZONE %s"
def sql_flush(self, style, tables, sequences, allow_cascade=False):
- if tables:
- # Perform a single SQL 'TRUNCATE x, y, z...;' statement. It allows
- # us to truncate tables referenced by a foreign key in any other
- # table.
- tables_sql = ', '.join(
- style.SQL_FIELD(self.quote_name(table)) for table in tables)
- if allow_cascade:
- sql = ['%s %s %s;' % (
- style.SQL_KEYWORD('TRUNCATE'),
- tables_sql,
- style.SQL_KEYWORD('CASCADE'),
- )]
- else:
- sql = ['%s %s;' % (
- style.SQL_KEYWORD('TRUNCATE'),
- tables_sql,
- )]
- sql.extend(self.sequence_reset_by_name_sql(style, sequences))
- return sql
- else:
+ if not tables:
return []
+ # Perform a single SQL 'TRUNCATE x, y, z...;' statement. It allows us
+ # to truncate tables referenced by a foreign key in any other table.
+ tables_sql = ', '.join(
+ style.SQL_FIELD(self.quote_name(table)) for table in tables
+ )
+ if allow_cascade:
+ sql = ['%s %s %s;' % (
+ style.SQL_KEYWORD('TRUNCATE'),
+ tables_sql,
+ style.SQL_KEYWORD('CASCADE'),
+ )]
+ else:
+ sql = ['%s %s;' % (
+ style.SQL_KEYWORD('TRUNCATE'),
+ tables_sql,
+ )]
+ sql.extend(self.sequence_reset_by_name_sql(style, sequences))
+ return sql
+
def sequence_reset_by_name_sql(self, style, sequences):
# 'ALTER SEQUENCE sequence_name RESTART WITH 1;'... style SQL statements
# to reset sequence indices