Files
Home-AssistantConfig/deps/sqlalchemy/sql/__pycache__/ddl.cpython-34.pyc

532 lines
37 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
|<7C><>W<EFBFBD><57><00>@sEdZddlmZddlmZddlmZmZmZm Z ddlm
Z
ddlm Z ddlm Z Gd d
<00>d
e<00>Z Gd d <00>d ee <00>ZGd d<00>de<00>ZGdd<00>de<00>ZGdd<00>de<00>ZGdd<00>de<00>ZGdd<00>de<00>ZGdd<00>de<00>ZGdd<00>de <00>ZGdd<00>de<00>ZGdd<00>de<00>ZGdd <00>d e<00>ZGd!d"<00>d"e<00>ZGd#d$<00>d$e<00>ZGd%d&<00>d&e<00>ZGd'd(<00>d(e<00>ZGd)d*<00>d*e<00>ZGd+d,<00>d,e<00>ZGd-d.<00>d.e<00>Zd/d/d0d1<00>Z d/d/d2d3<00>Z!d/S)4zq
Provides the hierarchy of DDL-defining schema items as well as routines
to invoke them for a create/drop call.
<EFBFBD>)<01>util<69>)<01> ClauseElement)<04>
Executable<EFBFBD> _generative<76> SchemaVisitor<6F>_bind_or_error)<01> topological)<01>event)<01>excc@seZdZdd<00>ZdS)<04> _DDLCompilescKs|j|||<00>S)zNReturn a compiler appropriate for this ClauseElement, given a
Dialect.)Z ddl_compiler)<03>self<6C>dialect<63>kw<6B>r<00>8/tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/sql/ddl.py<70> _compilersz_DDLCompiles._compilerN)<04>__name__<5F>
__module__<EFBFBD> __qualname__rrrrrr s r c@seZdZdZejjidd6<>ZdZdZdZ dZ
dd<00>Z dddd<00>Z e jd d
<00>d d <00><00>Zed d<00><00>Zeddddd<00><00>Zdd<00>Zdd<00>Zdd<00>Zdd<00>Zdd<00>Zdd<00>Zeee<00>Zdd<00>ZdS)<1F>
DDLElementa<EFBFBD>Base class for DDL expression constructs.
This class is the base for the general purpose :class:`.DDL` class,
as well as the various create/drop clause constructs such as
:class:`.CreateTable`, :class:`.DropTable`, :class:`.AddConstraint`,
etc.
:class:`.DDLElement` integrates closely with SQLAlchemy events,
introduced in :ref:`event_toplevel`. An instance of one is
itself an event receiving callable::
event.listen(
users,
'after_create',
AddConstraint(constraint).execute_if(dialect='postgresql')
)
.. seealso::
:class:`.DDL`
:class:`.DDLEvents`
:ref:`event_toplevel`
:ref:`schema_ddl_sequences`
TZ
autocommitNcCs|j|||<00>S)N)Z _execute_ddl)r <00>
connectionZ multiparams<6D>paramsrrr<00>_execute_on_connectionCsz!DDLElement._execute_on_connectioncCsZ|dkrt|<00>}n|j||<00>rC|j|j|<00><00>S|jjjd<00>dS)a Execute this DDL immediately.
Executes the DDL statement in isolation using the supplied
:class:`.Connectable` or
:class:`.Connectable` assigned to the ``.bind``
property, if not supplied. If the DDL has a conditional ``on``
criteria, it will be invoked with None as the event.
:param bind:
Optional, an ``Engine`` or ``Connection``. If not supplied, a valid
:class:`.Connectable` must be present in the
``.bind`` property.
:param target:
Optional, defaults to None. The target SchemaItem for the
execute call. Will be passed to the ``on`` callable if any,
and may also provide string expansion data for the
statement. See ``execute_at`` for more information.
Nz(DDL execution skipped, criteria not met.)r<00>_should_execute<74>execute<74>against<73>engine<6E>logger<65>info)r <00>bind<6E>targetrrrrFs   zDDLElement.executez0.7zCSee :class:`.DDLEvents`, as well as :meth:`.DDLElement.execute_if`.cs<<00><00>fdd<00>}tj|d<00>jdd<00>|<00>dS)aQLink execution of this DDL to the DDL lifecycle of a SchemaItem.
Links this ``DDLElement`` to a ``Table`` or ``MetaData`` instance,
executing it when that schema item is created or dropped. The DDL
statement will be executed using the same Connection and transactional
context as the Table create/drop itself. The ``.bind`` property of
this statement is ignored.
:param event:
One of the events defined in the schema item's ``.ddl_events``;
e.g. 'before-create', 'after-create', 'before-drop' or 'after-drop'
:param target:
The Table or MetaData instance for which this DDLElement will
be associated with.
A DDLElement instance can be linked to any number of schema items.
``execute_at`` builds on the ``append_ddl_listener`` interface of
:class:`.MetaData` and :class:`.Table` objects.
Caveat: Creating or dropping a Table in isolation will also trigger
any DDL set to ``execute_at`` that Table's MetaData. This may change
in a future release.
cs2<00>j<00>|||<00>r.|j<00>j|<00><00>SdS)N)<03>_should_execute_deprecatedrr)r!rr)<02>
event_namer rr<00>
call_event<EFBFBD>s z)DDLElement.execute_at.<locals>.call_event<6E><00>-<2D>_N)r
<00>listen<65>replace)r r#r!r$r)r#r r<00>
execute_ateszDDLElement.execute_atcCs ||_dS)z9Return a copy of this DDL against a specific schema item.N)r!)r r!rrrr<00>szDDLElement.againstcCs||_||_||_dS)a<>Return a callable that will execute this
DDLElement conditionally.
Used to provide a wrapper for event listening::
event.listen(
metadata,
'before_create',
DDL("my_ddl").execute_if(dialect='postgresql')
)
:param dialect: May be a string, tuple or a callable
predicate. If a string, it will be compared to the name of the
executing database dialect::
DDL('something').execute_if(dialect='postgresql')
If a tuple, specifies multiple dialect names::
DDL('something').execute_if(dialect=('postgresql', 'mysql'))
:param callable_: A callable, which will be invoked with
four positional arguments as well as optional keyword
arguments:
:ddl:
This DDL element.
:target:
The :class:`.Table` or :class:`.MetaData` object which is the
target of this event. May be None if the DDL is executed
explicitly.
:bind:
The :class:`.Connection` being used for DDL execution
:tables:
Optional keyword argument - a list of Table objects which are to
be created/ dropped within a MetaData.create_all() or drop_all()
method call.
:state:
Optional keyword argument - will be the ``state`` argument
passed to this function.
:checkfirst:
Keyword argument, will be True if the 'checkfirst' flag was
set during the call to ``create()``, ``create_all()``,
``drop()``, ``drop_all()``.
If the callable returns a true value, the DDL statement will be
executed.
:param state: any value which will be passed to the callable\_
as the ``state`` keyword argument.
.. seealso::
:class:`.DDLEvents`
:ref:`event_toplevel`
N)r<00> callable_<65>state)r rr+r,rrr<00>
execute_if<EFBFBD>sA  zDDLElement.execute_ifcKs<>|jdk r,|jd|||<00> r,dSt|jtj<00>r]|j|jjkr<>dSn7t|jtt t
f<00>r<>|jj|jkr<>dSn|j dk r<>|j |||d|j |<00> r<>dSdS)NFr,T) <0A>onr"<00>
isinstancerr<00> string_typesr<00>name<6D>tuple<6C>list<73>setr+r,)r r!r rrrrr<00>szDDLElement._should_executecKs<>|jdkrdSt|jtj<00>r;|j|jjkSt|jtttf<00>ri|jj|jkS|j|||||<00>SdS)NT) r.r/rr0rr1r2r3r4)r r
r!r rrrrr"<00>sz%DDLElement._should_execute_deprecatedcKs/|j|||<00>r+|j|j|<00><00>SdS)z"Execute the DDL as a ddl_listener.N)rrr)r r!r rrrr<00>__call__<5F>szDDLElement.__call__cCs_|dk r[t|tjtttf<17> r[tj|<00> r[tjdt |<00>j
<16><00>ndS)NzjExpected the name of a database dialect, a tuple of names, or a callable for 'on' criteria, got type '%s'.) r/rr0r2r3r4<00>callabler <00> ArgumentError<6F>typer)r r.rrr<00> _check_ddl_on<6F>s   zDDLElement._check_ddl_oncCs|jr|jSdS)N)<01>_bind)r rrrr s zDDLElement.bindcCs ||_dS)N)r:)r r rrr<00> _set_bindszDDLElement._set_bindcCs+|jj|j<00>}|jj<00>|_|S)N)<04> __class__<5F>__new__<5F>__dict__<5F>copy)r <00>srrr<00> _generateszDDLElement._generate)rrr<00>__doc__rZ_execution_options<6E>unionr!r.rr+rrrZ
deprecatedr*rrr-rr"r5r9r r;<00>propertyrArrrrrs(  %D 
  rc@s=eZdZdZdZddddd<00>Zdd<00>ZdS)<08>DDLa/A literal DDL statement.
Specifies literal SQL DDL to be executed by the database. DDL objects
function as DDL event listeners, and can be subscribed to those events
listed in :class:`.DDLEvents`, using either :class:`.Table` or
:class:`.MetaData` objects as targets. Basic templating support allows
a single DDL instance to handle repetitive tasks for multiple tables.
Examples::
from sqlalchemy import event, DDL
tbl = Table('users', metadata, Column('uid', Integer))
event.listen(tbl, 'before_create', DDL('DROP TRIGGER users_trigger'))
spow = DDL('ALTER TABLE %(table)s SET secretpowers TRUE')
event.listen(tbl, 'after_create', spow.execute_if(dialect='somedb'))
drop_spow = DDL('ALTER TABLE users SET secretpowers FALSE')
connection.execute(drop_spow)
When operating on Table events, the following ``statement``
string substitions are available::
%(table)s - the Table name, with any required quoting applied
%(schema)s - the schema name, with any required quoting applied
%(fullname)s - the Table name including schema, quoted if needed
The DDL's "context", if any, will be combined with the standard
substitutions noted above. Keys present in the context will override
the standard substitutions.
ZddlNcCsct|tj<00>s(tjd|<16><00>n||_|p:i|_|j|<00>||_||_ dS)awCreate a DDL statement.
:param statement:
A string or unicode string to be executed. Statements will be
processed with Python's string formatting operator. See the
``context`` argument and the ``execute_at`` method.
A literal '%' in a statement must be escaped as '%%'.
SQL bind parameters are not available in DDL statements.
:param on:
.. deprecated:: 0.7
See :meth:`.DDLElement.execute_if`.
Optional filtering criteria. May be a string, tuple or a callable
predicate. If a string, it will be compared to the name of the
executing database dialect::
DDL('something', on='postgresql')
If a tuple, specifies multiple dialect names::
DDL('something', on=('postgresql', 'mysql'))
If a callable, it will be invoked with four positional arguments
as well as optional keyword arguments:
:ddl:
This DDL element.
:event:
The name of the event that has triggered this DDL, such as
'after-create' Will be None if the DDL is executed explicitly.
:target:
The ``Table`` or ``MetaData`` object which is the target of
this event. May be None if the DDL is executed explicitly.
:connection:
The ``Connection`` being used for DDL execution
:tables:
Optional keyword argument - a list of Table objects which are to
be created/ dropped within a MetaData.create_all() or drop_all()
method call.
If the callable returns a true value, the DDL statement will be
executed.
:param context:
Optional dictionary, defaults to None. These values will be
available for use in string substitutions on the DDL statement.
:param bind:
Optional. A :class:`.Connectable`, used by
default when ``execute()`` is invoked without a bind argument.
.. seealso::
:class:`.DDLEvents`
:ref:`event_toplevel`
z4Expected a string or unicode SQL statement, got '%r'N)
r/rr0r r7<00> statement<6E>contextr9r.r:)r rFr.rGr rrr<00>__init__3sE    z DDL.__init__csLdt<00><00>jt<00><00>djt<00>j<00>g<00>fdd<00>dD<><17>fS)Nz <%s@%s; %s>z, cs8g|].}t<00>|<00>rd|t<00>|<00>f<16>qS)z%s=%r)<01>getattr)<02>.0<EFBFBD>key)r rr<00>
<listcomp><3E>s z DDL.__repr__.<locals>.<listcomp>r.rG)zonzcontext)r8r<00>id<69>join<69>reprrF)r r)r r<00>__repr__<5F>s
z DDL.__repr__)rrrrB<00>__visit_name__rHrPrrrrrEs !QrEc@s4eZdZdZdddd<00>Zdd<00>ZdS)<07>_CreateDropBasez<65>Base class for DDL constructs that represent CREATE and DROP or
equivalents.
The common theme of _CreateDropBase is a single
``element`` attribute which refers to the element
to be created or dropped.
NcCs,||_|j|<00>||_||_dS)N)<04>elementr9r.r )r rSr.r rrrrH<00>s   z_CreateDropBase.__init__cCsdS)z<>Allow disable of _create_rule using a callable.
Pass to _create_rule using
util.portable_instancemethod(self._create_rule_disable)
to retain serializability.
Fr)r <00>compilerrrr<00>_create_rule_disable<6C>sz$_CreateDropBase._create_rule_disable)rrrrBrHrUrrrrrR<00>s rRcs1eZdZdZdZd<00>fdd<00>Z<00>S)<06> CreateSchemaz<61>Represent a CREATE SCHEMA statement.
.. versionadded:: 0.7.4
The argument here is the string name of the schema.
Z create_schemaNc s&||_tt|<00>j||<00>dS)z.Create a new :class:`.CreateSchema` construct.N)<04>quote<74>superrVrH)r r1rWr)r<rrrH<00>s zCreateSchema.__init__)rrrrBrQrHrr)r<rrV<00>s rVcs4eZdZdZdZdd<00>fdd<00>Z<00>S)<07>
DropSchemaz~Represent a DROP SCHEMA statement.
The argument here is the string name of the schema.
.. versionadded:: 0.7.4
Z drop_schemaNFc s/||_||_tt|<00>j||<00>dS)z,Create a new :class:`.DropSchema` construct.N)rW<00>cascaderXrYrH)r r1rWrZr)r<rrrH<00>s  zDropSchema.__init__)rrrrBrQrHrr)r<rrY<00>s rYcs7eZdZdZdZddd<00>fdd<00>Z<00>S)<06> CreateTablez#Represent a CREATE TABLE statement.Z create_tableNcsHtt|<00>j|d|d|<00>dd<00>|jD<>|_||_dS)aLCreate a :class:`.CreateTable` construct.
:param element: a :class:`.Table` that's the subject
of the CREATE
:param on: See the description for 'on' in :class:`.DDL`.
:param bind: See the description for 'bind' in :class:`.DDL`.
:param include_foreign_key_constraints: optional sequence of
:class:`.ForeignKeyConstraint` objects that will be included
inline within the CREATE construct; if omitted, all foreign key
constraints that do not specify use_alter=True are included.
.. versionadded:: 1.0.0
r.r cSsg|]}t|<00><00>qSr)<01> CreateColumn)rJ<00>columnrrrrL<00>s z(CreateTable.__init__.<locals>.<listcomp>N)rXr[rH<00>columns<6E>include_foreign_key_constraints)r rSr.r r_)r<rrrH<00>s" zCreateTable.__init__)rrrrBrQrHrr)r<rr[<00>s r[c@seZdZdZdZdS)<04> _DropViewz<77>Semi-public 'DROP VIEW' construct.
Used by the test suite for dialect-agnostic drops of views.
This object will eventually be part of a public "view" API.
Z drop_viewN)rrrrBrQrrrrr`<00>s r`c@s(eZdZdZdZdd<00>ZdS)r\azRepresent a :class:`.Column` as rendered in a CREATE TABLE statement,
via the :class:`.CreateTable` construct.
This is provided to support custom column DDL within the generation
of CREATE TABLE statements, by using the
compiler extension documented in :ref:`sqlalchemy.ext.compiler_toplevel`
to extend :class:`.CreateColumn`.
Typical integration is to examine the incoming :class:`.Column`
object, and to redirect compilation if a particular flag or condition
is found::
from sqlalchemy import schema
from sqlalchemy.ext.compiler import compiles
@compiles(schema.CreateColumn)
def compile(element, compiler, **kw):
column = element.element
if "special" not in column.info:
return compiler.visit_create_column(element, **kw)
text = "%s SPECIAL DIRECTIVE %s" % (
column.name,
compiler.type_compiler.process(column.type)
)
default = compiler.get_column_default_string(column)
if default is not None:
text += " DEFAULT " + default
if not column.nullable:
text += " NOT NULL"
if column.constraints:
text += " ".join(
compiler.process(const)
for const in column.constraints)
return text
The above construct can be applied to a :class:`.Table` as follows::
from sqlalchemy import Table, Metadata, Column, Integer, String
from sqlalchemy import schema
metadata = MetaData()
table = Table('mytable', MetaData(),
Column('x', Integer, info={"special":True}, primary_key=True),
Column('y', String(50)),
Column('z', String(20), info={"special":True})
)
metadata.create_all(conn)
Above, the directives we've added to the :attr:`.Column.info` collection
will be detected by our custom compilation scheme::
CREATE TABLE mytable (
x SPECIAL DIRECTIVE INTEGER NOT NULL,
y VARCHAR(50),
z SPECIAL DIRECTIVE VARCHAR(20),
PRIMARY KEY (x)
)
The :class:`.CreateColumn` construct can also be used to skip certain
columns when producing a ``CREATE TABLE``. This is accomplished by
creating a compilation rule that conditionally returns ``None``.
This is essentially how to produce the same effect as using the
``system=True`` argument on :class:`.Column`, which marks a column
as an implicitly-present "system" column.
For example, suppose we wish to produce a :class:`.Table` which skips
rendering of the Postgresql ``xmin`` column against the Postgresql
backend, but on other backends does render it, in anticipation of a
triggered rule. A conditional compilation rule could skip this name only
on Postgresql::
from sqlalchemy.schema import CreateColumn
@compiles(CreateColumn, "postgresql")
def skip_xmin(element, compiler, **kw):
if element.element.name == 'xmin':
return None
else:
return compiler.visit_create_column(element, **kw)
my_table = Table('mytable', metadata,
Column('id', Integer, primary_key=True),
Column('xmin', Integer)
)
Above, a :class:`.CreateTable` construct will generate a ``CREATE TABLE``
which only includes the ``id`` column in the string; the ``xmin`` column
will be omitted, but only against the Postgresql backend.
.. versionadded:: 0.8.3 The :class:`.CreateColumn` construct supports
skipping of columns by returning ``None`` from a custom compilation
rule.
.. versionadded:: 0.8 The :class:`.CreateColumn` construct was added
to support custom column creation styles.
Z create_columncCs ||_dS)N)rS)r rSrrrrH_szCreateColumn.__init__N)rrrrBrQrHrrrrr\<00>s hr\c@seZdZdZdZdS)<04> DropTablez!Represent a DROP TABLE statement.Z
drop_tableN)rrrrBrQrrrrracs rac@seZdZdZdZdS)<04>CreateSequencez&Represent a CREATE SEQUENCE statement.Zcreate_sequenceN)rrrrBrQrrrrrbis rbc@seZdZdZdZdS)<04> DropSequencez$Represent a DROP SEQUENCE statement.Z drop_sequenceN)rrrrBrQrrrrrcos rcc@seZdZdZdZdS)<04> CreateIndexz#Represent a CREATE INDEX statement.Z create_indexN)rrrrBrQrrrrrdus rdc@seZdZdZdZdS)<04> DropIndexz!Represent a DROP INDEX statement.Z
drop_indexN)rrrrBrQrrrrre{s recs.eZdZdZdZ<00>fdd<00>Z<00>S)<05> AddConstraintz2Represent an ALTER TABLE ADD CONSTRAINT statement.Zadd_constraintcs5tt|<00>j|||<00>tj|j<00>|_dS)N)rXrfrHr<00>portable_instancemethodrU<00> _create_rule)r rS<00>argsr)r<rrrH<00>szAddConstraint.__init__)rrrrBrQrHrr)r<rrf<00>s rfcs1eZdZdZdZd<00>fdd<00>Z<00>S)<06>DropConstraintz3Represent an ALTER TABLE DROP CONSTRAINT statement.Zdrop_constraintFc s;||_tt|<00>j||<00>tj|j<00>|_dS)N)rZrXrjrHrrgrUrh)r rSrZr)r<rrrH<00>s zDropConstraint.__init__)rrrrBrQrHrr)r<rrj<00>s rjc@seZdZdd<00>ZdS)<04>DDLBasecCs ||_dS)N)r)r rrrrrH<00>szDDLBase.__init__N)rrrrHrrrrrk<00>s rkcs<>eZdZdd<00>fdd<00>Zdd<00>Zdd<00>Zd d
<00>Zdddd d <00>Zd d<00>Zddd<00>Z dd<00>Z
<00>S)<13>SchemaGeneratorFNc sMtt|<00>j||<00>||_||_|j|_||_i|_dS)N) rXrlrH<00>
checkfirst<EFBFBD>tables<65>identifier_preparer<65>preparerr<00>memo)r rrrmrn<00>kwargs)r<rrrH<00>s     zSchemaGenerator.__init__cCs_|jj|j<00>|jr2|jj|j<00>n|j p^|jj|j|jd|j<00> S)N<>schema)r<00>validate_identifierr1rsrm<00> has_tabler)r <00>tablerrr<00>_can_create_table<6C>s  
z!SchemaGenerator._can_create_tablecCsP|jjoO|jj s#|j oO|j pO|jj|j|jd|j<00> S)Nrs) r<00>supports_sequences<65>sequences_optional<61>optionalrm<00> has_sequencerr1rs)r <00>sequencerrr<00>_can_create_sequence<63>s  

  z$SchemaGenerator._can_create_sequencec
se<00>jdk r<00>j}nt|jj<00><00>}t<00>fdd<00>|D<><00>}<00>fdd<00>|jj<00>D<>}dd<00>|D<>}|jj|<00>jd|d<00>jd<00><00>x!|D]}<00>j |dd <00>q<>Wx`|D]X\}}|dk r<01>j |dd d
|d d <00>q<>x|D]} <00>j | <00>qWq<57>W|jj
|<00>jd|d<00>jd<00><00>dS) Ncs%g|]}<00>j|<00>r|<00>qSr)rw)rJ<00>t)r rrrL<00>s z2SchemaGenerator.visit_metadata.<locals>.<listcomp>cs4g|]*}|jdkr<00>j|<00>r|<00>qS)N)r]r})rJr@)r rrrL<00>s cSs(g|]\}}|dk r|<00>qS)Nr)rJr~<00>fksrrrrL<00>s rnrm<00> _ddl_runner<65> create_okTr_<00>_is_metadata_operation) rnr3<00>values<65>sort_tables_and_constraints<74>
_sequences<EFBFBD>dispatch<63> before_createrrm<00>traverse_single<6C> after_create)
r <00>metadatarn<00>
collection<EFBFBD>seq_coll<6C>event_collection<6F>seqrv<00>fkcs<63>fkcr)r r<00>visit_metadata<74>s2 "    
  zSchemaGenerator.visit_metadatac Cs| r|j|<00> rdS|jj||jd|jd|d|<00>x3|jD](}|jdk rP|j|j<00>qPqPW|jj s<>d}n|jj
t |d|<00><01>t |d<00>r<>x!|j D]}|j|<00>q<>Wn|jj||jd|jd|d|<00>dS)Nrmr<>r<>r_<00>indexes)rwr<>r<>rrmr^<00>defaultr<74>r<00>supports_alterrr[<00>hasattrr<72>r<>)r rvr<>r_r<>r]<00>indexrrr<00> visit_table<6C>s0      
   zSchemaGenerator.visit_tablecCs*|jjsdS|jjt|<00><00>dS)N)rr<>rrrf)r <00>
constraintrrr<00>visit_foreign_key_constraint s z,SchemaGenerator.visit_foreign_key_constraintcCs5| r|j|<00> rdS|jjt|<00><00>dS)N)r}rrrb)r r|r<>rrr<00>visit_sequenceszSchemaGenerator.visit_sequencecCs|jjt|<00><00>dS)N)rrrd)r r<>rrr<00> visit_indexszSchemaGenerator.visit_index) rrrrHrwr}r<>r<>r<>r<>r<>rr)r<rrl<00>s    '" rlcs<>eZdZdd<00>fdd<00>Zdd<00>Zdd<00>Zd d
<00>Zd d <00>Zddd d<00>Zdd<00>Z ddd<00>Z
<00>S)<13> SchemaDropperFNc sMtt|<00>j||<00>||_||_|j|_||_i|_dS)N) rXr<>rHrmrnrorprrq)r rrrmrnrr)r<rrrHs     zSchemaDropper.__init__c sV<00>jdk r<00>j}nt|jj<00><00>}yG<00>fdd<00>|D<>}ttt|d<00>fdd<00><00><01><00>}Wn<57>tjk
rE}z<><00>jjs<>t j
ddj t dd<00>|j D<><00><00><16>d d<00>|D<>}nRt jtj|jd
|j |jd d dj t d d<00>|j D<><00><00><16><01>WYdd}~XnX<>fdd<00>|jj<00>D<>}dd<00>|D<>}|jj|<00>jd|d<00>jd<00><00>xZ|D]R\}} |dk r<><01>j|dddd<00>q<>x| D]}
<00>j|
<00>q<>Wq<57>Wx!|D]} <00>j| dd<00>q
W|jj|<00>jd|d<00>jd<00><00>dS)Ncs%g|]}<00>j|<00>r|<00>qSr)<01>_can_drop_table)rJr~)r rrrL)s z0SchemaDropper.visit_metadata.<locals>.<listcomp><3E> filter_fncs$<00>jj s|jdkr dSdS)NF)rr<>r1)r<>)r rr<00><lambda>-s z.SchemaDropper.visit_metadata.<locals>.<lambda>a4Can't sort tables for DROP; an unresolvable foreign key dependency exists between tables: %s, and backend does not support ALTER. To restore at least a partial sort, apply use_alter=True to ForeignKey and ForeignKeyConstraint objects involved in the cycle to mark these as known cycles that will be ignored.z, cSsg|]}|j<00>qSr)<01>fullname)rJr~rrrrL?s cSsg|]}|ff<00>qSrr)rJr~rrrrLBs <00><00>msgz<67>Can't sort tables for DROP; an unresolvable foreign key dependency exists between tables: %s. Please ensure that the ForeignKey and ForeignKeyConstraint objects involved in the cycle have names so that they can be dropped using DROP CONSTRAINT.cSsg|]}|j<00>qSr)r<>)rJr~rrrrLPs cs4g|]*}|jdkr<00>j|<00>r|<00>qS)N)r]<00>_can_drop_sequence)rJr@)r rrrLWs cSs(g|]\}}|dk r|<00>qS)Nr)rJr~rrrrrL]s rnrmr<><00>drop_okTr<54>)rnr3r<><00>reversedr<64>r <00>CircularDependencyErrorrr<>r<00>warnrN<00>sortedZcyclesZraise_from_causeri<00>edgesr<73>r<><00> before_droprrmr<><00>
after_drop) r r<>rnZunsorted_tablesr<73>Zerr2r<32>r<>rvr<>r<>r<>r)r rr<>"sL   '
=     zSchemaDropper.visit_metadatacCs^|jj|j<00>|jr2|jj|j<00>n|j p]|jj|j|jd|j<00>S)Nrs)rrtr1rsrmrur)r rvrrrr<>ss
 zSchemaDropper._can_drop_tablecCsO|jjoN|jj s#|j oN|j pN|jj|j|jd|j<00>S)Nrs) rrxryrzrmr{rr1rs)r r|rrrr<>zs  

  z SchemaDropper._can_drop_sequencecCs|jjt|<00><00>dS)N)rrre)r r<>rrrr<><00>szSchemaDropper.visit_indexc Cs<>| r|j|<00> rdS|jj||jd|jd|d|<00>x3|jD](}|jdk rP|j|j<00>qPqPW|jjt |<00><00>|jj
||jd|jd|d|<00>dS)Nrmr<>r<>) r<>r<>r<>rrmr^r<>r<>rrar<>)r rvr<>r<>r]rrrr<><00>s       zSchemaDropper.visit_tablecCs*|jjsdS|jjt|<00><00>dS)N)rr<>rrrj)r r<>rrrr<><00>s z*SchemaDropper.visit_foreign_key_constraintcCs5| r|j|<00> rdS|jjt|<00><00>dS)N)r<>rrrc)r r|r<>rrrr<><00>szSchemaDropper.visit_sequence) rrrrHr<>r<>r<>r<>r<>r<>r<>rr)r<rr<>s  Q   r<>NcsJ<00>dk r!<00>fdd<00>}nd}dd<00>t|d|d|<00>D<>S)a\sort a collection of :class:`.Table` objects based on dependency.
This is a dependency-ordered sort which will emit :class:`.Table`
objects such that they will follow their dependent :class:`.Table` objects.
Tables are dependent on another based on the presence of
:class:`.ForeignKeyConstraint` objects as well as explicit dependencies
added by :meth:`.Table.add_is_dependent_on`.
.. warning::
The :func:`.sort_tables` function cannot by itself accommodate
automatic resolution of dependency cycles between tables, which
are usually caused by mutually dependent foreign key constraints.
To resolve these cycles, either the
:paramref:`.ForeignKeyConstraint.use_alter` parameter may be appled
to those constraints, or use the
:func:`.sql.sort_tables_and_constraints` function which will break
out foreign key constraints involved in cycles separately.
:param tables: a sequence of :class:`.Table` objects.
:param skip_fn: optional callable which will be passed a
:class:`.ForeignKey` object; if it returns True, this
constraint will not be considered as a dependency. Note this is
**different** from the same parameter in
:func:`.sort_tables_and_constraints`, which is
instead passed the owning :class:`.ForeignKeyConstraint` object.
:param extra_dependencies: a sequence of 2-tuples of tables which will
also be considered as dependent on each other.
.. seealso::
:func:`.sort_tables_and_constraints`
:meth:`.MetaData.sorted_tables` - uses this function to sort
Ncs,x%|jD]}<00>|<00>r
dSq
WdSdS)NT)<01>elements)r<>Zfk)<01>skip_fnrr<00>_skip_fn<66>s zsort_tables.<locals>._skip_fncSs(g|]\}}|dk r|<00>qS)Nr)rJr~r<>rrrrL<00>s zsort_tables.<locals>.<listcomp>r<><00>extra_dependencies)r<>)rnr<>r<>r<>r)r<>r<00> sort_tables<65>s )  r<>c s9t<00>}t<00>}|dk r.|j|<00>nt<00><00>x<>|D]<5D><00>x<><00>jD]<5D>}|jdkrv<00>j|<00>qNn<00>r<><00>|<00>}|dkr<><00>j|<00>qNq<>n|j}|<00>k rN|j|<00>f<00>qNqNW|j<00>fdd<00><00>jD<><00>q>Wy+ttj |j
|<00>|dd<00><01>}Wn<57>t j k
r} z<>x<>| j D]<5D>}
|
|krM|
d<19><00>fdd<00><00>jD<>} <00>j| <00>x<| D]1}|j}|<00>k r<>|j|<00>f<00>q<>q<>WqMqMWttj |j
|<00>|dd<00><01>}WYdd} ~ XnX<>fd d<00>|D<>dt<00><00>fgS)
a<EFBFBD>sort a collection of :class:`.Table` / :class:`.ForeignKeyConstraint`
objects.
This is a dependency-ordered sort which will emit tuples of
``(Table, [ForeignKeyConstraint, ...])`` such that each
:class:`.Table` follows its dependent :class:`.Table` objects.
Remaining :class:`.ForeignKeyConstraint` objects that are separate due to
dependency rules not satisifed by the sort are emitted afterwards
as ``(None, [ForeignKeyConstraint ...])``.
Tables are dependent on another based on the presence of
:class:`.ForeignKeyConstraint` objects, explicit dependencies
added by :meth:`.Table.add_is_dependent_on`, as well as dependencies
stated here using the :paramref:`~.sort_tables_and_constraints.skip_fn`
and/or :paramref:`~.sort_tables_and_constraints.extra_dependencies`
parameters.
:param tables: a sequence of :class:`.Table` objects.
:param filter_fn: optional callable which will be passed a
:class:`.ForeignKeyConstraint` object, and returns a value based on
whether this constraint should definitely be included or excluded as
an inline constraint, or neither. If it returns False, the constraint
will definitely be included as a dependency that cannot be subject
to ALTER; if True, it will **only** be included as an ALTER result at
the end. Returning None means the constraint is included in the
table-based result unless it is detected as part of a dependency cycle.
:param extra_dependencies: a sequence of 2-tuples of tables which will
also be considered as dependent on each other.
.. versionadded:: 1.0.0
.. seealso::
:func:`.sort_tables`
NTc3s|]}|<00>fVqdS)Nr)rJ<00>parent)rvrr<00> <genexpr>'sz.sort_tables_and_constraints.<locals>.<genexpr>Zdeterministic_orderrcs4g|]*}<00>dks*<00>|<00>dk r|<00>qS)NFr)rJr<>)r<>rrrL6s z/sort_tables_and_constraints.<locals>.<listcomp>cs(g|]}||jj<00><00>f<00>qSr)<02>foreign_key_constraints<74>
difference)rJrv)<01>remaining_fkcsrrrLEs )r4<00>updater<65>Z use_alter<65>addZreferred_tableZ_extra_dependenciesr3r <00>sortrCr r<>r<><00>discard) rnr<>r<>Zfixed_dependenciesZmutable_dependenciesr<73><00>filteredZ dependent_onZcandidate_sort<72>errZedgeZ
can_remover)r<>r<>rvrr<><00>sT*            ! 
    !r<>)"rBr%rr<>r<00>baserrrrr r
r r rrErRrVrYr[r`r\rarbrcrdrerfrjrkrlr<>r<>r<>rrrr<00><module> s6"<19>
o  z<16><