On 12/24/2015 12:15 PM, Jonathan Beluch wrote:
> I have a view that exists in the database and is defined in the metadata
> object via a Table() construct. When I use autogenerate, alembic always
> thinks that the view doesn't exist in the DB (it does) and so generates
> a create table operation.
> 
> I think it has to do with an asymmetry in autogenerate/compare.py using
> only inspector.get_table_names() and not get_views() whereas the
> metadata object contains both tables and views.
> 
> INFO  [sqlalchemy.engine.base.Engine] SELECT relname FROM pg_class c
> WHERE relkind = 'r' AND 'myschema' = (select nspname from pg_namespace n
> where n.oid = c.relnamespace)
> INFO  [sqlalchemy.engine.base.Engine] {}
> INFO  [alembic.autogenerate.compare] Detected added table
> u'my_schema.my_view'

that's a good observation and it might be nice if Alembic had something
automatic in this regard, but since SQLAlchemy still has no explicit
VIEW construct, it's probably best to wait until that is totally fleshed
out.

In the meantime, the standard way to control what autogenerate considers
is using the include_object callable:

http://alembic.readthedocs.org/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.include_object

here, you can even call the get_views() method of the Inspector and then
check if the given table name is in the list:

from sqlalchemy import inspect
reflected_views = set()
def include_object(object, name, type_, reflected, compare_to):
    if type_ == "table" and name in reflected_views:
        return False
    else:
        return True

with connectable.connect() as connection:
    reflected_views.update(inspect(connection).get_view_names())
    context.configure(
        # ...
        include_object = include_object
    )


> 
> SQLAlchemy==1.0.11
> alembic==0.8.4
> postgres 9.4
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy-alembic" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy-alembic+unsubscr...@googlegroups.com
> <mailto:sqlalchemy-alembic+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to