U ofC@srddlmZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z d d l m Z d d l mZd d l mZd d l mZd dl mZd dl mZd dl mZd dl mZd dlmZddlmZddlmZddlmZddlmZddlmZerRddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&d dl m'Z'Gdd d eZ(Gd!d"d"e(Z)Gd#d$d$eZ*Gd%d&d&eZ+Gd'd(d(e+Z,eed)d*eed)d*eed)d*eed)d*d+d,Z-ee*d)d*d$d-d.d/d0d1Z.ee,d)d*d(d-d.d/d2d3Z/ee+d)d*d&d-d.d/d4d5Z0d-d6d7d8d6d9d.d:d;d<Z1ee j"d)d*d=d-d.d/d>d?Z2dS)@) annotationsN)Any)Optional) TYPE_CHECKING)Unionschema)types) alter_table) AlterColumn) ColumnDefault) ColumnName)ColumnNullable) ColumnType)format_column_name)format_server_default) DefaultImpl)util) sqla_compat) _is_mariadb)_is_type_bound)compiles)Literal)MySQLDDLCompiler)DropConstraint) Constraint) TypeEngine)_ServerDefaultcseZdZdZdZejddhddhfZddgZd$d d d d d dd ddd d d dd dddfdd Zdddfdd Z dd ddddZ ddZ d d!Z d"d#Z ZS)% MySQLImplmysqlFZBOOLZTINYINTJSONZLONGTEXTzcharacter set ([\w\-_]+)zcollate ([\w\-_]+)NstrOptional[bool]z%Union[_ServerDefault, Literal[False]] Optional[str]Optional[TypeEngine]zOptional[_ServerDefault]$Optional[Union[str, Literal[False]]]rNone) table_name column_namenullableserver_defaultnametype_r existing_typeexisting_server_defaultexisting_nullable autoincrementexisting_autoincrementcommentexisting_commentkwreturnc st|| st|| r>tj||f||||| || d||dk s^||dk rV|n||r|t||||dk rv|n||dk r|n| dk r| nd|dk r|n||dk r|n| | dk r| n| | dk r| n|d n|dk s|dk s| dk s| dk rz|t||||dk r|n||dk r |n| dk r.| nd|dk r>|n||dk rN|n| | dk r^| n| | dk rn| n|d n |dk r|t ||||ddS)N)r+r.rr/r1r,r0TF)rnewnamer+r.defaultr2r4r) rZ_server_default_is_identityZ_server_default_is_computedsuper alter_column$_is_mysql_allowed_functional_default_execMySQLChangeColumnMySQLModifyColumnMySQLAlterDefault)selfr)r*r+r,r-r.rr/r0r1r2r3r4r5r6 __class__?/opt/hc_python/lib/python3.8/site-packages/alembic/ddl/mysql.pyr;3s    zMySQLImpl.alter_columnr)constr7cs(t|tjrt|rdSt|dSN) isinstancerCheckConstraintrr:drop_constraint)rArFrBrDrErJszMySQLImpl.drop_constraintbool)r.r,r7cCs|dk o|jtjko|dk SrG)_type_affinitysqltypesDateTime)rAr.r,rDrDrEr<s  z.MySQLImpl._is_mysql_allowed_functional_defaultcCs"|jjtjkr*|jr*|js*|s*|dkr*dS|r^|jjtjkr^|dk rRtdd|nd}||kS|r|jjtjkrtdd|}|d|dkS|r|rt d| }t d| }|r|sdS| d| dkrdS| d }| d }td d | td d | kS||kSdS) Nz'0'Fz^'|'$'z(.*) (on update.*?)(?:\(\))?$Trr z(.*?)(?:\(\))?$z\1) typerLrMIntegerZ primary_keyr2resubStringmatchlowergroup)rAZinspector_columnZmetadata_columnZrendered_metadata_defaultZrendered_inspector_defaultZmetadata_defaultZ onupdate_insZ onupdate_metrDrDrEcompare_server_defaultsl      z MySQLImpl.compare_server_defaultc Cst}t|D]~}|jrq|jD]j}|j|jkrJ||||jq|jD]*}|j|jkrP||||jq|qP|j|kr qq qt|D]}|j|kr||qdSrG)setlistuniquecolumnsr-removeaddZ foreign_keys) rAZconn_unique_constraintsZ conn_indexesZmetadata_unique_constraintsZmetadata_indexesZremovedidxcolfkrDrDrEcorrect_for_autogen_constraintss&             z)MySQLImpl.correct_for_autogen_constraintscsfdd|D}fdd|D}t||D]d}||}||}|jdk rn|jdkrn|jdkrnd|_|jdk r2|jdkr2|jdkr2d|_q2dS)Ncsi|]}|j|qSrD)Z _create_reflected_constraint_sigunnamed_no_options.0rbrArDrE #s z=MySQLImpl.correct_for_autogen_foreignkeys..csi|]}|j|qSrD)Z_create_metadata_constraint_sigrdrergrDrErh's ZrestrictZRESTRICT)rZ intersectionZondeleterWZonupdate)rAZconn_fksZ metadata_fksZconn_fk_by_sigZmetadata_fk_by_sigsigZmdfkZcnfkrDrgrEcorrect_for_autogen_foreignkeys"s.    z)MySQLImpl.correct_for_autogen_foreignkeys) NFNNNNNNNNFN)__name__ __module__ __qualname__ __dialect__Ztransactional_ddlrZ type_synonymsZtype_arg_extractr;rJr<rYrcrk __classcell__rDrDrBrEr )s22s  C%r c@seZdZdZdS) MariaDBImplmariadbN)rlrmrnrorDrDrDrErq@srqcs,eZdZd ddddddfdd ZZS) r@Nr#rr%r()r-r*r9rr7cs$tt|j||d||_||_dS)Nr)r:r __init__r*r9)rAr-r*r9rrBrDrErsEszMySQLAlterDefault.__init__)NrlrmrnrsrprDrDrBrEr@Dsr@c s6eZdZd dddddddddd d fd d ZZS)r>NFr#r%r&r$/Optional[Union[_ServerDefault, Literal[False]]]r'r() r-r*rr8r.r+r9r2r4r7c sZtt|j||d||_||_||_||_||_| |_|dkrJt dt ||_ dS)NrzDAll MySQL CHANGE/MODIFY COLUMN operations require the existing type.)r:r rsr*r+r8r9r2r4r CommandErrorrMZ to_instancer.) rAr-r*rr8r.r+r9r2r4rBrDrErsRs zMySQLChangeColumn.__init__)NNNNFNFrtrDrDrBrEr>Qsr>c@s eZdZdS)r?N)rlrmrnrDrDrDrEr?nsr?r!rrcKs tddS)Nz9Individual alter column constructs not supported by MySQL)NotImplementedErrorelementcompilerr6rDrDrE _mysql_doesnt_support_individualrsr{rr#)ryrzr7cKs<dt||j|jt||j|jdk r4dt||jndfS)Nz%s ALTER COLUMN %s %szSET DEFAULT %sz DROP DEFAULT)r r)rrr*r9rrxrDrDrE_mysql_alter_default|s r|c Ks<dt||j|jt||jt||j|j|j|j |j dfS)Nz%s MODIFY %s %sr+r,r.r2r4) r r)rrr*_mysql_colspecr+r9r.r2r4rxrDrDrE_mysql_modify_columns rc KsFdt||j|jt||jt||jt||j|j|j |j |j dfS)Nz%s CHANGE %s %s %sr}) r r)rrr*r8r~r+r9r.r2r4rxrDrDrE_mysql_change_columns  rr$rurr')rzr+r,r.r2r4r7cCsnd|jj||rdndf}|r*|d7}|dk rL|dk rL|dt||7}|rj|d|j|t7}|S)Nz%s %sZNULLzNOT NULLz AUTO_INCREMENTFz DEFAULT %sz COMMENT %s)dialectZ type_compilerprocessrZ sql_compilerZrender_literal_valuerMrU)rzr+r,r.r2r4specrDrDrEr~s   r~rcKs|j}t|tjtjtjfr.|r$t||St|tjrt |j rbd|j |j |j |fSd|j |j |j |fSntddS)zVRedefine SQLAlchemy's drop constraint to raise errors for invalid constraint type.z!ALTER TABLE %s DROP CONSTRAINT %szALTER TABLE %s DROP CHECK %szFNo generic 'DROP CONSTRAINT' in MySQL - please specify constraint typeN)ryrHrZForeignKeyConstraintZPrimaryKeyConstraintZUniqueConstraintAssertionErrorZvisit_drop_constraintrIrrpreparerZ format_tabletableZformat_constraintrw)ryrzr6 constraintrDrDrE_mysql_drop_constraints.       r)3 __future__rrStypingrrrrZ sqlalchemyrr rMbaser r r rrrrrimplrrOrrZutil.sqla_compatrrrrZsqlalchemy.dialects.mysql.baserZsqlalchemy.sql.ddlrZsqlalchemy.sql.schemarZsqlalchemy.sql.type_apirrr rqr@r>r?r{r|rrr~rrDrDrDrEsb