B
M!Vn @ s d dl Z d dlZd dlmZ d dlmZmZmZmZm Z d dl
mZ d dlm
Z ddlmZmZ ddlmZmZ e eZG d d
d
eZG dd deZG d
d deZG dd deZG dd deZdS ) N)contextmanager)MetaDataTableColumnStringliteral_column)MockEngineStrategy)url )callable EncodedIO)ddlutilc @ s e Zd ZdZd"ddZed#ddZd$dd Zd
d Zdd
Z dd Z
dd Zdd Zdd Z
d%ddZdd 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 shtn|| _|d| _ || _
d|krt|dptj
|d | _n|dtj
| _|d d| _|d
d| _|dd | _}|d
d | _}t|t tdtddd|d| _|d| _tj||| j| j
|| j|| _td| jjj | j
rdtd td| jj!rxdnd d S )Nscriptas_sqlFtransactional_ddlZtransaction_per_migrationfnZoutput_encoding
output_buffercompare_typecompare_server_default
version_tableZalembic_versionversion_table_schemaversion_num )Znullable)ZschemaZstarting_revzContext impl %s.zGenerating static SQLzWill assume %s DDL.Z
transactionalznon-transactional)"environment_contextoptsdialectgetr _transaction_per_migration_stdout_connection
connectionAssertionError_migrations_fnr r sysstdoutr _user_compare_type_user_compare_server_defaultr r r r r r _version_start_from_revr
ZDefaultImplZget_by_dialectimplloginfo __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__>