관리-도구
편집 파일: api.cpython-37.opt-1.pyc
B �M!Vz9 � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd l Z d d� Z dd � Zddd�Zdd� Z G dd� de�ZG dd� de�Zd S )zXProvide the 'autogenerate' feature which can produce migration operations automatically.� )�ops� )�render)�compare)�util� )� InspectorNc C s t | |�}|j�� S )a� 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.schema import SchemaItem from sqlalchemy.types import TypeEngine from sqlalchemy import (create_engine, MetaData, Column, Integer, String, Table) import pprint engine = create_engine("sqlite://") engine.execute(''' create table foo ( id integer not null primary key, old_data varchar, x integer )''') engine.execute(''' 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(bind=None), Column('info', String(), table=<bat>), schema=None)), ( 'remove_table', Table(u'bar', MetaData(bind=None), Column(u'data', VARCHAR(), table=<bar>), schema=None)), ( 'add_column', None, 'foo', Column('data', Integer(), table=<foo>)), ( 'remove_column', None, 'foo', Column(u'old_data', VARCHAR(), table=None)), [ ( 'modify_nullable', None, 'foo', u'x', { 'existing_server_default': None, 'existing_type': INTEGER()}, True, False)]] :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_opsZas_diffs)�context�metadata�migration_script� r �I/opt/alt/python37/lib/python3.7/site-packages/alembic/autogenerate/api.py�compare_metadata s Z r c C s8 t | |d�}tjdt�g �t�g �d�}t�||� |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`. .. versionadded:: 0.8.0 .. seealso:: :func:`.compare_metadata` - returns more fundamental "diff" data from comparing a schema. )r N)�rev_idr � downgrade_ops)�AutogenContextr �MigrationScript� UpgradeOps�DowngradeOpsr �_populate_migration_script)r r �autogen_contextr r r r r j s r �sa.�op.Fr c C s6 ||||d�}t d|d�}t|�|_t�t�| |��S )z�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. )�sqlalchemy_module_prefix�alembic_module_prefix�render_item�render_as_batchN)�opts)r �set�importsr Z_indentZ_render_cmd_body)Z up_or_down_opr r r r! r r r r r r �render_python_code� s r"