관리-도구
편집 파일: migration.cpython-37.pyc
B �M!Vn � @ s� d dl Z d dlZd dlmZ d dlmZmZmZmZm Z d dl mZ d dlm Z ddlmZmZ ddlmZmZ e �e�ZG d d � d e�ZG dd� de�ZG d d� de�ZG dd� de�ZG dd� de�ZdS )� N)�contextmanager)�MetaData�Table�Column�String�literal_column)�MockEngineStrategy)�url� )�callable� EncodedIO)�ddl�utilc @ s� e Zd ZdZd"dd�Zed#dd��Zd$dd �Zd d� Zdd � Z dd� Z dd� Zdd� Zdd� Z d%dd�Zdd� Zedd� �Zedd� �Zdd� Zd d!� ZdS )&�MigrationContexta� Represent the database state made available to a migration script. :class:`.MigrationContext` is the front end to an actual database connection, or alternatively a string output stream given a particular database dialect, from an Alembic perspective. When inside the ``env.py`` script, the :class:`.MigrationContext` is available via the :meth:`.EnvironmentContext.get_context` method, which is available at ``alembic.context``:: # from within env.py script from alembic import context migration_context = context.get_context() For usage outside of an ``env.py`` script, such as for utility routines that want to check the current version in the database, the :meth:`.MigrationContext.configure` method to create new :class:`.MigrationContext` objects. For example, to get at the current revision in the database using :meth:`.MigrationContext.get_current_revision`:: # in any application, outside of an env.py script from alembic.migration import MigrationContext from sqlalchemy import create_engine engine = create_engine("postgresql://mydatabase") conn = engine.connect() context = MigrationContext.configure(conn) current_rev = context.get_current_revision() The above context can also be used to produce Alembic migration operations with an :class:`.Operations` instance:: # in any application, outside of the normal Alembic environment from alembic.operations import Operations op = Operations(context) op.alter_column("mytable", "somecolumn", nullable=True) Nc C s� || _ || _|| _|�d�| _|�dd�}|�d�}|�dd�| _|rb| �|�| _| jd k sht�n|| _|�d�| _ || _ d|kr�t|�d�p�tj |d �| _n|�dtj �| _|�d d�| _|�d d�| _|�dd� | _}|�d d � | _}t|t� tdtd�dd�|d�| _|�d�| _tj�|�|| j| j || j|�| _t�d| jjj � | j �rdt�d� t�d| jj!�rxdnd� d S )N�script�as_sqlF�transactional_ddlZtransaction_per_migration�fnZoutput_encoding� output_buffer�compare_type�compare_server_default� version_tableZalembic_version�version_table_schema�version_num� )Znullable)ZschemaZstarting_revzContext impl %s.zGenerating static SQLzWill assume %s DDL.Z transactionalznon-transactional)"�environment_context�opts�dialect�getr �_transaction_per_migration�_stdout_connection� connection�AssertionError�_migrations_fnr r �sys�stdoutr �_user_compare_type�_user_compare_server_defaultr r r r r r �_version�_start_from_revr ZDefaultImplZget_by_dialect�impl�log�info� __class__�__name__r ) �selfr r! r r r r r r � r0 �J/opt/alt/python37/lib/python3.7/site-packages/alembic/runtime/migration.py�__init__>