diff options
author | Jungkook Park <pjknkda@gmail.com> | 2016-02-19 17:25:38 +0900 |
---|---|---|
committer | Jungkook Park <pjknkda@gmail.com> | 2016-02-20 05:18:46 +0900 |
commit | 8b48dd5cb6719d43d826682ed76d9f87eb2a093c (patch) | |
tree | 58f90bce1afe2c9cc4d1d2a65deda667d24194a5 /lib/sqlalchemy/engine/reflection.py | |
parent | c97aa63789036fc145503f03123275253ae02d2c (diff) | |
download | sqlalchemy-pr/242.tar.gz |
add reflection for expression-based index and partial index of postgresqlpr/242
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r-- | lib/sqlalchemy/engine/reflection.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index eaa5e2e48..833e53014 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -57,6 +57,7 @@ def cache(fn, self, con, *args, **kw): class Inspector(object): + """Performs database schema inspection. The Inspector acts as a proxy to the reflection methods of the @@ -727,26 +728,25 @@ class Inspector(object): continue if duplicates: continue - # look for columns by orig name in cols_by_orig_name, - # but support columns that are in-Python only as fallback + idx_cols = [] for c in columns: - try: - idx_col = cols_by_orig_name[c] \ - if c in cols_by_orig_name else table.c[c] - except KeyError: - util.warn( - "%s key '%s' was not located in " - "columns for table '%s'" % ( - flavor, c, table_name - )) + if c in cols_by_orig_name: + idx_col = cols_by_orig_name[c] + elif c in table.c: + idx_col = table.c[c] else: - idx_cols.append(idx_col) + # expression-based index + idx_col = sql.text(c) + + idx_cols.append(idx_col) - sa_schema.Index( + idx = sa_schema.Index( name, *idx_cols, **dict(list(dialect_options.items()) + [('unique', unique)]) ) + if idx.table is None: + table.append_constraint(idx) def _reflect_unique_constraints( self, table_name, schema, table, cols_by_orig_name, |