mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
update tablespace instances to check OPTIONS first
This commit is contained in:
parent
2b972ff07c
commit
5d5a4ce44b
@ -290,10 +290,19 @@ class BaseDatabaseSchemaEditor:
|
|||||||
if statement
|
if statement
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
if model._meta.db_tablespace:
|
db_tablespace = None
|
||||||
tablespace_sql = self.connection.ops.tablespace_sql(
|
if (
|
||||||
model._meta.db_tablespace
|
settings.DATABASES[self.connection.alias]
|
||||||
)
|
.get("OPTIONS", {})
|
||||||
|
.get("DEFAULT_TABLESPACE")
|
||||||
|
):
|
||||||
|
db_tablespace = settings.DATABASES[self.connection.alias]["OPTIONS"][
|
||||||
|
"DEFAULT_TABLESPACE"
|
||||||
|
]
|
||||||
|
elif model._meta.db_tablespace:
|
||||||
|
db_tablespace = model._meta.db_tablespace
|
||||||
|
if db_tablespace:
|
||||||
|
tablespace_sql = self.connection.ops.tablespace_sql(db_tablespace)
|
||||||
if tablespace_sql:
|
if tablespace_sql:
|
||||||
sql += " " + tablespace_sql
|
sql += " " + tablespace_sql
|
||||||
return sql, params
|
return sql, params
|
||||||
@ -359,7 +368,13 @@ class BaseDatabaseSchemaEditor:
|
|||||||
elif field.unique:
|
elif field.unique:
|
||||||
yield "UNIQUE"
|
yield "UNIQUE"
|
||||||
# Optionally add the tablespace if it's an implicitly indexed column.
|
# Optionally add the tablespace if it's an implicitly indexed column.
|
||||||
tablespace = field.db_tablespace or model._meta.db_tablespace
|
tablespace = (
|
||||||
|
field.db_tablespace
|
||||||
|
or settings.DATABASES[self.connection.alias]
|
||||||
|
.get("OPTIONS", {})
|
||||||
|
.get("DEFAULT_TABLESPACE")
|
||||||
|
or model._meta.db_tablespace
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
tablespace
|
tablespace
|
||||||
and self.connection.features.supports_tablespaces
|
and self.connection.features.supports_tablespaces
|
||||||
@ -1517,10 +1532,15 @@ class BaseDatabaseSchemaEditor:
|
|||||||
|
|
||||||
def _get_index_tablespace_sql(self, model, fields, db_tablespace=None):
|
def _get_index_tablespace_sql(self, model, fields, db_tablespace=None):
|
||||||
if db_tablespace is None:
|
if db_tablespace is None:
|
||||||
|
db_options = settings.DATABASES[self.connection.alias].get("OPTIONS", {})
|
||||||
if len(fields) == 1 and fields[0].db_tablespace:
|
if len(fields) == 1 and fields[0].db_tablespace:
|
||||||
db_tablespace = fields[0].db_tablespace
|
db_tablespace = fields[0].db_tablespace
|
||||||
|
elif db_options.get("DEFAULT_INDEX_TABLESPACE"):
|
||||||
|
db_tablespace = db_options["DEFAULT_INDEX_TABLESPACE"]
|
||||||
elif settings.DEFAULT_INDEX_TABLESPACE:
|
elif settings.DEFAULT_INDEX_TABLESPACE:
|
||||||
db_tablespace = settings.DEFAULT_INDEX_TABLESPACE
|
db_tablespace = settings.DEFAULT_INDEX_TABLESPACE
|
||||||
|
elif db_options.get("DEFAULT_TABLESPACE"):
|
||||||
|
db_tablespace = db_options["DEFAULT_TABLESPACE"]
|
||||||
elif model._meta.db_tablespace:
|
elif model._meta.db_tablespace:
|
||||||
db_tablespace = model._meta.db_tablespace
|
db_tablespace = model._meta.db_tablespace
|
||||||
if db_tablespace is not None:
|
if db_tablespace is not None:
|
||||||
|
@ -922,7 +922,13 @@ class Field(RegisterLookupMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def db_tablespace(self):
|
def db_tablespace(self):
|
||||||
return self._db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
|
return (
|
||||||
|
self._db_tablespace
|
||||||
|
or settings.DATABASES[connection.alias]
|
||||||
|
.get("OPTIONS", {})
|
||||||
|
.get("DEFAULT_INDEX_TABLESPACE")
|
||||||
|
or settings.DEFAULT_INDEX_TABLESPACE
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def db_returning(self):
|
def db_returning(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user