default schema / schema translation map as an execution argument

Issue #2685 resolved
Mike Bayer repo owner created an issue

this comes up a lot, the need to swap in a schema name for all tables. this is an easy add as an execution option, most of a patch is attached, needs tests.

Comments (10)

  1. Mike Bayer reporter

    the usage pattern would be like:

    conn = connection.execution_options(default_schema="foo")
    conn.execute(stmt)
    

    to generate the SQL plain looks like:

    from sqlalchemy import *
    from sqlalchemy import schema
    
    m = MetaData()
    t1 = Table('t1', m, Column('x', Integer))
    
    print t1.select().compile()
    print t1.select().compile(compile_kwargs={'default_schema': 'foo'})
    
    print schema.CreateTable(t1).compile(compile_kwargs={'default_schema': 'foo'})
    
  2. Mike Bayer reporter

    this patch works for rendering but isn't taken into account by the inspector. needs that also.

  3. Mike Bayer reporter

    we might want to look into providing a "swap" feature, e.g. if an app has tables in "(default)", "schema_a", "schema_b", a lookup table can be sent in such that any of these three can be exchanged for another.

  4. Mike Bayer reporter
    • Multi-tenancy schema translation for :class:.Table objects is added. This supports the use case of an application that uses the same set of :class:.Table objects in many schemas, such as schema-per-user. A new execution option :paramref:.Connection.execution_options.schema_translate_map is added. fixes #2685
    • latest tox doesn't like the {posargs} in the profile rerunner

    → <<cset 89facbed8855>>

  5. Log in to comment