summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoulder Sprinters <boulder-sprinters@djangoproject.com>2007-04-17 23:22:49 +0000
committerBoulder Sprinters <boulder-sprinters@djangoproject.com>2007-04-17 23:22:49 +0000
commite558b9aac4e935320c828416d6bb2aae3ed88f36 (patch)
tree4db6ae3f45b5351849afaf23df895e597b438f5b
parent99b7f9c1855f82d92fe686f246c4c1241fee1de1 (diff)
boulder-oracle-sprint: Fixes #4055: Added "tablespace" parameter to model metadata options to support specification of tablespaces, primarily for Oracle.
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5022 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/management.py12
-rw-r--r--django/db/backends/ado_mssql/base.py4
-rw-r--r--django/db/backends/dummy/base.py1
-rw-r--r--django/db/backends/mysql/base.py4
-rw-r--r--django/db/backends/oracle/base.py4
-rw-r--r--django/db/backends/postgresql/base.py4
-rw-r--r--django/db/backends/postgresql_psycopg2/base.py4
-rw-r--r--django/db/backends/sqlite3/base.py3
-rw-r--r--django/db/models/options.py7
9 files changed, 36 insertions, 7 deletions
diff --git a/django/core/management.py b/django/core/management.py
index 024ff72042..ecb8a4cd5e 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -210,7 +210,10 @@ def _get_sql_model_create(model, known_models=set()):
full_statement = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + style.SQL_TABLE(backend.quote_name(opts.db_table)) + ' (']
for i, line in enumerate(table_output): # Combine and add commas.
full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or ''))
- full_statement.append(');')
+ full_statement.append(')')
+ if opts.tablespace and backend.supports_tablespaces:
+ full_statement.append(backend.get_tablespace_sql() % backend.quote_name(opts.tablespace))
+ full_statement.append(';')
final_output.append('\n'.join(full_statement))
if opts.has_auto_field and hasattr(backend, 'get_autoinc_sql'):
@@ -282,7 +285,10 @@ def _get_many_to_many_sql_for_model(model):
(style.SQL_KEYWORD('UNIQUE'),
style.SQL_FIELD(backend.quote_name(f.m2m_column_name())),
style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name()))))
- table_output.append(');')
+ table_output.append(')')
+ if opts.tablespace and backend.supports_tablespaces:
+ table_output.append(backend.get_tablespace_sql() % opts.tablespace)
+ table_output.append(';')
final_output.append('\n'.join(table_output))
# Add any extra SQL needed to support auto-incrementing PKs
@@ -1355,7 +1361,7 @@ def load_data(fixture_labels, verbosity=1):
# Keep a count of the installed objects and fixtures
count = [0,0]
models = set()
-
+
humanize = lambda dirname: dirname and "'%s'" % dirname or 'absolute path'
# Get a cursor (even though we don't need one yet). This has
diff --git a/django/db/backends/ado_mssql/base.py b/django/db/backends/ado_mssql/base.py
index a1ee4e428d..8845f0f79b 100644
--- a/django/db/backends/ado_mssql/base.py
+++ b/django/db/backends/ado_mssql/base.py
@@ -94,6 +94,7 @@ autoindexes_primary_keys = False
needs_datetime_string_cast = True
needs_upper_for_iops = False
supports_constraints = True
+supports_tablespaces = True
uses_case_insensitive_names = False
def quote_name(name):
@@ -153,6 +154,9 @@ def get_max_name_length():
def get_start_transaction_sql():
return "BEGIN;"
+def get_tablespace_sql():
+ return "ON %s"
+
def get_autoinc_sql(table):
return None
diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py
index eb3c3867c2..ddcbd0d484 100644
--- a/django/db/backends/dummy/base.py
+++ b/django/db/backends/dummy/base.py
@@ -27,6 +27,7 @@ class DatabaseWrapper:
pass # close()
supports_constraints = False
+supports_tablespaces = False
quote_name = complain
dictfetchone = complain
dictfetchmany = complain
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index 3424366878..16aab54446 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -137,6 +137,7 @@ autoindexes_primary_keys = False
needs_datetime_string_cast = True # MySQLdb requires a typecast for dates
needs_upper_for_iops = False
supports_constraints = True
+supports_tablespaces = True
uses_case_insensitive_names = False
def quote_name(name):
@@ -200,6 +201,9 @@ def get_max_name_length():
def get_start_transaction_sql():
return "BEGIN;"
+def get_tablespace_sql():
+ return "TABLESPACE %s STORAGE DISK"
+
def get_autoinc_sql(table):
return None
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 771cd09e82..75005be369 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -72,6 +72,7 @@ autoindexes_primary_keys = True
needs_datetime_string_cast = False
needs_upper_for_iops = True
supports_constraints = True
+supports_tablespaces = True
uses_case_insensitive_names = True
class FormatStylePlaceholderCursor(Database.Cursor):
@@ -168,6 +169,9 @@ def get_max_name_length():
def get_start_transaction_sql():
return None
+def get_tablespace_sql():
+ return "TABLESPACE %s"
+
def get_autoinc_sql(table):
# To simulate auto-incrementing primary keys in Oracle, we have to
# create a sequence and a trigger.
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index 2f2363728f..741d3a3c8c 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -110,6 +110,7 @@ autoindexes_primary_keys = False
needs_datetime_string_cast = True
needs_upper_for_iops = False
supports_constraints = True
+supports_tablespaces = True
uses_case_insensitive_names = False
def quote_name(name):
@@ -173,6 +174,9 @@ def get_max_name_length():
def get_start_transaction_sql():
return "BEGIN;"
+def get_tablespace_sql():
+ return "TABLESPACE %s"
+
def get_autoinc_sql(table):
return None
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index 1a149f42a7..22fcfeac67 100644
--- a/django/db/backends/postgresql_psycopg2/base.py
+++ b/django/db/backends/postgresql_psycopg2/base.py
@@ -78,6 +78,7 @@ autoindexes_primary_keys = False
needs_datetime_string_cast = False
needs_upper_for_iops = False
supports_constraints = True
+supports_tablespaces = True
uses_case_insensitive_names = True
def quote_name(name):
@@ -133,6 +134,9 @@ def get_max_name_length():
def get_start_transaction_sql():
return "BEGIN;"
+def get_tablespace_sql():
+ return "TABLESPACE %s"
+
def get_autoinc_sql(table):
return None
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index d518a83585..bd829f23a1 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -105,6 +105,7 @@ autoindexes_primary_keys = False
needs_datetime_string_cast = True
needs_upper_for_iops = False
supports_constraints = False
+supports_tablespaces = False
uses_case_insensitive_names = False
def quote_name(name):
@@ -192,7 +193,7 @@ def get_sql_sequence_reset(style, model_list):
"Returns a list of the SQL statements to reset sequences for the given models."
# No sequence reset required
return []
-
+
def _sqlite_date_trunc(lookup_type, dt):
try:
dt = util.typecast_timestamp(dt)
diff --git a/django/db/models/options.py b/django/db/models/options.py
index e2c896a668..79f22384dc 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -13,7 +13,7 @@ get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|
DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
'unique_together', 'permissions', 'get_latest_by',
- 'order_with_respect_to', 'app_label')
+ 'order_with_respect_to', 'app_label', 'tablespace')
class Options(object):
def __init__(self, meta):
@@ -27,6 +27,7 @@ class Options(object):
self.object_name, self.app_label = None, None
self.get_latest_by = None
self.order_with_respect_to = None
+ self.tablespace = None
self.admin = None
self.meta = meta
self.pk = None
@@ -92,10 +93,10 @@ class Options(object):
def __repr__(self):
return '<Options for %s>' % self.object_name
-
+
def __str__(self):
return "%s.%s" % (self.app_label, self.module_name)
-
+
def get_field(self, name, many_to_many=True):
"Returns the requested field by name. Raises FieldDoesNotExist on error."
to_search = many_to_many and (self.fields + self.many_to_many) or self.fields