1
0
mirror of https://github.com/django/django.git synced 2025-04-05 05:56:42 +00:00

update tablespace instances to check OPTIONS first

This commit is contained in:
Ben Cail 2024-02-15 14:13:09 -05:00
parent 2b972ff07c
commit 5d5a4ce44b
2 changed files with 32 additions and 6 deletions

View File

@ -290,10 +290,19 @@ class BaseDatabaseSchemaEditor:
if statement
),
}
if model._meta.db_tablespace:
tablespace_sql = self.connection.ops.tablespace_sql(
model._meta.db_tablespace
)
db_tablespace = None
if (
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:
sql += " " + tablespace_sql
return sql, params
@ -359,7 +368,13 @@ class BaseDatabaseSchemaEditor:
elif field.unique:
yield "UNIQUE"
# 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 (
tablespace
and self.connection.features.supports_tablespaces
@ -1517,10 +1532,15 @@ class BaseDatabaseSchemaEditor:
def _get_index_tablespace_sql(self, model, fields, db_tablespace=None):
if db_tablespace is None:
db_options = settings.DATABASES[self.connection.alias].get("OPTIONS", {})
if len(fields) == 1 and 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:
db_tablespace = settings.DEFAULT_INDEX_TABLESPACE
elif db_options.get("DEFAULT_TABLESPACE"):
db_tablespace = db_options["DEFAULT_TABLESPACE"]
elif model._meta.db_tablespace:
db_tablespace = model._meta.db_tablespace
if db_tablespace is not None:

View File

@ -922,7 +922,13 @@ class Field(RegisterLookupMixin):
@property
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
def db_returning(self):