summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-11-05 14:52:35 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-11-10 16:13:01 -0500
commitbe705595846cd2205c72f9d87c025f8dc530cb73 (patch)
treed690bf7efe8c7d9e8b52472aa9b8db6a1b8e75e7 /lib/sqlalchemy/sql/schema.py
parent15ac07f7b6c235131361f289d75d174c49afb0b5 (diff)
downloadsqlalchemy-be705595846cd2205c72f9d87c025f8dc530cb73.tar.gz
Add new "all columns" naming convention tokens
Added new naming convention tokens ``column_0N_name``, ``column_0_N_name``, etc., which will render the names / keys / labels for all columns referenced by a particular constraint in a sequence. In order to accommodate for the length of such a naming convention, the SQL compiler's auto-truncation feature now applies itself to constraint names as well, which creates a shortened, deterministically generated name for the constraint that will apply to a target backend without going over the character limit of that backend. Additional notes: 1. the SQLite dialect had a format_index method that was apparently not used, removed. 2. the naming convention logic has been applying the foreign key remote column spec to the naming convention, and not the actual column name. In the case where the referenced Table object uses .key inside the columns and these are what ForeignKey() references, the naming convention was doing the wrong thing. The patch here fixes this, however this isn't noted in the migration notes. Fixes: #3989 Change-Id: Ib24f4754b886676096c480fc54b2e5c2463ac99a
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 88050b87e..e37c703eb 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -3654,15 +3654,29 @@ class MetaData(SchemaItem):
* ``%(column_0_name)s`` - the name of the :class:`.Column` at
index position "0" within the constraint.
- * ``%(column_0_label)s`` - the label of the :class:`.Column` at
- index position "0", e.g. :attr:`.Column.label`
-
- * ``%(column_0_key)s`` - the key of the :class:`.Column` at
- index position "0", e.g. :attr:`.Column.key`
-
- * ``%(referred_column_0_name)s`` - the name of a :class:`.Column`
- at index position "0" referenced by a
- :class:`.ForeignKeyConstraint`.
+ * ``%(column_0N_name)s`` - the name of all :class:`.Column`
+ objects in order within the constraint, joined without a
+ separator.
+
+ * ``%(column_0_N_name)s`` - the name of all :class:`.Column`
+ objects in order within the constraint, joined with an
+ underscore as a separator.
+
+ * ``%(column_0_label)s``, ``%(column_0N_label)s``,
+ ``%(column_0_N_label)s`` - the label of either the zeroth
+ :class:`.Column` or all :class:`.Columns`, separated with
+ or without an underscore
+
+ * ``%(column_0_key)s``, ``%(column_0N_key)s``,
+ ``%(column_0_N_key)s`` - the key of either the zeroth
+ :class:`.Column` or all :class:`.Columns`, separated with
+ or without an underscore
+
+ * ``%(referred_column_0_name)s``, ``%(referred_column_0N_name)s``
+ ``%(referred_column_0_N_name)s``, ``%(referred_column_0_key)s``,
+ ``%(referred_column_0N_key)s``, ... column tokens which
+ render the names/keys/labels of columns that are referenced
+ by a :class:`.ForeignKeyConstraint`.
* ``%(constraint_name)s`` - a special key that refers to the
existing name given to the constraint. When this key is
@@ -3675,7 +3689,10 @@ class MetaData(SchemaItem):
it along with a ``fn(constraint, table)`` callable to the
naming_convention dictionary.
- .. versionadded:: 0.9.2
+ .. versionadded:: 1.3.0 - added new ``%(column_0N_name)s``,
+ ``%(column_0_N_name)s``, and related tokens that produce
+ concatenations of names, keys, or labels for all columns referred
+ to by a given constraint.
.. seealso::