U of@sjddlmZddlZddlmZddlmZddlmZddlmZddlmZddl m Z dd l m Z dd l m Z dd l m Z d d lmZd dlmZd dlmZd dlmZddlmZddlmZer:ddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl%m&Z&GdddeZ'eedd d!d"d#d$d%Z(dS)&) annotationsN)Any)Dict)Optional) TYPE_CHECKING)Union)cast)JSON)schema)sql) alter_table)format_table_name) RenameTable) DefaultImpl)util)compiles) Inspector) DDLCompiler)Cast) ClauseElement)Column) Constraint)Table) TypeEngine)BatchOperationsImplcseZdZdZdZdddddZdd d d Zdd d d ZddddddddZdddddZ dddddddZ d)ddddfd d! Z dd"d#dd$d%d&Z d'd(Z ZS)* SQLiteImplsqliteFrbool)batch_opreturncCs~|jD]r}|ddkrf|dd}t|jtjrFt|jjtjrFdSt|jtj j rx|jj rxdSq|ddkrdSqdS)zReturn True if the given :class:`.BatchOperationsImpl` would need the table to be recreated and copied in order to proceed. Normally, only returns True on SQLite when operations other than add_column are present. r add_columnr T)Z create_indexZ drop_indexFN) batch isinstanceZserver_defaultr Z DefaultClauseargr rrZ sqla_compatZComputedZ persisted)selfr opcolr)@/opt/hc_python/lib/python3.8/site-packages/alembic/ddl/sqlite.pyrequires_recreate_in_batch.s$    z%SQLiteImpl.requires_recreate_in_batchr)constcCs,|jdkrtdn||r(tddS)NNo support for ALTER of constraints in SQLite dialect. Please refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.zSkipping unsupported ALTER for creation of implicit constraint. Please refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.) _create_ruleNotImplementedErrorrwarnr&r,r)r)r*add_constraintJs  zSQLiteImpl.add_constraintcCs|jdkrtddS)Nr-)r.r/r1r)r)r*drop_constraint[s zSQLiteImpl.drop_constraintz Column[Any]z Optional[str])inspector_columnmetadata_columnrendered_metadata_defaultrendered_inspector_defaultr!cCsP|dk r$tdd|}tdd|}|dk rHtdd|}tdd|}||kS)Nz ^\((.+)\)$z\1z^\"?'(.+)'\"?$)resub)r&r4r5r6r7r)r)r*compare_server_defaultcs.z!SQLiteImpl.compare_server_default)exprr!cCs@|sdStd|rdStd|r(dStd|r8dSdSdS)aDetermine if a server default is a SQL expression or a constant. There are too many assertions that expect server defaults to round-trip identically without parenthesis added so we will add parens only in very specific cases. Fz ^[0-9\.]$z^'.+'$z^\(.+\)$TN)r8match)r&r;r)r)r*-_guess_if_default_is_unparenthesized_sql_expr~s    z8SQLiteImpl._guess_if_default_is_unparenthesized_sql_exprrrzDict[str, Any]None) inspectortable column_infor!cCs(||ddr$d|df|d<dS)Ndefault(%s))r=get)r&r?r@rAr)r)r*autogen_column_reflects z!SQLiteImpl.autogen_column_reflectrstr)r;is_server_defaultr!c s4tj|fd|i|}|r0||r0d|f}|S)NrGrC)superrender_ddl_sql_exprr=)r&r;rGkwZstr_expr __class__r)r*rIs zSQLiteImpl.render_ddl_sql_exprz"Dict[str, Union[TypeEngine, Cast]]r)existingexisting_transfernew_typer!cCs.|jj|jk r*t|ts*t|d||d<dS)Nr;)typeZ_type_affinityr$r r)r&rMrNrOr)r)r*cast_for_batch_migrates z!SQLiteImpl.cast_for_batch_migratecCs|||dS)N)Z_skip_functional_indexes)r&Zconn_unique_constraintsZ conn_indexesZmetadata_unique_constraintsZmetadata_indexesr)r)r*correct_for_autogen_constraintssz*SQLiteImpl.correct_for_autogen_constraints)F)__name__ __module__ __qualname__Z __dialect__Ztransactional_ddlr+r2r3r:r=rErIrQrR __classcell__r)r)rKr*r&srrrrrF)elementcompilerr!cKs"dt||j|jt||jdfS)Nz%s RENAME TO %s)r Z table_namer rZnew_table_name)rWrXrJr)r)r*visit_rename_tables rY)) __future__rr8typingrrrrrZ sqlalchemyrr r r baser rrimplrrZutil.sqla_compatrZsqlalchemy.engine.reflectionrZsqlalchemy.sql.compilerrZsqlalchemy.sql.elementsrrZsqlalchemy.sql.schemarrrZsqlalchemy.sql.type_apirZoperations.batchrrrYr)r)r)r*s<                         #