§ }<ˆjºTãóà—ddlmZddlZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd l mZd dlmZd dlmZddlmZddlmZ e rZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl"m#Z#ddl"m$Z$ddl"m%Z%ddl&m'Z'dd l(m)Z)dd!l(m*Z*dGd(„Z+dHd*„Z, dIdJd>„Z-dKdB„Z.GdC„dD¦«Z/GdE„dF¦«Z0dS)Lé)Ú annotationsN)ÚAny)ÚCallable)ÚDict)ÚIterator)ÚOptional)ÚSequence)ÚSet)Ú TYPE_CHECKING)ÚUnion)Úinspecté)Úcompare)Úrenderé)Úutil)Úops)Ú Connection)ÚDialect)Ú Inspector)ÚMetaData)Ú SchemaItem)ÚConfig)Ú DowngradeOps)ÚMigrationScript)Ú UpgradeOps)ÚNameFilterParentNames)ÚNameFilterType)Ú RenderItemFn©ÚMigrationContext)ÚScript)ÚScriptDirectoryÚcontextr!ÚmetadatarÚreturnrcóT—t||¦«}|j ¦«S)aB Compare a database schema to that given in a :class:`~sqlalchemy.schema.MetaData` instance. The database connection is presented in the context of a :class:`.MigrationContext` object, which provides database connectivity as well as optional comparison functions to use for datatypes and server defaults - see the "autogenerate" arguments at :meth:`.EnvironmentContext.configure` for details on these. The return format is a list of "diff" directives, each representing individual differences:: from alembic.migration import MigrationContext from alembic.autogenerate import compare_metadata from sqlalchemy import ( create_engine, MetaData, Column, Integer, String, Table, text, ) import pprint engine = create_engine("sqlite://") with engine.begin() as conn: conn.execute( text( ''' create table foo ( id integer not null primary key, old_data varchar, x integer ) ''' ) ) conn.execute(text("create table bar (data varchar)")) metadata = MetaData() Table( "foo", metadata, Column("id", Integer, primary_key=True), Column("data", Integer), Column("x", Integer, nullable=False), ) Table("bat", metadata, Column("info", String)) mc = MigrationContext.configure(engine.connect()) diff = compare_metadata(mc, metadata) pprint.pprint(diff, indent=2, width=20) Output:: [ ( "add_table", Table( "bat", MetaData(), Column("info", String(), table=), schema=None, ), ), ( "remove_table", Table( "bar", MetaData(), Column("data", VARCHAR(), table=), schema=None, ), ), ( "add_column", None, "foo", Column("data", Integer(), table=), ), [ ( "modify_nullable", None, "foo", "x", { "existing_comment": None, "existing_server_default": False, "existing_type": INTEGER(), }, True, False, ) ], ( "remove_column", None, "foo", Column("old_data", VARCHAR(), table=), ), ] :param context: a :class:`.MigrationContext` instance. :param metadata: a :class:`~sqlalchemy.schema.MetaData` instance. .. seealso:: :func:`.produce_migrations` - produces a :class:`.MigrationScript` structure based on metadata comparison. )Úproduce_migrationsÚ upgrade_opsÚas_diffs)r$r%Úmigration_scripts új/builddir/build/BUILD/cloudlinux-venv-1.0.12/venv/lib/python3.11/site-packages/alembic/autogenerate/api.pyÚcompare_metadatar-+s*€õr*¨'°8Ñ<Ô<ÐØ Ô '× 0Ò 0Ñ 2Ô 2Ð2órcóÈ—t||¬¦«}tjdtjg¦«tjg¦«¬¦«}t j||¦«|S)aßProduce a :class:`.MigrationScript` structure based on schema comparison. This function does essentially what :func:`.compare_metadata` does, but then runs the resulting list of diffs to produce the full :class:`.MigrationScript` object. For an example of what this looks like, see the example in :ref:`customizing_revision`. .. seealso:: :func:`.compare_metadata` - returns more fundamental "diff" data from comparing a schema. )r%N©Úrev_idr)Ú downgrade_ops)ÚAutogenContextrrrrrÚ_populate_migration_script)r$r%Úautogen_contextr+s r,r(r(¨sh€õ$% W°xÐ@Ñ@Ô@€OåÔ*ØÝ”N 2Ñ&Ô&ÝÔ& rÑ*Ô*ðñôÐõ  Ô& Ð8HÑIÔIÐIà Ðr.úsa.úop.F©Ú up_or_down_opúUnion[UpgradeOps, DowngradeOps]Úsqlalchemy_module_prefixÚstrÚalembic_module_prefixÚrender_as_batchÚboolÚimportsú Sequence[str]Ú render_itemúOptional[RenderItemFn]Úmigration_contextúOptional[MigrationContext]Úuser_module_prefixú Optional[str]cóø—|||||dœ}|€%ddlm} ddlm} | j| ¦«¬¦«}t ||¬¦«} t |¦«| _tj tj || ¦«¦«S) a*Render Python code given an :class:`.UpgradeOps` or :class:`.DowngradeOps` object. This is a convenience function that can be used to test the autogenerate output of a user-defined :class:`.MigrationScript` structure. :param up_or_down_op: :class:`.UpgradeOps` or :class:`.DowngradeOps` object :param sqlalchemy_module_prefix: module prefix for SQLAlchemy objects :param alembic_module_prefix: module prefix for Alembic constructs :param render_as_batch: use "batch operations" style for rendering :param imports: sequence of import symbols to add :param render_item: callable to render items :param migration_context: optional :class:`.MigrationContext` :param user_module_prefix: optional string prefix for user-defined types .. versionadded:: 1.11.0 )r;r=rBr>rFNrr r)ÚDefaultDialect)Údialect)Úopts) Úruntime.migrationr!Úsqlalchemy.engine.defaultrIÚ configurer3Úsetr@rÚ_indentÚ_render_cmd_body) r9r;r=r>r@rBrDrFrKr!rIr5s r,Úrender_python_coderRÇs¸€ð:%=Ø!6Ø"Ø*Ø0ð  ð €DðÐ Ø8Ð8Ð8Ð8Ð8Ð8Ø<Ð<Ð<Ð<Ð<Ð<à6Ð,Ô6Ø"�NÑ$Ô$ð ñ ô Ðõ%Ð%6¸TÐBÑBÔB€OÝ! '™lœl€OÔÝ Œ>ÝÔ  ¨Ñ?Ô?ñ ô ðr.Ú template_argsúDict[Any, Any]ÚNonecóô—t|¦«}tjg¦«}tj||¦«tjd|| ¦«¬¦«}tj|||¦«dS)z6legacy, used by test_autogen_composition at the momentNr0) r3rrrÚ_produce_net_changesrÚreverserÚ _render_python_into_templatevars)r$rSr5r)r+s r,Ú_render_migration_diffsrZús‰€õ % WÑ-Ô-€Oå”. Ñ$Ô$€KÝ Ô  °+Ñ>Ô>Ð>åÔ*ØØØ!×)Ò)Ñ+Ô+ðñôÐõ  Ô+ØÐ)¨=ñôðððr.có —eZdZUdZdZded< dZded< dZded< dZd ed < dZ d ed < d(d)d„Z e j d*d„¦«Z ejd+d„¦«Zd,d„Zd-d%„ZeZe j d&„¦«Ze j d'„¦«ZdS).r3zSMaintains configuration and state that's specific to an autogenerate operation.NúOptional[MetaData]r%zOptional[Connection]Ú connectionzOptional[Dialect]rJzSet[str]r@r!rDTrKúOptional[dict]Ú autogenerater?r&rUcón—|r|�|jrtjd¦«‚|€|j}|€| dd¦«n|x|_}|r,|€*|�(|j�!tjd|jjz¦«‚| dd¦«}| dd¦«}g}g}|r| |¦«|r| |¦«||_ ||_ ||_ |j �"|j j |_ |j j|_t¦«|_||_d|_dS)Nz^autogenerate can't use as_sql=True as it prevents querying the database for schema informationÚtarget_metadataz‰Can't proceed with --autogenerate option; environment script %s does not provide a MetaData object or sequence of objects to the context.Úinclude_objectÚ include_nameF)Úas_sqlrÚ CommandErrorrKÚgetr%ÚscriptÚenv_py_locationÚappendÚ_object_filtersÚ _name_filtersrDÚbindr]rJrOr@Ú _has_batch) ÚselfrDr%rKr_rbrcÚobject_filtersÚ name_filterss r,Ú__init__zAutogenContext.__init__Gs~€ð ð à!Ð-Ø!Ô(ð.õÔ#ð6ñôð ð ˆ<Ø$Ô)ˆDð2:Ð1AˆD�HŠHÐ&¨Ñ -Ô -Ð -Àx𠈌 ˜ð ð àÐ Ø!Ð-Ø!Ô(Ð4åÔ#ðKð%Ô+Ô;ñ=ñôð ðŸšÐ"2°DÑ9Ô9ˆØ—x’x °Ñ5Ô5ˆ àˆØˆ Ø ð 2Ø × !Ò ! .Ñ 1Ô 1Ð 1Ø ð .Ø × Ò   Ñ -Ô -Ð -à-ˆÔØ)ˆÔà!2ˆÔØ Ô !Ð -Ø"Ô4Ô9ˆDŒOØÔ1Ô9ˆDŒLå‘u”uˆŒ Ø$(ˆŒ Ø %ˆŒˆˆr.rcóV—|j€td¦«‚t|j¦«S)NzHcan't return inspector as this AutogenContext has no database connection)r]Ú TypeErrorr ©rns r,Ú inspectorzAutogenContext.inspectorƒs3€à Œ?Ð "Ýð<ñôð õ�t”Ñ'Ô'Ð'r.úIterator[None]c#ó.K—d|_dV—d|_dS)NTF)rmrts r,Ú _within_batchzAutogenContext._within_batchŒs!èè€àˆŒØ ˆˆˆØˆŒˆˆr.ÚnamerGÚtype_rÚ parent_namesrcó¸—d|vr;|dkr|}n| dd¦«}|r|d}|r |›d|›�|d<n||d<|jD]}||||¦«sdSŒdS) aîRun the context's name filters and return True if the targets should be part of the autogenerate operation. This method should be run for every kind of name encountered within the reflection side of an autogenerate operation, giving the environment the chance to filter what names should be reflected as database objects. The filters here are produced directly via the :paramref:`.EnvironmentContext.configure.include_name` parameter. Ú schema_nameÚtableÚ table_nameNú.Úschema_qualified_table_nameFT)rfrk)rnryrzr{rr}Úfns r,Úrun_name_filterszAutogenContext.run_name_filters’s¹€ð ˜LÐ (Ð (ؘÒÐØ!� � à)×-Ò-¨l¸DÑAÔA� Øð MØ*¨=Ô9� ØðMà#˜ ˜ Ø"˜ ðC�LÐ!>Ñ?Ð?ð CM�LÐ!>Ñ?àÔ$ð ð ˆBà�2�d˜E <Ñ0Ô0ð Ø�u�uð ð�4r.Úobject_rÚ reflectedÚ compare_toúOptional[SchemaItem]có>—|jD]}||||||¦«sdSŒdS)aÛRun the context's object filters and return True if the targets should be part of the autogenerate operation. This method should be run for every kind of object encountered within an autogenerate operation, giving the environment the chance to filter what objects should be included in the comparison. The filters here are produced directly via the :paramref:`.EnvironmentContext.configure.include_object` parameter. FT)rj)rnr„ryrzr…r†r‚s r,Úrun_object_filtersz!AutogenContext.run_object_filters¸sC€ð$Ô&ð ð ˆBØ�2�g˜t U¨I°zÑBÔBð Ø�u�uð ð�4r.cóv—g}tj|j¦«D]}| |j¦«Œ|S)aiReturn an aggregate of the :attr:`.MetaData.sorted_tables` collection(s). For a sequence of :class:`.MetaData` objects, this concatenates the :attr:`.MetaData.sorted_tables` collection for each individual :class:`.MetaData` in the order of the sequence. It does **not** collate the sorted tables collections. )rÚto_listr%ÚextendÚ sorted_tables)rnÚresultÚms r,r�zAutogenContext.sorted_tablesÒs@€ðˆÝ”˜dœmÑ,Ô,ð +ð +ˆAØ �MŠM˜!œ/Ñ *Ô *Ð *Ð *؈ r.c óZ—i}tj|j¦«D]Ž}t|¦« t|j¦«¦«}|rz4AutogenContext.table_key_to_table..õs&èè€Ð KÐ K°# ¨#¡Ð KÐ KÐ KÐ KÐ KÐ Kr.) rr‹r%rOÚ intersectionÚtablesÚ ValueErrorÚjoinÚsortedÚupdate)rnrŽr�Ú intersects r,Útable_key_to_tablez!AutogenContext.table_key_to_tableâs®€ðˆÝ”˜dœmÑ,Ô,ð $ð $ˆAݘF™ œ ×0Ò0µ°Q´X±´Ñ?Ô?ˆIØð Ý ð+à—y’yÐ KÐ K½À Ñ9JÔ9JÐ KÑ KÔ KÑKÔKñMñôðð �MŠM˜!œ(Ñ #Ô #Ð #Ð #؈ r.)NNT) rDr!r%r\rKr^r_r?r&rU)r&r)r&rv)ryrGrzrr{rr&r?) r„rryrGrzrr…r?r†r‡r&r?)Ú__name__Ú __module__Ú __qualname__Ú__doc__r%Ú__annotations__r]rJr@rDrqrÚmemoized_propertyruÚ contextlibÚcontextmanagerrxrƒr‰Ú run_filtersr�rœr8r.r,r3r3sp€€€€€€ððð$(€HÐ'Ð'Ð'Ñ'ðð"(,€JÐ+Ð+Ð+Ñ+ðð"&€GÐ%Ð%Ð%Ñ%ðð€GÐÐÐÑð ð+/ÐÐ.Ð.Ð.Ñ.ØNð (,Ø#Ø!ð :&ð:&ð:&ð:&ð:&ðx Ôð(ð(ð(ñÔð(ðÔð ð ð ñÔð ð $ð$ð$ð$ðLðððð0%€Kà Ôð ð ñÔð ð ÔððñÔðððr.r3cóN—eZdZdZ ddd „Zd d„Zd!d„Zd!d„Zd"d„Zd#d„Z d$d„Z dS)%ÚRevisionContextz^Maintains configuration and state that's specific to a revision file generation operation.NÚconfigrÚscript_directoryr#Ú command_argsúDict[str, Any]Úprocess_revision_directivesúOptional[Callable]r&rUcó„—||_||_||_||_d|i|_| ¦«g|_dS)Nr¨)r¨r©rªr¬rSÚ_default_revisionÚgenerated_revisions)rnr¨r©rªr¬s r,rqzRevisionContext.__init__sQ€ðˆŒ Ø 0ˆÔØ(ˆÔØ+FˆÔ(à �fð ˆÔð%)×$:Ò$:Ñ$<Ô$<Ð#=ˆÔ Ð Ð r.r+rúOptional[Script]c ó�—|j ¦«}t|dd¦«rV|j}t ¦«|_|jr|j |j¦«tj|||¦«|j €J‚|j j |j |j fd|j |j|j|j|jdœ|¤ŽS)NÚ _needs_renderFT)ÚrefreshÚheadÚspliceÚ branch_labelsÚ version_pathÚ depends_on)rSÚcopyÚgetattrÚ_last_autogen_contextrOr@ršrrYr1r©Úgenerate_revisionÚmessagerµr¶Ú branch_labelr¸r¹)rnr+rSr5s r,Ú _to_scriptzRevisionContext._to_scriptsõ€ð)-Ô(:×(?Ò(?Ñ(AÔ(Aˆ å Ð# _°eÑ <Ô <ð Ø"Ô8ˆOõ'*¡e¤eˆOÔ #ØÔ'ð IØÔ'×.Ò.Ð/?Ô/GÑHÔHÐHÝ Ô 3ØÐ!1°=ñ ô ð ð Ô&Ð2Ð2Ð2Ø6ˆtÔ$Ô6Ø Ô #Ø Ô $ð  ðØ!Ô&Ø#Ô*Ø*Ô7Ø)Ô6Ø'Ô2ð  ð  ðð  ð  ð r.ÚrevÚtuplerDr!có4—| ||d¦«dS)NT©Ú_run_environment©rnrÁrDs r,Úrun_autogeneratez RevisionContext.run_autogenerate/s#€ð ×Ò˜cÐ#4°dÑ;Ô;Ð;Ð;Ð;r.có4—| ||d¦«dS)NFrÄrÆs r,Úrun_no_autogeneratez#RevisionContext.run_no_autogenerate4s#€ð ×Ò˜cÐ#4°eÑ<Ô<Ð<Ð<Ðð>ð>ð>ð>ð" ð ð ð ð<<ð<ð<ð<ð =ð=ð=ð=ð 62ð62ð62ð62ðp ð ð ð ð6ð6ð6ð6ð6ð6r.r§)r$r!r%rr&r)r$r!r%rr&r)r6r7Fr8NNN)r9r:r;r<r=r<r>r?r@rArBrCrDrErFrGr&r<)r$r!rSrTr&rU)1Ú __future__rr£Útypingrrrrrr r r r Ú sqlalchemyr ÚrrrÚ operationsrÚsqlalchemy.enginerrrÚsqlalchemy.sql.schemarrr¨rÚoperations.opsrrrÚruntime.environmentrrrrLr!Ú script.baser"r#r-r(rRrZr3r§r8r.r,úrçsðØ"Ð"Ð"Ð"Ð"Ð"àÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØ Ð Ð Ð Ð Ð ØÐÐÐÐÐàÐÐÐÐÐàÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐððð.Ø,Ð,Ð,Ð,Ð,Ð,Ø)Ð)Ð)Ð)Ð)Ð)Ø+Ð+Ð+Ð+Ð+Ð+Ø.Ð.Ð.Ð.Ð.Ð.Ø0Ð0Ð0Ð0Ð0Ð0àÐÐÐÐÐØ-Ð-Ð-Ð-Ð-Ð-Ø0Ð0Ð0Ð0Ð0Ð0Ø+Ð+Ð+Ð+Ð+Ð+Ø;Ð;Ð;Ð;Ð;Ð;Ø4Ð4Ð4Ð4Ð4Ð4Ø2Ð2Ð2Ð2Ð2Ð2Ø4Ð4Ð4Ð4Ð4Ð4Ø$Ð$Ð$Ð$Ð$Ð$Ø-Ð-Ð-Ð-Ð-Ð-ðz3ðz3ðz3ðz3ðzððððB%*Ø!&Ø!ØØ*.Ø48Ø(,ð0ð0ð0ð0ð0ðfðððð*jðjðjðjðjñjôjðjðZF6ðF6ðF6ðF6ðF6ñF6ôF6ðF6ðF6ðF6r.