default schema / schema translation map as an execution argument

Issue #2685 resolved
Michael 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. Michael Bayer reporter

    the usage pattern would be like:

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

    to generate the SQL plain looks like:

    from sqlalchemy import *
    from sqlalchemy import schema
    m = MetaData()
    t1 = Table('t1', m, Column('x', Integer))
    print{'default_schema': 'foo'})
    print schema.CreateTable(t1).compile(compile_kwargs={'default_schema': 'foo'})
  2. Michael 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.

  3. Michael 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>>

  4. Log in to comment