Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
4043dc69
Kaydet (Commit)
4043dc69
authored
May 05, 2019
tarafından
Rob Golding-Day
Kaydeden (comit)
Mariusz Felisiak
May 07, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #30444 -- Moved SQL generation for tables to BaseDatabaseSchemaEditor.table_sql().
üst
0e2ed4fd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
54 deletions
+59
-54
AUTHORS
AUTHORS
+1
-0
schema.py
django/db/backends/base/schema.py
+58
-54
No files found.
AUTHORS
Dosyayı görüntüle @
4043dc69
...
...
@@ -740,6 +740,7 @@ answer newbie questions, and generally made Django that much better:
Roberto Aguilar <roberto@baremetal.io>
Robert Rock Howard <http://djangomojo.com/>
Robert Wittams
Rob Golding-Day <rob@golding-day.com>
Rob Hudson <https://rob.cogit8.org/>
Robin Munn <http://www.geekforgod.com/>
Rodrigo Pinheiro Marques de Araújo <fenrrir@gmail.com>
...
...
django/db/backends/base/schema.py
Dosyayı görüntüle @
4043dc69
...
...
@@ -140,6 +140,63 @@ class BaseDatabaseSchemaEditor:
def
quote_name
(
self
,
name
):
return
self
.
connection
.
ops
.
quote_name
(
name
)
def
table_sql
(
self
,
model
):
"""Take a model and return its table definition."""
# Add any unique_togethers (always deferred, as some fields might be
# created afterwards, like geometry fields with some backends).
for
fields
in
model
.
_meta
.
unique_together
:
columns
=
[
model
.
_meta
.
get_field
(
field
)
.
column
for
field
in
fields
]
self
.
deferred_sql
.
append
(
self
.
_create_unique_sql
(
model
,
columns
))
# Create column SQL, add FK deferreds if needed.
column_sqls
=
[]
params
=
[]
for
field
in
model
.
_meta
.
local_fields
:
# SQL.
definition
,
extra_params
=
self
.
column_sql
(
model
,
field
)
if
definition
is
None
:
continue
# Check constraints can go on the column SQL here.
db_params
=
field
.
db_parameters
(
connection
=
self
.
connection
)
if
db_params
[
'check'
]:
definition
+=
' '
+
self
.
sql_check_constraint
%
db_params
# Autoincrement SQL (for backends with inline variant).
col_type_suffix
=
field
.
db_type_suffix
(
connection
=
self
.
connection
)
if
col_type_suffix
:
definition
+=
'
%
s'
%
col_type_suffix
params
.
extend
(
extra_params
)
# FK.
if
field
.
remote_field
and
field
.
db_constraint
:
to_table
=
field
.
remote_field
.
model
.
_meta
.
db_table
to_column
=
field
.
remote_field
.
model
.
_meta
.
get_field
(
field
.
remote_field
.
field_name
)
.
column
if
self
.
sql_create_inline_fk
:
definition
+=
' '
+
self
.
sql_create_inline_fk
%
{
'to_table'
:
self
.
quote_name
(
to_table
),
'to_column'
:
self
.
quote_name
(
to_column
),
}
elif
self
.
connection
.
features
.
supports_foreign_keys
:
self
.
deferred_sql
.
append
(
self
.
_create_fk_sql
(
model
,
field
,
'_fk_
%(to_table)
s_
%(to_column)
s'
))
# Add the SQL to our big list.
column_sqls
.
append
(
'
%
s
%
s'
%
(
self
.
quote_name
(
field
.
column
),
definition
,
))
# Autoincrement SQL (for backends with post table definition
# variant).
if
field
.
get_internal_type
()
in
(
'AutoField'
,
'BigAutoField'
):
autoinc_sql
=
self
.
connection
.
ops
.
autoinc_sql
(
model
.
_meta
.
db_table
,
field
.
column
)
if
autoinc_sql
:
self
.
deferred_sql
.
extend
(
autoinc_sql
)
constraints
=
[
constraint
.
constraint_sql
(
model
,
self
)
for
constraint
in
model
.
_meta
.
constraints
]
sql
=
self
.
sql_create_table
%
{
'table'
:
self
.
quote_name
(
model
.
_meta
.
db_table
),
'definition'
:
', '
.
join
(
constraint
for
constraint
in
(
*
column_sqls
,
*
constraints
)
if
constraint
),
}
if
model
.
_meta
.
db_tablespace
:
tablespace_sql
=
self
.
connection
.
ops
.
tablespace_sql
(
model
.
_meta
.
db_tablespace
)
if
tablespace_sql
:
sql
+=
' '
+
tablespace_sql
return
sql
,
params
# Field <-> database mapping functions
def
column_sql
(
self
,
model
,
field
,
include_default
=
False
):
...
...
@@ -250,60 +307,7 @@ class BaseDatabaseSchemaEditor:
Create a table and any accompanying indexes or unique constraints for
the given `model`.
"""
# Create column SQL, add FK deferreds if needed
column_sqls
=
[]
params
=
[]
for
field
in
model
.
_meta
.
local_fields
:
# SQL
definition
,
extra_params
=
self
.
column_sql
(
model
,
field
)
if
definition
is
None
:
continue
# Check constraints can go on the column SQL here
db_params
=
field
.
db_parameters
(
connection
=
self
.
connection
)
if
db_params
[
'check'
]:
definition
+=
" "
+
self
.
sql_check_constraint
%
db_params
# Autoincrement SQL (for backends with inline variant)
col_type_suffix
=
field
.
db_type_suffix
(
connection
=
self
.
connection
)
if
col_type_suffix
:
definition
+=
"
%
s"
%
col_type_suffix
params
.
extend
(
extra_params
)
# FK
if
field
.
remote_field
and
field
.
db_constraint
:
to_table
=
field
.
remote_field
.
model
.
_meta
.
db_table
to_column
=
field
.
remote_field
.
model
.
_meta
.
get_field
(
field
.
remote_field
.
field_name
)
.
column
if
self
.
sql_create_inline_fk
:
definition
+=
" "
+
self
.
sql_create_inline_fk
%
{
"to_table"
:
self
.
quote_name
(
to_table
),
"to_column"
:
self
.
quote_name
(
to_column
),
}
elif
self
.
connection
.
features
.
supports_foreign_keys
:
self
.
deferred_sql
.
append
(
self
.
_create_fk_sql
(
model
,
field
,
"_fk_
%(to_table)
s_
%(to_column)
s"
))
# Add the SQL to our big list
column_sqls
.
append
(
"
%
s
%
s"
%
(
self
.
quote_name
(
field
.
column
),
definition
,
))
# Autoincrement SQL (for backends with post table definition variant)
if
field
.
get_internal_type
()
in
(
"AutoField"
,
"BigAutoField"
):
autoinc_sql
=
self
.
connection
.
ops
.
autoinc_sql
(
model
.
_meta
.
db_table
,
field
.
column
)
if
autoinc_sql
:
self
.
deferred_sql
.
extend
(
autoinc_sql
)
# Add any unique_togethers (always deferred, as some fields might be
# created afterwards, like geometry fields with some backends)
for
fields
in
model
.
_meta
.
unique_together
:
columns
=
[
model
.
_meta
.
get_field
(
field
)
.
column
for
field
in
fields
]
self
.
deferred_sql
.
append
(
self
.
_create_unique_sql
(
model
,
columns
))
constraints
=
[
constraint
.
constraint_sql
(
model
,
self
)
for
constraint
in
model
.
_meta
.
constraints
]
# Make the table
sql
=
self
.
sql_create_table
%
{
"table"
:
self
.
quote_name
(
model
.
_meta
.
db_table
),
"definition"
:
", "
.
join
(
constraint
for
constraint
in
(
*
column_sqls
,
*
constraints
)
if
constraint
),
}
if
model
.
_meta
.
db_tablespace
:
tablespace_sql
=
self
.
connection
.
ops
.
tablespace_sql
(
model
.
_meta
.
db_tablespace
)
if
tablespace_sql
:
sql
+=
' '
+
tablespace_sql
sql
,
params
=
self
.
table_sql
(
model
)
# Prevent using [] as params, in the case a literal '%' is used in the definition
self
.
execute
(
sql
,
params
or
None
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment