L iydZddlmZddlZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZej<r`ddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&dd l#m'Z'dd!l#m(Z(dd l#m Z dd"l#m)Z)dd#l*m+Z+dd$l,m-Z-dd%l.m/Z/dd&l.m0Z0dd'l.m1Z1dd(l.m2Z2ed)ed*e3f+Z4Gd,d-eZ5Gd.d/eZ6Gd0d1ejnZ8Gd2d3ejree5Z:e:Z; Gd4d5e:Z<Gd6d7e:ee4Z=Gd8d9e=e4Z>Gd:d;e=e4Z?Gd<d=e>e3Z@Gd>d?e?e3ZAGd@dAe>dBZBGdCdDe?dBZCGdEdFe5ZDGdGdHe5ZEGdIdJe?dBZFGdKdLe>dMZGGdNdOe?dMZHGdPdQe>dRZIGdSdTe?dRZJGdUdVe>dWZKGdXdYe?dWZLGdZd[e=dBZMGd\d]e=dBZNGd^d_e=d`ZOGdadbe=d`ZPGdcdde=dWZQGdedfe=dWZRGdgdheZSGdidjeSZTGdkdleSZUGdmdneTZVGdodpeUZW ds dtdqZX dudrZYy)vzq Provides the hierarchy of DDL-defining schema items as well as routines to invoke them for a create/drop call. ) annotationsN)Any)Callable)Generic)Iterable)List)Optional)Sequence)Tuple)TypeVar)Union)roles) _generative) Executable) SchemaVisitor) ClauseElement)exc)util) topological)Protocol)Self)Compiled) DDLCompiler) BindParameter)Column) Constraint)ForeignKeyConstraint)Index) SchemaItem)Table) TableClause) Connection) CacheStats)CompiledCacheType)Dialect)SchemaTranslateMapType_SIr!)boundcFeZdZdZdZ dZddd ddZy)BaseDDLElementzThe root of DDL constructs, including those that are sub-elements within the "create table" and other processes. .. versionadded:: 2.0 Fc *|j||fi|S)zNReturn a compiler appropriate for this ClauseElement, given a Dialect.) ddl_compiler)selfdialectkws X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/sql/ddl.py _compilerzBaseDDLElement._compilerHs$w##GT8R88N)for_executemanyschema_translate_mapc tNNotImplementedError)r/r0compiled_cache column_keysr5r6r1s r2_compile_w_cachezBaseDDLElement._compile_w_cacheNs "##r4)r0r'r;zOptional[CompiledCacheType]r<z List[str]r5boolr6z Optional[SchemaTranslateMapType]r1rreturnzJTuple[Compiled, Optional[typing_Sequence[BindParameter[Any]]], CacheStats])__name__ __module__ __qualname____doc___hierarchy_supports_cachingr3r=r4r2r,r,=sh#(B9!&AE $ $4 $  $  $? $ $  $r4r,cBeZdZ ddd ddZy) DDLIfCallableN.)compilercyr8rE) r/ddltargetbindtablesstater0rH checkfirsts r2__call__zDDLIfCallable.__call__^sr4NN)rJr,rKUnion[SchemaItem, str]rLOptional[Connection]rMzOptional[List[Table]]rN Optional[Any]r0r'rHOptional[DDLCompiler]rOr>r?r>)r@rArBrPrEr4r2rGrG]sq )-# +.   ' #  &    (    r4rGcNeZdZUded<ded<ded< d d dZy) DDLIf Optional[str]r0Optional[DDLIfCallable] callable_rTrNNc | |j}n| |j}nJdt|jtr|j|jk7r?yt|jtt t fr|j|jvry|j$|j|||f|j||d|syy)NFzcompiler or dialect is required)rNr0rHT) r0 isinstancestrnametuplelistsetrZrN)r/rJrKrLrHr1r0s r2_should_executezDDLIf._should_executeqs  llG  !&&G ;; ;5 dllC (||w||+  udC&8 9||4<</ >> %ndnn   / ** / / r4r8) rJr,rKrRrLrSrHrUr1rr?r>)r@rArB__annotations__rbrEr4r2rWrWlsX && +/   ' #  (     r4rWceZdZUdZdZded<dZded<dZeddZ e d dd Z d Z d Z d Z d Zy)ExecutableDDLElementaBase class for standalone executable 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. .. versionchanged:: 2.0 :class:`.ExecutableDDLElement` is renamed from :class:`.DDLElement`, which still exists for backwards compatibility. :class:`.ExecutableDDLElement` 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` NzOptional[DDLIf]_ddl_ifzUnion[SchemaItem, str, None]rKc(|j|||Sr8) _execute_ddl)r/ connectiondistilled_paramsexecution_optionss r2_execute_on_connectionz+ExecutableDDLElement._execute_on_connections && "$5  r4c||_|S)aReturn a copy of this :class:`_schema.ExecutableDDLElement` which will include the given target. This essentially applies the given item to the ``.target`` attribute of the returned :class:`_schema.ExecutableDDLElement` object. This target is then usable by event handlers and compilation routines in order to provide services such as tokenization of a DDL string in terms of a particular :class:`_schema.Table`. When a :class:`_schema.ExecutableDDLElement` object is established as an event handler for the :meth:`_events.DDLEvents.before_create` or :meth:`_events.DDLEvents.after_create` events, and the event then occurs for a given target such as a :class:`_schema.Constraint` or :class:`_schema.Table`, that target is established with a copy of the :class:`_schema.ExecutableDDLElement` object using this method, which then proceeds to the :meth:`_schema.ExecutableDDLElement.execute` method in order to invoke the actual DDL instruction. :param target: a :class:`_schema.SchemaItem` that will be the subject of a DDL operation. :return: a copy of this :class:`_schema.ExecutableDDLElement` with the ``.target`` attribute assigned to the given :class:`_schema.SchemaItem`. .. seealso:: :class:`_schema.DDL` - uses tokenization against the "target" when processing the DDL string. )rK)r/rKs r2againstzExecutableDDLElement.againstsB  r4c*t||||_|S)aA Return a callable that will execute this :class:`_ddl.ExecutableDDLElement` conditionally within an event handler. 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 or tuple of strings. 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 three positional arguments as well as optional keyword arguments: :ddl: This DDL element. :target: The :class:`_schema.Table` or :class:`_schema.MetaData` object which is the target of this event. May be None if the DDL is executed explicitly. :bind: The :class:`_engine.Connection` being used for DDL execution. May be None if this construct is being created inline within a table, in which case ``compiler`` will be present. :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. :dialect: keyword argument, but always present - the :class:`.Dialect` involved in the operation. :compiler: keyword argument. Will be ``None`` for an engine level DDL invocation, but will refer to a :class:`.DDLCompiler` if this DDL element is being created inline within a table. :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:: :meth:`.SchemaItem.ddl_if` :class:`.DDLEvents` :ref:`event_toplevel` )rWrf)r/r0rZrNs r2 execute_ifzExecutableDDLElement.execute_ifsfWi7  r4c Z|jy|jj|||fi|SNT)rfrbr/rKrLr1s r2rbz$ExecutableDDLElement._should_execute9s/ << /4<<//fdIbI Ir4c^|j|j|r|j|Syr8)rbrKexecute)r/rLs r2 _invoke_withz!ExecutableDDLElement._invoke_with?s*    T 2<<% % 3r4c D|j|j|y)z"Execute the DDL as a ddl_listener.N)rnrvrss r2rPzExecutableDDLElement.__call__Cs V))$/r4c|jj|j}|jj|_|Sr8) __class____new____dict__copy)r/ss r2 _generatezExecutableDDLElement._generateHs3 NN " "4>> 2]]'') r4)rKr!r?r)NNN)r0rXrZrYrNrTr?r)r@rArBrCrfrcrKrlrrnrprbrvrPr~rEr4r2reres@ $G_#+/F (/ !!F"&-1# SS+S S  SSjJ &0 r4rec"eZdZdZdZddZdZy)DDLaZA 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:`_schema.Table` or :class:`_schema.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 substitutions are available: .. sourcecode:: text %(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. rJNcxt|tstjd|z||_|xsi|_y)aCreate a DDL statement. :param statement: A string or unicode string to be executed. Statements will be processed with Python's string formatting operator using a fixed set of string substitutions, as well as additional substitutions provided by the optional :paramref:`.DDL.context` parameter. A literal '%' in a statement must be escaped as '%%'. SQL bind parameters are not available in DDL statements. :param context: Optional dictionary, defaults to None. These values will be available for use in string substitutions on the DDL statement. .. seealso:: :class:`.DDLEvents` :ref:`event_toplevel` z4Expected a string or unicode SQL statement, got '%r'N)r\r]r ArgumentError statementcontext)r/rrs r2__init__z DDL.__init__zs@4)S)##F  #}" r4ct|jg}|jr|jd|jdt |j dt |ddj|dS)Nzcontext=<@z; , >)reprrrappendtyper@idjoin)r/partss r2__repr__z DDL.__repr__s^dnn%& << LL8DLL>2 3 J   tH IIe   r4r8)r@rArBrC__visit_name__rrrEr4r2rrRs#JN!%F  r4rc:eZdZUdZded<ddZedZdZy) _CreateDropBasezBase 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. r)elementcD|x|_|_t|dd|_y)Nrf)rrKgetattrrfr/rs r2rz_CreateDropBase.__init__s %,, t{w 48 r4cft|jtrJ|jjSr8)r\rr]create_drop_stringify_dialect)r/s r2stringify_dialectz!_CreateDropBase.stringify_dialects&dllC000||999r4cy)zAllow disable of _create_rule using a callable. Pass to _create_rule using util.portable_instancemethod(self._create_rule_disable) to retain serializability. FrE)r/rHs r2_create_rule_disablez$_CreateDropBase._create_rule_disablesr4N)rr)r?None) r@rArBrCrcrpropertyrrrEr4r2rrs,L9::r4rc"eZdZddfd ZxZS) _CreateBasec2t||||_yr8)superr if_not_existsr/rrrys r2rz_CreateBase.__init__s !*r4F)rr)rr>r?rr@rArBr __classcell__rys@r2rrs ++r4rc"eZdZddfd ZxZS) _DropBasec2t||||_yr8)rr if_existsr/rrrys r2rz_DropBase.__init__s !"r4r)rr)rr>r?rrrs@r2rrs ##r4rc:eZdZdZdZdZ d dfd ZxZS) CreateSchemazcRepresent a CREATE SCHEMA statement. The argument here is the string name of the schema. create_schemadefaultc(t|||y)z.Create a new :class:`.CreateSchema` construct.)rrNrr)r/r^rrys r2rzCreateSchema.__init__s ]Cr4r)r^r]rr>r?rr@rArBrCrrrrrs@r2rrsE %N! $DDD  DDr4rc@eZdZdZdZdZ d dfd ZxZS) DropSchemazaRepresent a DROP SCHEMA statement. The argument here is the string name of the schema. drop_schemarc6t|||||_y)z,Create a new :class:`.DropSchema` construct.)rrN)rrcascade)r/r^rrrys r2rzDropSchema.__init__s ; r4)FF)r^r]rr>rr>r?rrrs@r2rrsM #N!        r4rc<eZdZdZdZ d dfd ZxZS) CreateTablez#Represent a CREATE TABLE statement. create_tablect||||jDcgc] }t|c}|_||_ycc}w)aCreate a :class:`.CreateTable` construct. :param element: a :class:`_schema.Table` that's the subject of the CREATE :param on: See the description for 'on' in :class:`.DDL`. :param include_foreign_key_constraints: optional sequence of :class:`_schema.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. :param if_not_exists: if True, an IF NOT EXISTS operator will be applied to the construct. .. versionadded:: 1.4.0b2 rN)rrcolumns CreateColumninclude_foreign_key_constraints)r/rrrcolumnrys r2rzCreateTable.__init__s@0  >;B??K V,K /N,LsANF)rr"rz/Optional[typing_Sequence[ForeignKeyConstraint]]rr>r?rr@rArBrCrrrrs@r2rrsI-#N # OO* O  O OOr4rr"ceZdZdZdZy) _DropViewzSemi-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. drop_viewNr@rArBrCrrEr4r2rr#s!Nr4rc eZdZUded<ddZy)CreateConstraintrrc||_yr8rrs r2rzCreateConstraint.__init__1  r4N)rrr?r)r@rArBrcrrEr4r2rr.s r4rc(eZdZUdZdZded<ddZy)raRepresent a :class:`_schema.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:`_schema.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:`_schema.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:`_schema.Column.info` collection will be detected by our custom compilation scheme: .. sourcecode:: sql 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:`_schema.Column`, which marks a column as an implicitly-present "system" column. For example, suppose we wish to produce a :class:`_schema.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. create_column Column[Any]rc||_yr8rrs r2rzCreateColumn.__init__rr4N)rrr?r)r@rArBrCrrcrrEr4r2rr5sl\%N r4rc*eZdZdZdZddfd ZxZS) DropTablez!Represent a DROP TABLE statement. drop_tablec(t|||y)aVCreate a :class:`.DropTable` construct. :param element: a :class:`_schema.Table` that's the subject of the DROP. :param on: See the description for 'on' in :class:`.DDL`. :param if_exists: if True, an IF EXISTS operator will be applied to the construct. .. versionadded:: 1.4.0b2 rNrrs r2rzDropTable.__init__s I6r4r)rr"rr>r?rrrs@r2rrs+!N 7 7r4rceZdZdZdZy)CreateSequencez&Represent a CREATE SEQUENCE statement.create_sequenceNrrEr4r2rrs 0&Nr4rr ceZdZdZdZy) DropSequencez$Represent a DROP SEQUENCE statement. drop_sequenceNrrEr4r2rrs .$Nr4rc*eZdZdZdZddfd ZxZS) CreateIndexz#Represent a CREATE INDEX statement. create_indexc(t|||y)a Create a :class:`.Createindex` construct. :param element: a :class:`_schema.Index` that's the subject of the CREATE. :param if_not_exists: if True, an IF NOT EXISTS operator will be applied to the construct. .. versionadded:: 1.4.0b2 rNrrs r2rzCreateIndex.__init__s  >r4r)rr rr>r?rrrs@r2rrs-#N ? ?r4rr c*eZdZdZdZddfd ZxZS) DropIndexz!Represent a DROP INDEX statement. drop_indexc(t|||y)aCreate a :class:`.DropIndex` construct. :param element: a :class:`_schema.Index` that's the subject of the DROP. :param if_exists: if True, an IF EXISTS operator will be applied to the construct. .. versionadded:: 1.4.0b2 rNrrs r2rzDropIndex.__init__s I6r4r)rr rr>r?rrrs@r2rrs+!N 7 7r4rc8eZdZdZdZdd dfdZxZS) AddConstraintz2Represent an ALTER TABLE ADD CONSTRAINT statement.add_constraintT)isolate_from_tablecrt|||r%tj|j|_yy)aLConstruct a new :class:`.AddConstraint` construct. :param element: a :class:`.Constraint` object :param isolate_from_table: optional boolean, defaults to True. Has the effect of the incoming constraint being isolated from being included in a CREATE TABLE sequence when associated with a :class:`.Table`. .. versionadded:: 2.0.39 - added :paramref:`.AddConstraint.isolate_from_table`, defaulting to True. Previously, the behavior of this parameter was implicitly turned on in all cases. N)rrrportable_instancemethodr _create_rule)r/rrrys r2rzAddConstraint.__init__s6* ! #'#?#?))$G  r4)rrrr>r?rrrs@r2rrs6<%N $( !   r4rrcHeZdZdZdZdddd dfdZxZS)DropConstraintz3Represent an ALTER TABLE DROP CONSTRAINT statement.drop_constraintFT)rrrc ||_t||fd|i||r%tj|j |_yy)a`Construct a new :class:`.DropConstraint` construct. :param element: a :class:`.Constraint` object :param cascade: optional boolean, indicates backend-specific "CASCADE CONSTRAINT" directive should be rendered if available :param if_exists: optional boolean, indicates backend-specific "IF EXISTS" directive should be rendered if available :param isolate_from_table: optional boolean, defaults to True. Has the effect of the incoming constraint being isolated from being included in a CREATE TABLE sequence when associated with a :class:`.Table`. .. versionadded:: 2.0.39 - added :paramref:`.DropConstraint.isolate_from_table`, defaulting to True. Previously, the behavior of this parameter was implicitly turned on in all cases. rN)rrrrrrr)r/rrrrr1rys r2rzDropConstraint.__init__sG6  rr>rr>r1rr?rrrs@r2rrsZ=&N #' !! !  ! ! !! !!r4rceZdZdZdZy)SetTableCommentz*Represent a COMMENT ON TABLE IS statement.set_table_commentNrrEr4r2rr=s 4(Nr4rceZdZdZdZy)DropTableCommentzfRepresent a COMMENT ON TABLE '' statement. Note this varies a lot across database backends. drop_table_commentNrrEr4r2rrCs *Nr4rceZdZdZdZy)SetColumnCommentz+Represent a COMMENT ON COLUMN IS statement.set_column_commentNrrEr4r2rrMs 5)Nr4rrceZdZdZdZy)DropColumnCommentz0Represent a COMMENT ON COLUMN IS NULL statement.drop_column_commentNrrEr4r2rrSs :*Nr4rceZdZdZdZy)SetConstraintCommentz/Represent a COMMENT ON CONSTRAINT IS statement.set_constraint_commentNrrEr4r2rrYs 9-Nr4rceZdZdZdZy)DropConstraintCommentz4Represent a COMMENT ON CONSTRAINT IS NULL statement.drop_constraint_commentNrrEr4r2rr_s >.Nr4rc6eZdZdZej dZy) InvokeDDLBasec F||_|rJd|jy)NzUnexpected keywords: )rikeys)r/rir1s r2rzInvokeDDLBase.__init__fs&$:.rwwyk::v2r4c t)dhelper context manager that will apply appropriate DDL events to a CREATE or DROP operation.r9r/rKr1s r2with_ddl_eventszInvokeDDLBase.with_ddl_eventsjs "##r4N)r@rArBr contextlibcontextmanagerr rEr4r2rres!;$$r4rc0eZdZejdZy)InvokeCreateDDLBasec+K|jj||jfd|i|d|jj||jfd|i|ywr _ddl_runnerN)dispatch before_createri after_creater s r2r z#InvokeCreateDDLBase.with_ddl_eventsssg &%% DOO 15 9;  $$$ DOO 15 9; AANr@rArBr r r rEr4r2rrr    r4rc0eZdZejdZy)InvokeDropDDLBasec+K|jj||jfd|i|d|jj||jfd|i|ywr)r before_dropri after_dropr s r2r z!InvokeDropDDLBase.with_ddl_eventssg $## DOO 15 9;  """ DOO 15 9; rNrrEr4r2rrrr4rc^eZdZ d fd ZdZdZdZdZ d dZdZ d dZ d d Z xZ S) SchemaGeneratorc t||fi|||_||_|j|_||_i|_yr8rrrOrMidentifier_preparerpreparerr0memor/r0rirOrMkwargsrys r2rzSchemaGenerator.__init__@ .v.$ 33   r4c@|jj|j|jj |}|r|jj||j xs3|jj |j|j| SN)schemar0validate_identifierr^rischema_for_objectrO has_tabler/tableeffective_schemas r2_can_create_tablez!SchemaGenerator._can_create_tables ((4??<??" $,,*@*@ OOUZZ0@+A+ '  r4c4|jj|j}|r|jj ||j xsH|jj |j|jj|j| Sr(rir,r/r0r+rO has_indexr^r/indexr0s r2_can_create_indexz!SchemaGenerator._can_create_indexs??<??" $,,*@*@ OO KK   JJ# +A+ '  r4c<|jj|}|jjxrj|jj xs |j xrB|j xs3|jj|j|j| Sr( rir,r0supports_sequencessequences_optionaloptionalrO has_sequencer^r/sequencer0s r2_can_create_sequencez$SchemaGenerator._can_create_sequences??<   ! ! #9" (   -- 9>>-((8 9<<..26/ 3  l4??+ui("]]@E(($(?@ .. 44==,#E*77H#mmOF~~1(0==dooNO<<<<&+&7&7 %--9 OO33 4Z @I( ( ( sGDGAG+&GG#c|jjsy|j|5t|j |j dddy#1swYyxYwr8)r0rWr rrvrir/r^s r2visit_foreign_key_constraintz,SchemaGenerator.visit_foreign_key_constraintsP||**   ! !* - D * % 2 24?? C D D D %AA c|s|j|sy|j|5t|j|jdddy#1swYyxYwr8)r@r rrvri)r/r?rDs r2visit_sequencezSchemaGenerator.visit_sequencesS!:!:8!D   ! !( + C 8 $ 1 1$// B C C C %AAc|s|j|sy|j|5t|j|jdddy#1swYyxYwr8)r7r rrvri)r/r6rDs r2 visit_indexzSchemaGenerator.visit_index#sO!7!7!>   ! !% ( =   + +DOO < = = =rfFN)FNFr) r@rArBrr1r7r@rSr_rbrerhrrs@r2rrsB<@     $2R(,$ 2hDC =r4rc^eZdZ d fd ZdZdZdZdZd dZ d dZ dZ d d Z xZ S) SchemaDropperc t||fi|||_||_|j|_||_i|_yr8r r$s r2rzSchemaDropper.__init__+r&r4c8j j}n#t|jj} |Dcgc]}j|s|}}tt t |fd}|j$jDcgc]}j'|r|}}|D cgc] \}} | | } }} j)|| j* 5|D]5\} } | j-| d d | | D]} j-| 7|D]!}j-||j.du # dddycc}w#t j$r}jjsptjddjt|jDcgc]}|jncc}wc}zDcgc]}|dfncc}w}}n~t j|j d|j|j"ddjt|jDcgc]}|jncc}wc}z|Yd}~d}~wwxYwcc}wcc} }w#1swYyxYw) NcPjjr |jdSdSr)r0rWr^)r^r/s r2z.SchemaDropper.visit_metadata..As.#'<<#>#>)6""& r4) filter_fna4Can'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.rrErzCan'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.)msgrBT)drop_okrE_ignore_sequences)rr)rMr`rF_can_drop_tablereversedrGrCircularDependencyErrorr0rWrwarnrsortedcyclesfullnameargsedgesrH_can_drop_sequencer rOrIr)r/rJrMrKunsorted_tablesrLerr2r}rMrNrOr/rQrRrPs` r2rSzSchemaDropper.visit_metadata5s ;; "[[F(//0023F* *0LQD4H4H4KqLOL/'#  JX((//1 &&q)   /9J(1cAMAJJ  ! ! #"  F * 2 t$(( $/3*2 ) $2,,S12 2  F$$S#**2D$E F# F FgM** <<.. 3yyT[[(I(I(I!JKM 0??!q"g?? ?11IIaLKKJJ'yyT[[(I(I(I!JKM  @ : K F FstEEE$EJ? J  J /A!JEJ3AI=7G  I=% G10AI= II==JJc>|jj|j|jj |}|r|jj||j xs2|jj |j|j|Sr(r*r.s r2rtzSchemaDropper._can_drop_tables} ((4??<??" dll&<&< OOUZZ0@'='  r4c2|jj|j}|r|jj ||j xsG|jj |j|jj|j|Sr(r3r5s r2_can_drop_indexzSchemaDropper._can_drop_indexsy??<??" dll&<&< OO KK   JJ# '='  r4c:|jj|}|jjxri|jj xs |j xrA|j xs2|jj|j|j|Sr(r9r>s r2r}z SchemaDropper._can_drop_sequences??<E Ar4rkcp||fd}nd}t|||dDcgc] \}}|| c}}Scc}}w)a Sort a collection of :class:`_schema.Table` objects based on dependency. This is a dependency-ordered sort which will emit :class:`_schema.Table` objects such that they will follow their dependent :class:`_schema.Table` objects. Tables are dependent on another based on the presence of :class:`_schema.ForeignKeyConstraint` objects as well as explicit dependencies added by :meth:`_schema.Table.add_is_dependent_on`. .. warning:: The :func:`._schema.sort_tables` function cannot by itself accommodate automatic resolution of dependency cycles between tables, which are usually caused by mutually dependent foreign key constraints. When these cycles are detected, the foreign keys of these tables are omitted from consideration in the sort. A warning is emitted when this condition occurs, which will be an exception raise in a future release. Tables which are not part of the cycle will still be returned in dependency order. To resolve these cycles, the :paramref:`_schema.ForeignKeyConstraint.use_alter` parameter may be applied to those constraints which create a cycle. Alternatively, the :func:`_schema.sort_tables_and_constraints` function will automatically return foreign key constraints in a separate collection when cycles are detected so that they may be applied to a schema separately. .. versionchanged:: 1.3.17 - a warning is emitted when :func:`_schema.sort_tables` cannot perform a proper sort due to cyclical dependencies. This will be an exception in a future release. Additionally, the sort will continue to return other tables not involved in the cycle in dependency order which was not the case previously. :param tables: a sequence of :class:`_schema.Table` objects. :param skip_fn: optional callable which will be passed a :class:`_schema.ForeignKeyConstraint` 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:`_schema.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` :attr:`_schema.MetaData.sorted_tables` - uses this function to sort Nc<|jD] }|s yyrr)elements)rRfk fixed_skip_fns r2_skip_fnzsort_tables.._skip_fns&ll  $ r4T)rpextra_dependencies_warn_for_cycles)rG)rMskip_fnrrrKrQrs @r2 sort_tablesrs[B  5 1!    Q =    s2c t}t}||j|t}|D]jD]f}|jdur|j |#|r||}|dur|j |C|j } | usT|j | fh|jfdj D ttj|j||} | Dcgc]}||jj)|f!c}dt|fgzS#tj$r} |rBtjddjt!d| j"Dd| j$D]} | |vs| d| j"vrjDcgc]}| ||d ur|ncc}w} }|j| | D]&}|j } | us|j'| f(ttj|j||} Yd} ~ Wd} ~ wwxYwcc}w) aSort a collection of :class:`_schema.Table` / :class:`_schema.ForeignKeyConstraint` objects. This is a dependency-ordered sort which will emit tuples of ``(Table, [ForeignKeyConstraint, ...])`` such that each :class:`_schema.Table` follows its dependent :class:`_schema.Table` objects. Remaining :class:`_schema.ForeignKeyConstraint` objects that are separate due to dependency rules not satisfied by the sort are emitted afterwards as ``(None, [ForeignKeyConstraint ...])``. Tables are dependent on another based on the presence of :class:`_schema.ForeignKeyConstraint` objects, explicit dependencies added by :meth:`_schema.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:`_schema.Table` objects. :param filter_fn: optional callable which will be passed a :class:`_schema.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. .. seealso:: :func:`.sort_tables` NTc3&K|]}|f ywr8rE).0parentr/s r2 z.sort_tables_and_constraints..vs" &VUO" szLCannot correctly sort tables; there are unresolvable cycles between tables "rc34K|]}|jywr8)rz)rrKs r2rz.sort_tables_and_constraints..s#C1AJJ#Csz", which is usually caused by mutually dependent foreign key constraints. Foreign key constraints involving these tables will not be considered; this warning may raise an error in a future release.rF)raupdateforeign_key_constraints use_alteraddreferred_table_extra_dependenciesr`rsortunionrrvrrwrrxryr|discard difference)rMrprrfixed_dependenciesmutable_dependenciesremaining_fkcsrRfiltered dependent_oncandidate_sorterredge can_remover/s `r2rGrG0s\5%!!"45UN 00 @C}}$""3'$S>t#"&&s+--L5($((,)>? @ !!" */*C*C"  # *%    "(()=>  P$   --88HI  ^$ %& ''A  & &  II 99V#C #CCD G II LD++Q * %<< (IcN%,G  %%j1%LC##5L#50,44lE5JKL L   "(()=>  3 @ s8.D<$I!<IAI("I G .IAIIrQ)rMzIterable[TableClause]rz0Optional[Callable[[ForeignKeyConstraint], bool]]rz:Optional[typing_Sequence[Tuple[TableClause, TableClause]]]r?z List[Table])NNF)ZrC __future__rr typingrrrrrr r typing_Sequencer r r rbaserrrrrrrr util.typingrr TYPE_CHECKINGrHrrrr)rrrr r!r" selectabler# engine.baser$engine.interfacesr%r&r'r(r]r)r,rG NamedTuplerWDDLRolere DDLElementrrrrrrrrrrrrrrrrrrrrrrrrrrrrkrrGrEr4r2rs # .#" "%'",",'(.5+: e5s!234$]$@ H %F  %Pw5==*nwt" HT T n*GCL@+/#&+ #$# D;s#D*3.O+g&OD! '"!~t>tn7 '"7('[,' %9Z(% ?+g&?&7 '"7&K -D&Y|,&R)og.) *w/**}5* + 6+ .?<8. /OL9/ $M $  -     W=)W=tiA%iA\AE W !W =WW  WvGLt'r4