U of@L@sddlmZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&ddl#m'Z'ddl#m(Z(dd l)m*Z*dd!l+m,Z,erJdd"lm-Z-dd#lm.Z.dd$lm/Z/dd%lm0Z0dd&lm1Z1dd'lm2Z2dd(l3m4Z4dd)l!m5Z5dd*l6m7Z7dd+l8m9Z9dd,l#m:Z:dd-l;mm?Z?dd0l>m@Z@ed1ed2d3ZAGd4d5d5e ZBd6d7d8d9d:ZCeDd;d<eEd=eDZFeFd>kZGeFd?kZHeFd@kZIeFdAkZJeFdBkZKeZLzddClMmNZNWn"eOk rddCl#mNZNYnXGdDdEdEZPerdFd6dGdHdIdJZQn ddKlRmQZQzddLlmSZSWn4eOk rles`GdMdNdNePZSdOZTdOZUYnXdPZTeFdQkZUzddRlmVZVWn0eOk resGdSdTdTePZVdOZWYn$XeXeVe"ZYddUdVdWdXdYdZZZdPZWeKrdd[l!m[Z[n dd\l\m]Z[ede^e[fZ_ee^e[fZ`d]d^d_d`daZad]dbd_dcddZbd]ded_dfdgZcdhZdejedidjdkdldmZfddndoZgdpdqdkdrdsZhdpdtdkdudvZidpdtdkdwdxZjdidVdkdydzZkd{d|d}d~dZld1d1dddZmdpddkddZnddddZodpd6ddVdddZpddZqddZrdVdddZsdVdddZtdddddZuddZvdddtdddZwddZxeyejzdr|ddZ{ddZ|nddZ{ddZ|dddddZ}ddVdddZ~ddVdddZddZdddtdddZddddddZd1dd1dddZGdd„dej:ZeQeddd6dĜddƄZGddȄde$ZeQeddd6dĜddʄZddd͜ddτZdddedҜddԄZdddVdҜddׄZddVdٜddۄZdd݄ZdddddZeHrddlmZddlmZeZn"ddlmZddZddddZd{dVdddZddVdddZdS)) annotationsN)Any)Callable)Dict)Iterable)Iterator)Mapping)Optional)Protocol)Set)Type) TYPE_CHECKING)TypeVar)Union) __version__)inspectschema)sql)types)url)CheckConstraint)Column)ForeignKeyConstraint)visitors) DialectKWArgs) BindParameter) ColumnClause) quoted_name) TextClause)UnaryExpression)traverse) TypeGuard) ClauseElement)Index)Table) Connection)Dialect) Transaction) Inspector)ColumnCollection) SQLCompiler)Insert) ColumnElement) Constraint) SchemaItem)Select) TableClause_CE)zColumnElement[Any]r/)boundc@s eZdZdddddddZdS)_CompilerProtocolrstr)elementcompilerkwreturncKsdSN)selfr6r7r8r;r;F/opt/hc_python/lib/python3.8/site-packages/alembic/util/sqla_compat.py__call__>z_CompilerProtocol.__call__N)__name__ __module__ __qualname__r>r;r;r;r=r4=sr4r5zUnion[int, str])valuer9cCs z t|WS|YSXdSr:)int)rCr;r;r= _safe_intAs rEcCsg|] }t|qSr;)rE).0xr;r;r= IsrHz (\d+|[abc]\d)))rI)rIrK)rIrK)) _NONE_NAMEc@seZdZdZdS) _Unsupportedz.Placeholder for unsupported SQLAlchemy classesN)r@rArB__doc__r;r;r;r=rPYsrPzType[ClauseElement]z0Callable[[_CompilerProtocol], _CompilerProtocol])r6dialectsr9cGsdSr:r;)r6rRr;r;r=compiles_srS)rS)Computedc@s eZdZdS)rTNr@rArBr;r;r;r=rTksrTFT)rIrJ)Identityc@s eZdZdS)rWNrUr;r;r;r=rWysrWz&Union[Identity, schema.Sequence, None]boolzDict[str, Any])identitydialect_kwargsr9csdkr iStr8}|rtts*t|jnHi}ttrdj|d<j dk rdj |d<d}|fdd|D|S)Nalwayson_null) start incrementZminvalueZmaxvalueZ nominvalueZ nomaxvaluecyclecacheordercs*i|]"}t|ddk r|t|dqSr:)getattrrFkeyrYr;r= sz._get_identity_options_dict..) identity_has_dialect_kwargsZ_as_dict isinstancerAssertionErrorupdaterZrWr[r\)rYrZas_dictattrsr;rer=_get_identity_options_dicts&      rm) _NoneName)symbol_ConstraintNamez!TypeGuard[_ConstraintNameDefined])namer9cCs|tkpt|ttfSr:)rOrhr5rnrqr;r;r=constraint_name_definedsrszTypeGuard[str]cCs t|tSr:)rhr5rrr;r;r=constraint_name_stringsrtz Optional[str]cCst|r |SdSr:)rtrrr;r;r=constraint_name_or_nonesruautozOptional[Connection]zIterator[None]) connectionr9c cslz |j}Wntk r"d}YnX|dkr4dVn4|sb|dk sFt| dVW5QRXndVdSr:)in_transactionAttributeErrorribeginrwrxr;r;r=_ensure_scope_for_ddls   r|cCs tr|j|dS|j|dSdS)N) hide_password)sqla_14Zrender_as_stringZ __to_string__)rr}r;r;r=url_render_as_strings rr&r(cCst|}|r|S|SdSr:)_get_connection_transactionrzrwZ transactionr;r;r="_safe_begin_connection_transactionsrNonecCst|}|r|dSr:)rcommitrr;r;r=#_safe_commit_connection_transactionsrcCst|}|r|dSr:)rrollbackrr;r;r=%_safe_rollback_connection_transactionsrcCs,z |j}Wntk r YdSX|SdS)NF)rxryr{r;r;r=_get_connection_in_transactions  rr$zIterable[ColumnElement[Any]])idxr9cCs|jSr:) expressions)rr;r;r=_idx_table_bound_expressions sr) schema_itemr9cKs&t|dr|jf|S|jf|SdS)N_copy)hasattrrcopy)rr8r;r;r=rs  rzOptional[Transaction]cCstr |S|j}|jSdSr:)r~Zget_transaction_rootZ_Connection__transaction)rwrr;r;r=rsrzurl.URL)r9cOs*ttjdrtjj||Stj||SdS)Ncreate)rrURLr)argr8r;r;r= _create_url s rzUnion[str, None]) connectable tablename schemanamer9cCs(trt|||S|j|||SdSr:)r~rZ has_tabledialect)rrrr;r;r=_connectable_has_table'src Ks@tr.|}|||W5QRSQRXn|j||SdSr:)r~Z_operation_contextexecutebind) inspectorZ statementparamsconnr;r;r=_exec_on_inspector2s  rcCs&ts |jSddlm}|j|jkSdS)Nrr)r~Znullablesqlalchemy.sqlrZ_user_defined_nullableZNULL_UNSPECIFIED)Zmetadata_columnrr;r;r=_nullability_might_be_unset:s   rcGstsdStdd|DSdS)NFcss|]}t|tVqdSr:)rhrTrFsdr;r;r= Isz._server_default_is_computed..) has_computedanyZserver_defaultr;r;r=_server_default_is_computedEsrcGstsdStdd|DSdS)NFcss|]}t|tVqdSr:)rhrWrr;r;r=rPsz._server_default_is_identity..)r~rrr;r;r=_server_default_is_identityLsrr.r%) constraintr9cCs*t|tr |j}|dk st|S|jSdSr:)rhrparentritable)rrr;r;r=_table_for_constraintSs   rcCs<t|trdd|jDSt|tr.t|jSt|jSdS)NcSsg|] }|jqSr;)r)rFZfkr;r;r=rH^sz+_columns_for_constraint..)rhrelementsr _find_columnsZsqltextlistcolumnsrr;r;r=_columns_for_constraint\s    rr))rrr9cCs tr||dS||dSdSr:)r~Z reflect_tableZ reflecttable)rrr;r;r=_reflect_tablees  rcCs*t|r"t|\}}||j|S|SdSr:)_type_has_variants_get_variant_mappinggetrq)type_rZ base_typemappingr;r;r=_resolve_for_variantns r_variant_mappingcCs t|jSr:)rXrrr;r;r=rxsrcCs ||jfSr:)rrr;r;r=r{srcCst|tjkSr:)typesqltypesZVariantrr;r;r=rscCs |j|jfSr:)implrrr;r;r=rsrrc str0jdk stjdk s ttjts0tfddjD}jj}jj }jdj j j }jdj j j}ddjD}j }j }j} j} ||||||||| | f S)Ncsg|]}j|jqSr;)rrqrcrr;r=rHsz_fk_spec..rcSsg|] }|jjqSr;)columnrq)rFr6r;r;r=rHs)r rrirrhrr%Z column_keysrqrrrondeleteonupdate deferrable initially) rZsource_columnsZ source_tableZ source_schemaZ target_schema target_tableZtarget_columnsrrrrr;rr=_fk_specs6 rcCsF|jd}|d}|dd|}|jdk s:t||jjkS)Nr.)rZ _get_colspecsplitpopjoinrrird)rspectokensZtablekeyr;r;r=_fk_is_self_referentials    rcCs|jSr:)Z _type_boundrr;r;r=_is_type_boundsrcCst}t|id|ji|S)z2locate Column objects within the given expression.r)setr!add)Zclausecolsr;r;r=rsrr*z%Union[Column[Any], ColumnClause[Any]]) collectionrr9cCsH|jdk st||j}t|ds,t|dr:|j|n ||dS)z(remove a column from a ColumnCollection.NZ _immutableZ _readonly)rdrirZ_parentremove)rrZ to_remover;r;r=_remove_column_from_collections  rz*Union[str, TextClause, ColumnElement[Any]]z&Union[ColumnElement[Any], Column[Any]])rtext_r9cCspt|tr$t|tj}|||St|tr8t||St|trNt||j St|t j rdt ||St ddS)zAa workaround for the Index construct's severe lack of flexibilityz#String or text() construct expectedN)rhr5rrNULLTYPE append_columnr_textual_index_element_textual_index_columntextrr-_copy_expression ValueError)rrcr;r;r=rs         r) expressionrr9csfdd}t|i|S)NcsVt|trN|jdk rN|jk rN|jjkr6j|jSt|}||SndSdSr:)rhrrrqrrr)colrrr;r=replaces   z!_copy_expression..replace)rZreplacement_traverse)rrrr;rr=rs  rc@s.eZdZdZdZddddddZd d Zd S) raQWrap around a sqlalchemy text() construct in such a way that we appear like a column-oriented SQL expression to an Index construct. The issue here is that currently the Postgresql dialect, the biggest recipient of functional indexes, keys all the index expressions to the corresponding column expressions when rendering CREATE INDEX, so the Index we create here needs to have a .columns collection that is the same length as the .expressions collection. Ultimately SQLAlchemy should support text() expressions in indexes. See SQLAlchemy issue 3174. Z_textual_idx_elementr%rr)rrr9cCs8||_||_|j|_t|jjtj|_||jdSr:) rrrdrrrr fake_columnr)r<rrr;r;r=__init__ s z_textual_index_element.__init__cCs|jgSr:)r)r<r;r;r= get_childrensz#_textual_index_element.get_childrenN)r@rArBrQZ__visit_name__rrr;r;r;r=rsrr+)r6r7r9cKs|j|jf|Sr:)processrr6r7r8r;r;r=_render_textual_index_columnsrc@s eZdZdS)_literal_bindparamNrUr;r;r;r=rsrcKs|j|f|Sr:)Zrender_literal_bindparamrr;r;r=_render_literal_bindparam!srrr)rr9cCstr |jSiSdSr:)sqla_13kwargs)rr;r;r=_column_kwargs(srzUnion[Index, Constraint]zOptional[Dialect])rrr9cCs|jdkrdS|dk sttr.|jj|ddSt|jdrFt|j}nt}|t|jdd}|j |d}t |t j r| |d}||S|j|SdS)NFZ_alembic_quotequote)rrr)rqrir~identifier_preparerformat_constraintrrrr5 __class__rhrr$Z ddl_compilerZ_prepared_index_name)rrZquoted_name_clsnew_namedr;r;r=_get_constraint_final_name/s"        rzUnion[Constraint, Index]cCsDtr6|jdkrdS|dk st|jj|dd}|dk S|jdk SdS)NFr)r~rqrirr)rrrqr;r;r=_constraint_is_namedTs  rr') mysql_dialectr9cCstr |jSt|jo|jSdSr:)r~Z is_mariadbrXZserver_version_info _is_mariadbrr;r;r=rcs rcCs|jSr:) _mariadb_normalized_version_inforr;r;r=rmsrzUnion[TableClause, Table]r,)rr9cCs tr|S|jddSdS)NT)inline)r~insertr)rr;r;r=_insert_inlineqs r)create_mock_engine)select create_enginecKstdd|dS)Nz postgresql://Zmock)Zstrategyexecutorr)rrr8r;r;r=rs rr0cOstjt|f|Sr:)rrr)rr8r;r;r=_selectsr)indexr9cCs|jD]}t|rdSqdSNTF)r is_expression)rexprr;r;r=is_expression_indexs r )rr9cCs*t|tr|j}qt|tr"|jr&dSdSr)rhr r6rZ is_literal)rr;r;r=rs  r)F)T) __future__r contextlibretypingrrrrrrr r r r r rrZ sqlalchemyrrrrrrZsqlalchemy.enginerZsqlalchemy.schemarrrrrZsqlalchemy.sql.baserZsqlalchemy.sql.elementsrrrrr Zsqlalchemy.sql.visitorsr!typing_extensionsr"r#r$r%r&r'r(Zsqlalchemy.engine.reflectionr)r*Zsqlalchemy.sql.compilerr+Zsqlalchemy.sql.dmlr,r-Zsqlalchemy.sql.schemar.r/Zsqlalchemy.sql.selectabler0r1r2r4rEtuplefindallZ_versrr~Z sqla_14_18Z sqla_14_26Zsqla_2Zsqlalchemy_versionZsqlalchemy.sql.namingrO ImportErrorrPrSZsqlalchemy.ext.compilerrTrZhas_computed_reflectionrWZ has_identity issubclassrgrmrnZsqlalchemy.utilror5rpZ_ConstraintNameDefinedrsrtruZAUTOINCREMENT_DEFAULTcontextmanagerr|rrrrrrrrrrrrrrrrrrrZ TypeEnginerrrrrrrrrrrrrrrrrrrrrZ _sa_selectrrr rr;r;r;r=s,                                                   '            ! %