U of$@shddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l m Z dd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZe rVddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl"m#Z#ddl$m%Z%GdddZ&d S)!) annotations)Any)Dict)List)Optional)Sequence)Tuple) TYPE_CHECKING)Unionschema)Column) Constraint)Index)Integer)NULLTYPE)util) sqla_compat) ColumnElement) TextClause)CheckConstraint) ForeignKey)ForeignKeyConstraint)MetaData)PrimaryKeyConstraint)Table)UniqueConstraint) TypeEngine)MigrationContextc@seZdZddddddd d dd d d d dd ddZd?ddd d ddddZd@dddd ddddZdAddd d ddd d!Zd"d#d$d%Z dd&d'd(d)Z dd*d+d,d-d.Z dBd d d/d d0d1d2d3Z dd4d5d6d7Z d"d8dd9d:d;ZdS)C SchemaObjectsNzOptional[MigrationContext]None)migration_contextreturncCs ||_dSN)r")selfr"r&J/opt/hc_python/lib/python3.8/site-packages/alembic/operations/schemaobj.py__init__)szSchemaObjects.__init__z,Optional[sqla_compat._ConstraintNameDefined]strz Sequence[str]z Optional[str]r)name table_namecolsr r#c  sT|}dd|D}tj||f|d|itjfdd|Dd|i|}|S)NcSsg|]}t|tqSr& sa_schemar r.0nr&r&r' 7sz8SchemaObjects.primary_key_constraint..r csg|]}j|qSr&cr/tr&r'r2<sr*)metadatar.rr) r%r*r+r,r dialect_kwmcolumnspr&r5r'primary_key_constraint.sz$SchemaObjects.primary_key_constraintz List[str]zOptional[bool]r) r*sourcereferent local_cols remote_colsonupdateondelete deferrable source_schemareferent_schema initiallymatchr#c  s|}||kr"| | kr"||}n&|}tj||fdd|Dd| itj||fddt|Dd| i}| rd| |fn|| | d<tj|fdd|Df||||| d| }|||S) NcSsg|]}t|tqSr&r-r/r&r&r'r2Xsz8SchemaObjects.foreign_key_constraint..r cSsg|]}t|tqSr&r-r/r&r&r'r2_s%s.%srGcsg|]}d|fqS)rHr&r/tnamer&r'r2ps)r*rArBrCrF)r7r.rrZ unique_listrappend_constraint)r%r*r=r>r?r@rArBrCrDrErFrGr8r9Zt1_colst1fr&rIr'foreign_key_constraint@sR    z$SchemaObjects.foreign_key_constraintr)r*r=r?r r#c sVtj||fdd|Dd|i||d<tjfdd|D|}||S)NcSsg|]}t|tqSr&r-r/r&r&r'r2sz3SchemaObjects.unique_constraint..r r*csg|]}j|qSr&r3r/r5r&r'r2s)r.rr7rrK)r%r*r=r?r kwZuqr&r5r'unique_constraint|s  zSchemaObjects.unique_constraintz*Union[str, TextClause, ColumnElement[Any]]zUnion[CheckConstraint])r*r= conditionr r#cKsBtj||tdt|d}tj|fd|i|}|||S)Nxr r*)r.rr7r rrrK)r%r*r=rQr rOr6Zckr&r&r'check_constraints  zSchemaObjects.check_constraintr)r*r+type_r r#c Ks|j||d}ddtjtjddtjd}z ||}WnDtk r|} z&tddtdd |D| W5d} ~ XYnX||d }| ||SdS) Nr cSstjgg|dS)Nr*)r.rrUr&r&r'sz2SchemaObjects.generic_constraint..cSstjd|dS)NrU)r.rrUr&r&r'rV)Z foreignkeyprimaryuniquecheckNz'type' can be one of %sz, css|]}t|VqdSr$)repr)r0rRr&r&r' sz3SchemaObjects.generic_constraint..rU) tabler.rrrKeyError TypeErrorjoinsortedrK) r%r*r+rTr rOr6typesconstZker&r&r'generic_constraints(    z SchemaObjects.generic_constraintr)r#cCsFi}|jdk r:d|jjkr:|jjd}t|dr:|j|d<tjf|S)NZtarget_metadatanaming_convention)r"optshasattrrfr.r)r%rOmtr&r&r'r7s    zSchemaObjects.metadatar)r*r#c s|}dd|D}|dd}|r<|D]}d|_|_q*tj||f||fdd|D}|D]} | qfjD]} ||| q|S)NcSs.g|]&}t|tr|jdk r&t|n|qSr$) isinstancer r^r_copy)r0r4r&r&r'r2s z'SchemaObjects.table.._constraints_includedFcsLg|]D}t|ttfrt|ddk rDt|dddk rDtj|dn|qS)parentN)Z target_table)rjrrgetattrrrk)r0elemr5r&r'r2s) r7poprZindexr.rrKZ foreign_keys_ensure_table_for_fk) r%r*r:rOr9r,rlr4 constraintsrdrMr&r5r'r^s"     zSchemaObjects.tablerr )r*rTr#cKstj||f|Sr$)r.r )r%r*rTrOr&r&r'columnszSchemaObjects.columnz4Sequence[Union[str, TextClause, ColumnElement[Any]]]r)r* tablenamer:r r#c sDtj|p d||d|d<tj|ffdd|D|}|S)NZno_tabler _tablecsg|]}tj|qSr&)rrZ_textual_index_columnr/r5r&r'r2sz'SchemaObjects.index..)r.rr7r)r%r*rur:r rOidxr&r5r'rqszSchemaObjects.indexzTuple[Optional[str], str]) table_keyr#cCs>d|kr.|d}d|dd}|d}n|}d}||fS)N.r)splitra)r%rxtokenssnamerJr&r&r'_parse_table_key s  zSchemaObjects._parse_table_keyr)r7fkr#cCsrt|jtrn|jdd\}}||\}}||jkrHtj|||d}n |j|}||jkrn| t |t dS)zUcreate a placeholder Table object for the referent of a ForeignKey. ryr N) rjZ_colspecr)rsplitr~Ztablesr.rr4 append_columnr r)r%r7rrxcnamer}rJZrel_tr&r&r'rrs    z"SchemaObjects._ensure_table_for_fk)N)N)NNNNNNN)N)N)N)N)__name__ __module__ __qualname__r(r<rNrPrSrer7r^rtrqr~rrr&r&r&r'r (s2 (A ' r N)' __future__rtypingrrrrrrr r Z sqlalchemyr r.Zsqlalchemy.sql.schemar rrZsqlalchemy.typesrrrWrrZsqlalchemy.sql.elementsrrrrrrrrrZsqlalchemy.sql.type_apirZruntime.migrationrr r&r&r&r's: