bgxddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd lm Z dd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZerBddlmZddlm Z ddl!m"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddl&m'Z'dd l(m)Z)dd!l*m+Z+dd"l,m-Z-dd#l.m/Z/e ee0ee0d$ffZ1eeee0e0fed%gd&fZ2ee0ed'gee0ed(ffZ3ed)Z4e ed*e e0fZ5ee e0e4e5ge6fZ7ed+e e0e4e6e d+ge6fZ8eed,eee e0efgd&fZ9eed-d-e e0e ee e0ge e6fZ:Gd.d/ej;Z|jjS)aReturn True if the context is configured to expect a transactional DDL capable backend. This defaults to the type of database in use, and can be overridden by the ``transactional_ddl`` argument to :meth:`.configure` This function requires that a :class:`.MigrationContext` has first been made available via :meth:`.configure`. ) get_contextimpltransactional_ddlr?s r:is_transactional_ddlz'EnvironmentContext.is_transactional_ddls!!&88r<c,| SrC)rKr?s r:requires_connectionz&EnvironmentContext.requires_connections''))))r< _RevNumberc6|jdS)aReturn the hex identifier of the 'head' script revision. If the script directory has multiple heads, this method raises a :class:`.CommandError`; :meth:`.EnvironmentContext.get_head_revisions` should be preferred. This function does not require that the :class:`.MigrationContext` has been configured. .. seealso:: :meth:`.EnvironmentContext.get_head_revisions` headr3as_revision_numberr?s r:get_head_revisionz$EnvironmentContext.get_head_revisions{--f555r<c6|jdS)aReturn the hex identifier of the 'heads' script revision(s). This returns a tuple containing the version number of all heads in the script directory. This function does not require that the :class:`.MigrationContext` has been configured. headsrVr?s r:get_head_revisionsz%EnvironmentContext.get_head_revisionss{--g666r<c|j1|j|jSd|jvr%|j|jdSt jd)aTReturn the 'starting revision' argument, if the revision was passed using ``start:end``. This is only meaningful in "offline" mode. Returns ``None`` if no value is available or was configured. This function does not require that the :class:`.MigrationContext` has been configured. N starting_revz+No starting revision argument is available.)r1r3rWrM_start_from_revr8r CommandErrorr?s r:get_starting_revision_argumentz1EnvironmentContext.get_starting_revision_arguments  " .;11  ""2 t0 0 0;11!.1 #= r<cL|j|jdS)aGet the 'destination' revision argument. This is typically the argument passed to the ``upgrade`` or ``downgrade`` command. If it was specified as ``head``, the actual version number is returned; if specified as ``base``, ``None`` is returned. This function does not require that the :class:`.MigrationContext` has been configured. destination_rev)r3rWr8r?s r:get_revision_argumentz(EnvironmentContext.get_revision_argument%s*{--  / 0   r< Optional[str]c8|jddS)agReturn the value passed for the ``--tag`` argument, if any. The ``--tag`` argument is not used directly by Alembic, but is available for custom ``env.py`` configurations that wish to use it; particularly for offline generation scripts that wish to generate tagged filenames. This function does not require that the :class:`.MigrationContext` has been configured. .. seealso:: :meth:`.EnvironmentContext.get_x_argument` - a newer and more open ended system of extending ``env.py`` scripts via the command line. tagNrIr?s r:get_tag_argumentz#EnvironmentContext.get_tag_argument7s$ $$UD111r< as_dictionaryLiteral[False] List[str]cdSrCr9rhs r:get_x_argumentz!EnvironmentContext.get_x_argumentK r< Literal[True]Dict[str, str]cdSrCrlrms r:rnz!EnvironmentContext.get_x_argumentOror<. Union[List[str], Dict[str, str]]cdSrCrlrms r:rnz!EnvironmentContext.get_x_argumentSs  r<Fc|jj|jjjpg}ng}|rtd|D}|S)aReturn the value(s) passed for the ``-x`` argument, if any. The ``-x`` argument is an open ended flag that allows any user-defined value or values to be passed on the command line, then available here for consumption by a custom ``env.py`` script. The return value is a list, returned directly from the ``argparse`` structure. If ``as_dictionary=True`` is passed, the ``x`` arguments are parsed using ``key=value`` format into a dictionary that is then returned. For example, to support passing a database URL on the command line, the standard ``env.py`` script can be modified like this:: cmd_line_url = context.get_x_argument( as_dictionary=True).get('dbname') if cmd_line_url: engine = create_engine(cmd_line_url) else: engine = engine_from_config( config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) This then takes effect by running the ``alembic`` script as:: alembic -x dbname=postgresql://user:pass@host/dbname upgrade head This function does not require that the :class:`.MigrationContext` has been configured. .. seealso:: :meth:`.EnvironmentContext.get_tag_argument` :attr:`.Config.cmd_opts` Nc3BK|]}|ddVdS)=rN)split).0rAs r: z4EnvironmentContext.get_x_argument..s0<rs""""""!!!!!!!!!!!! ((((((......%%%%%%((((((''''''###### .%%%%%%111111555555......000000((((((111111!!!!!!111111------ eCsCx01 2 %uS#X-?(@A4G# %WU^(;"<< ' FG SM c]N$9:D@        3c9JK      TN h'h'h'h'h',h'h'h'h'h'r<