Ticket #6148: generic-db_schema-r8308.diff
File generic-db_schema-r8308.diff, 7.3 KB (added by , 16 years ago) |
---|
-
django/core/management/commands/syncdb.py
61 61 app_name = app.__name__.split('.')[-2] 62 62 model_list = models.get_models(app) 63 63 for model in model_list: 64 # Add model defined schema tables if anny 65 if connection.features.supports_schemas and model._meta.db_schema: 66 tables += connection.introspection.schema_table_names(model._meta.db_schema) 64 67 # Create the model's database table, if it doesn't already exist. 65 68 if verbosity >= 2: 66 69 print "Processing %s.%s model" % (app_name, model._meta.object_name) -
django/core/management/sql.py
72 72 73 73 # Figure out which tables already exist 74 74 if cursor: 75 table_names = connection.introspection.get_table_list(cursor) 75 table_names = connection.introspection.get_table_list(cursor) 76 76 else: 77 77 table_names = [] 78 78 … … 84 84 references_to_delete = {} 85 85 app_models = models.get_models(app) 86 86 for model in app_models: 87 # Find aditional tables in model defined schemas 88 if connection.features.supports_schemas and model._meta.db_schema: 89 table_names += connection.introspection.get_schema_table_list(cursor, model._meta.db_schema) 87 90 if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names: 88 91 # The table exists, so it needs to be dropped 89 92 opts = model._meta -
django/db/backends/__init__.py
55 55 update_can_self_select = True 56 56 interprets_empty_strings_as_nulls = False 57 57 can_use_chunked_reads = True 58 supports_schemas = False 58 59 59 60 class BaseDatabaseOperations(object): 60 61 """ … … 345 346 "Returns a list of names of all tables that exist in the database." 346 347 cursor = self.connection.cursor() 347 348 return self.get_table_list(cursor) 349 350 def schema_table_names(self, schema): 351 "Returns a list of names of all tables that exist in the database schema." 352 if self.connection.features.supports_schemas: 353 cursor = self.connection.cursor() 354 return self.get_schema_table_list(cursor, schema) 355 else: 356 return [] 348 357 349 358 def django_table_names(self, only_existing=False): 350 359 """ -
django/db/backends/creation.py
243 243 tablespace_sql = '' 244 244 else: 245 245 tablespace_sql = '' 246 # Use original db_table in index name if schema is provided 247 if self.connection.features.supports_schemas and model._meta.db_schema: 248 index_table_name = model._meta._db_table 249 else: 250 index_table_name = model._meta.db_table 251 246 252 output = [style.SQL_KEYWORD('CREATE INDEX') + ' ' + 247 style.SQL_TABLE(qn('%s_%s' % ( model._meta.db_table, f.column))) + ' ' +253 style.SQL_TABLE(qn('%s_%s' % (index_table_name, f.column))) + ' ' + 248 254 style.SQL_KEYWORD('ON') + ' ' + 249 255 style.SQL_TABLE(qn(model._meta.db_table)) + ' ' + 250 256 "(%s)" % style.SQL_FIELD(qn(f.column)) + -
django/db/backends/mysql/base.py
67 67 class DatabaseFeatures(BaseDatabaseFeatures): 68 68 empty_fetchmany_value = () 69 69 update_can_self_select = False 70 supports_schemas = True 70 71 71 72 class DatabaseOperations(BaseDatabaseOperations): 72 73 def date_extract_sql(self, lookup_type, field_name): … … 99 100 def quote_name(self, name): 100 101 if name.startswith("`") and name.endswith("`"): 101 102 return name # Quoting once is enough. 102 return "`%s`" % name 103 # add support for tablenames passed that also have their schema in their name 104 return "`%s`" % name.replace('.','`.`') 103 105 104 106 def random_function_sql(self): 105 107 return 'RAND()' -
django/db/backends/mysql/introspection.py
31 31 "Returns a list of table names in the current database." 32 32 cursor.execute("SHOW TABLES") 33 33 return [row[0] for row in cursor.fetchall()] 34 35 def get_schema_table_list(self, cursor, schema): 36 cursor.execute("SHOW TABLES FROM %s" % self.connection.ops.quote_name(schema)) 37 return [schema + "." + row[0] for row in cursor.fetchall()] 34 38 35 39 def get_table_description(self, cursor, table_name): 36 40 "Returns a description of the table, with the DB-API cursor.description interface." -
django/db/models/options.py
21 21 DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering', 22 22 'unique_together', 'permissions', 'get_latest_by', 23 23 'order_with_respect_to', 'app_label', 'db_tablespace', 24 'abstract' )24 'abstract', 'db_schema') 25 25 26 26 class Options(object): 27 27 def __init__(self, meta, app_label=None): … … 29 29 self.module_name, self.verbose_name = None, None 30 30 self.verbose_name_plural = None 31 31 self.db_table = '' 32 self.db_schema = '' 32 33 self.ordering = [] 33 34 self.unique_together = [] 34 35 self.permissions = [] … … 89 90 else: 90 91 self.verbose_name_plural = string_concat(self.verbose_name, 's') 91 92 del self.meta 93 94 92 95 93 96 # If the db_table wasn't provided, use the app_label + module_name. 94 97 if not self.db_table: 95 self.db_table = "%s_%s" % (self.app_label, self.module_name) 98 self.db_table = "%s_%s" % (self.app_label, self.module_name) 96 99 self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) 97 98 100 101 # Patch db_table with the schema if provided and allowed 102 if self.db_schema and connection.features.supports_schemas: 103 # Store original db_table in a save place first 104 self._db_table = self.db_table 105 self.db_table = "%s.%s" % (self.db_schema, self.db_table) 106 107 99 108 def _prepare(self, model): 100 109 if self.order_with_respect_to: 101 110 self.order_with_respect_to = self.get_field(self.order_with_respect_to)