diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2018-11-11 01:58:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2018-11-11 01:58:18 +0000 |
commit | 6b84db83e0c16b294eda9c0724957b32a3feb016 (patch) | |
tree | 985dedcc7e628792937047e7a5850c44795cc5bc /lib/sqlalchemy/sql/compiler.py | |
parent | 680835f815c7fb0cdd96113e3780261a71a8a5fc (diff) | |
parent | be705595846cd2205c72f9d87c025f8dc530cb73 (diff) | |
download | sqlalchemy-6b84db83e0c16b294eda9c0724957b32a3feb016.tar.gz |
Merge "Add new "all columns" naming convention tokens"
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 27ee4afc6..459e0ba2c 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2621,17 +2621,7 @@ class DDLCompiler(Compiled): else: schema_name = None - ident = index.name - if isinstance(ident, elements._truncated_label): - max_ = self.dialect.max_index_name_length or \ - self.dialect.max_identifier_length - if len(ident) > max_: - ident = ident[0:max_ - 8] + \ - "_" + util.md5_hex(ident)[-4:] - else: - self.dialect.validate_identifier(ident) - - index_name = self.preparer.quote(ident) + index_name = self.preparer.format_index(index) if schema_name: index_name = schema_name + "." + index_name @@ -3162,11 +3152,31 @@ class IdentifierPreparer(object): if isinstance(constraint.name, elements._defer_name): name = naming._constraint_name_for_table( constraint, constraint.table) - if name: - return self.quote(name) - elif isinstance(constraint.name, elements._defer_none_name): - return None - return self.quote(constraint.name) + + if name is None: + if isinstance(constraint.name, elements._defer_none_name): + return None + else: + name = constraint.name + else: + name = constraint.name + + if isinstance(name, elements._truncated_label): + if constraint.__visit_name__ == 'index': + max_ = self.dialect.max_index_name_length or \ + self.dialect.max_identifier_length + else: + max_ = self.dialect.max_identifier_length + if len(name) > max_: + name = name[0:max_ - 8] + \ + "_" + util.md5_hex(name)[-4:] + else: + self.dialect.validate_identifier(name) + + return self.quote(name) + + def format_index(self, index): + return self.format_constraint(index) def format_table(self, table, use_schema=True, name=None): """Prepare a quoted table and schema name.""" |