Ticket #6148: generic-db_schema-update.patch

File generic-db_schema-update.patch, 6.2 KB (added by oldium, 6 years ago)

Incremental patch that fixes CREATE INDEX problems, some quotations and supports new global settings.DATABASE_SCHEMA

  • django/conf/global_settings.py

    diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
    index 99fc72e..0143770 100644
    a b DATABASE_PASSWORD = '' # Not used with sqlite3. 
    130130DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
    131131DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
    132132DATABASE_OPTIONS = {}          # Set to empty dictionary for default.
     133DATABASE_SCHEMA = ''           # Set to empty string for default.
    133134
    134135# Host for sending e-mail.
    135136EMAIL_HOST = 'localhost'
  • django/conf/project_template/settings.py

    diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py
    index bbf005d..bb4564e 100644
    a b DATABASE_USER = '' # Not used with sqlite3. 
    1515DATABASE_PASSWORD = ''         # Not used with sqlite3.
    1616DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
    1717DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
     18DATABASE_SCHEMA = ''           # Set to empty string for default.
    1819
    1920# Local time zone for this installation. Choices can be found here:
    2021# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index 0a9ec1e..48d21eb 100644
    a b class BaseDatabaseOperations(object): 
    290290    def prep_db_table(self, db_schema, db_table):
    291291        """
    292292        Prepares and formats the table name if necessary.
    293         Just returns the db_table if not supported.
     293        Just returns quoted db_table if not supported.
    294294        """
    295         return db_table
     295        return self.quote_name(db_table)
     296
     297    def prep_db_index(self, db_schema, db_index):
     298        """
     299        Prepares and formats the table index name if necessary.
     300        Just returns quoted db_index if not supported.
     301        """
     302        return self.quote_name(db_index)
    296303
    297304    def random_function_sql(self):
    298305        """
  • django/db/backends/creation.py

    diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
    index 828889c..a7ab6fd 100644
    a b class BaseDatabaseCreation(object): 
    274274            else:
    275275                tablespace_sql = ''
    276276            index_name = '%s_%s' % (model._meta.db_table, f.column)
    277             index_name = self.connection.ops.prep_db_table(model._meta.db_schema, index_name)
     277            index_name = self.connection.ops.prep_db_index(model._meta.db_schema, index_name)
    278278            output = [style.SQL_KEYWORD('CREATE INDEX') + ' ' +
    279279                style.SQL_TABLE(index_name) + ' ' +
    280280                style.SQL_KEYWORD('ON') + ' ' +
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index abea3b7..0d47dc0 100644
    a b class DatabaseOperations(BaseDatabaseOperations): 
    167167        else:
    168168            return qn(db_table)
    169169
     170    def prep_db_index(self, db_schema, db_index):
     171        return self.prep_db_table(db_schema, db_index)
     172
    170173    def random_function_sql(self):
    171174        return 'RAND()'
    172175
  • django/db/backends/oracle/base.py

    diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
    index f1240d7..7488376 100644
    a b WHEN (new.%(col_name)s IS NULL) 
    135135        else:
    136136            return qn(db_table)
    137137
     138    def prep_db_index(self, db_schema, db_index):
     139        return self.prep_db_table(db_schema, db_index)
     140
    138141    def prep_for_iexact_query(self, x):
    139142        return x
    140143
  • django/db/models/options.py

    diff --git a/django/db/models/options.py b/django/db/models/options.py
    index a6fd925..7985e5f 100644
    a b class Options(object): 
    3030        self.module_name, self.verbose_name = None, None
    3131        self.verbose_name_plural = None
    3232        self.db_table = ''
    33         self.db_schema = ''
     33        self.db_schema = settings.DATABASE_SCHEMA
    3434        self.qualified_name = ''
    3535        self.ordering = []
    3636        self.unique_together =  []
  • docs/ref/models/options.txt

    diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt
    index 30b6fb6..682a229 100644
    a b If your database table name is an SQL reserved word, or contains characters that 
    5050aren't allowed in Python variable names -- notably, the hyphen -- that's OK.
    5151Django quotes column and table names behind the scenes.
    5252
     53.. _db_schema:
     54
    5355``db_schema``
    5456-----------------
    5557
     58.. attribute:: Options.db_schema
     59
    5660**New in Django development version**
    5761
    5862The name of the database schema to use for the model. If the backend
    5963doesn't support multiple schemas, this options is ignored.
    6064
    61 If this is used Django will prefix any table names with the schema name.
    62 For example MySQL Django would use ``db_schema + '.' + db_table``.
    63 Be aware that postgres supports different schemas within the database.
     65If this is used the Django will prefix the model table names with the schema
     66name. For example MySQL Django would use ``db_schema + '.' + db_table``.
     67Be aware that PostgreSQL supports different schemas within the database.
    6468MySQL solves the same thing by treating it as just another database.
    6569
    6670
  • docs/ref/settings.txt

    diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
    index e8c673d..4c16bf7 100644
    a b Default: ``''`` (Empty string) 
    227227The port to use when connecting to the database. An empty string means the
    228228default port. Not used with SQLite.
    229229
     230.. setting:: DATABASE_SCHEMA
     231
     232DATABASE_SCHEMA
     233---------------
     234
     235**New in Django development version**
     236
     237Default: ``''`` (Empty string)
     238
     239The name of the database schema to use for models. If the backend
     240doesn't support multiple schemas, this options is ignored. An empty
     241string means the default schema.
     242
     243If this is used the Django will prefix any table names with the schema name.
     244The schema can be overriden in model, for details see :ref:`db_schema`.
     245
    230246.. setting:: DATABASE_USER
    231247
    232248DATABASE_USER
Back to Top