U of@sddlmZddlmZddlmZddlmZddl m Z ddl m Z erXdd l m Z eejd d d d ddZeejd dd d ddZeejd dd d ddZeejd dd d ddZeejd dd d ddZeejd ddd ddZeejd d d d d!d"Zeejd d#d d d$d%Zeejd d&d d d'd(Z eej!d d)d d d*d+Z"eej#d d,d d d-d.Z$eej%d d/d d d0d1Z&eej'd d2d d d3d4Z(eej)d d5d d d6d7Z*d S)8) TYPE_CHECKINGschema)ops) Operations)_copy)sqla_14)Tablerzops.AlterColumnOpN) operations operationreturnc s"|jj|jjd|j}|j}|j}|j}|j}|j}|j }|j } |j } |j } |j } |j} fdd}|r|r|jj|t|||d}|jD]}||r|j|q|jj||f| | | |||||| | d |j|r|jj||j|||d}|jD]}||r|j|qdS)Ncs t|tj o|j p|SN) isinstance sa_schemaPrimaryKeyConstraintZ _create_rule) constraintcompilerG/opt/hc_python/lib/python3.8/site-packages/alembic/operations/toimpl.py_count_constraint&sz'alter_column.._count_constraintr) nullableserver_defaultnametype_r existing_typeexisting_server_defaultexisting_nullablecommentexisting_comment)impldialectZstatement_compilerrrrZ modify_type column_name table_namerZmodify_server_defaultZ modify_nameZmodify_nullableZmodify_commentr! schema_objtablerColumn constraintsdrop_constraint alter_columnkwcolumnadd_constraint)r r rrrrr$r%rrZnew_column_namerr r!rtrrrrr+sh       r+zops.DropTableOpcCs|j||jdSr)r" drop_tableto_tablemigration_contextr r rrrr0Ps r0zops.DropColumnOpcCs0||j}|jj|j|fd|ji|jdS)Nr)Z to_columnr2r" drop_columnr%rr,)r r r-rrrr4Ws r4zops.CreateIndexOpcCsD||j}i}|jdk r0ts&td|j|d<|jj|f|dS)NSQLAlchemy 1.4+ required if_not_exists)to_indexr2r6r NotImplementedErrorr" create_index)r r idxr,rrrr9as   r9zops.DropIndexOpcCs@i}|jdk r$tstd|j|d<|jj||jf|dS)Nr5 if_exists)r;r r8r" drop_indexr7r2)r r r,rrrr<os   r<zops.CreateTableOpr cCs||j}|j||Sr)r1r2r" create_tabler r r'rrrr=~s  r=zops.RenameTableOpcCs|jj|j|j|jddSNr)r" rename_tabler%Znew_table_namerr3rrrr@s r@zops.CreateTableCommentOpcCs||j}|j|dSr)r1r2r"create_table_commentr>rrrrAs rAzops.DropTableCommentOpcCs||j}|j|dSr)r1r2r"drop_table_commentr>rrrrBs rBzops.AddColumnOpc Cs|j}|j}|j}|j}|jdk r*t|}|jj|||d}|jj||fd|i||j D]}t |t j s\|j |q\|jD]}|j|q|jjjo|jjj } |j} | r| r|j|dS)Nrr)r%r-rr,r'r r&r" add_columnr)rrrr.Zindexesr9r#Zsupports_commentsZinline_commentsr Zcreate_column_comment) r r r%r-rr,r/rindexZ with_commentr rrrrCs&      rCzops.AddConstraintOpcCs|j||jdSr)r"r.Z to_constraintr2r3rrrcreate_constraints rEzops.DropConstraintOpcCs(|j|jj|j|j|j|jddSr?)r"r*r&Zgeneric_constraintZconstraint_namer%Zconstraint_typerr3rrrr*sr*zops.BulkInsertOpcCs|jj|j|j|jddS)N) multiinsert)r" bulk_insertr'rowsrFr3rrrrGs rGzops.ExecuteSQLOpcCs|jjj|j|jddS)N)execution_options)r2r"executeZsqltextrIr3rrr execute_sqlsrK)+typingrZ sqlalchemyrrrbaserZutil.sqla_compatr r Zsqlalchemy.sql.schemar Zimplementation_forZ AlterColumnOpr+Z DropTableOpr0Z DropColumnOpr4Z CreateIndexOpr9Z DropIndexOpr<Z CreateTableOpr=Z RenameTableOpr@ZCreateTableCommentOprAZDropTableCommentOprBZ AddColumnOprCZAddConstraintOprEZDropConstraintOpr*Z BulkInsertOprGZ ExecuteSQLOprKrrrrs        >