관리-도구
편집 파일: script.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Script Directory — Alembic 0.8.3 documentation</title> <link rel="stylesheet" href="../_static/nature_override.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/changelog.css" type="text/css" /> <link rel="stylesheet" href="../_static/sphinx_paramlinks.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '0.8.3', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="top" title="Alembic 0.8.3 documentation" href="../index.html" /> <link rel="up" title="API Details" href="index.html" /> <link rel="next" title="DDL Internals" href="ddl.html" /> <link rel="prev" title="Autogeneration" href="autogenerate.html" /> </head> <body role="document"> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="ddl.html" title="DDL Internals" accesskey="N">next</a> |</li> <li class="right" > <a href="autogenerate.html" title="Autogeneration" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Alembic 0.8.3 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API Details</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="script-directory"> <span id="alembic-script-toplevel"></span><h1>Script Directory<a class="headerlink" href="#script-directory" title="Permalink to this headline">¶</a></h1> <p>The <a class="reference internal" href="#alembic.script.ScriptDirectory" title="alembic.script.ScriptDirectory"><code class="xref py py-class docutils literal"><span class="pre">ScriptDirectory</span></code></a> object provides programmatic access to the Alembic version files present in the filesystem.</p> <span class="target" id="module-alembic.script"></span><dl class="class"> <dt id="alembic.script.ScriptDirectory"> <em class="property">class </em><code class="descclassname">alembic.script.</code><code class="descname">ScriptDirectory</code><span class="sig-paren">(</span><em>dir</em>, <em>file_template='%(rev)s_%(slug)s'</em>, <em>truncate_slug_length=40</em>, <em>version_locations=None</em>, <em>sourceless=False</em>, <em>output_encoding='utf-8'</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory" title="Permalink to this definition">¶</a></dt> <dd><p>Provides operations upon an Alembic script directory.</p> <p>This object is useful to get information as to current revisions, most notably being able to get at the “head” revision, for schemes that want to test if the current revision in the database is the most recent:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">alembic.script</span> <span class="kn">import</span> <span class="n">ScriptDirectory</span> <span class="kn">from</span> <span class="nn">alembic.config</span> <span class="kn">import</span> <span class="n">Config</span> <span class="n">config</span> <span class="o">=</span> <span class="n">Config</span><span class="p">()</span> <span class="n">config</span><span class="o">.</span><span class="n">set_main_option</span><span class="p">(</span><span class="s">"script_location"</span><span class="p">,</span> <span class="s">"myapp:migrations"</span><span class="p">)</span> <span class="n">script</span> <span class="o">=</span> <span class="n">ScriptDirectory</span><span class="o">.</span><span class="n">from_config</span><span class="p">(</span><span class="n">config</span><span class="p">)</span> <span class="n">head_revision</span> <span class="o">=</span> <span class="n">script</span><span class="o">.</span><span class="n">get_current_head</span><span class="p">()</span> </pre></div> </div> <dl class="method"> <dt id="alembic.script.ScriptDirectory.as_revision_number"> <code class="descname">as_revision_number</code><span class="sig-paren">(</span><em>id_</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.as_revision_number" title="Permalink to this definition">¶</a></dt> <dd><p>Convert a symbolic revision, i.e. ‘head’ or ‘base’, into an actual revision number.</p> </dd></dl> <dl class="classmethod"> <dt id="alembic.script.ScriptDirectory.from_config"> <em class="property">classmethod </em><code class="descname">from_config</code><span class="sig-paren">(</span><em>config</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.from_config" title="Permalink to this definition">¶</a></dt> <dd><p>Produce a new <a class="reference internal" href="#alembic.script.ScriptDirectory" title="alembic.script.ScriptDirectory"><code class="xref py py-class docutils literal"><span class="pre">ScriptDirectory</span></code></a> given a <a class="reference internal" href="config.html#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal"><span class="pre">Config</span></code></a> instance.</p> <p>The <a class="reference internal" href="config.html#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal"><span class="pre">Config</span></code></a> need only have the <code class="docutils literal"><span class="pre">script_location</span></code> key present.</p> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.generate_revision"> <code class="descname">generate_revision</code><span class="sig-paren">(</span><em>revid</em>, <em>message</em>, <em>head=None</em>, <em>refresh=False</em>, <em>splice=False</em>, <em>branch_labels=None</em>, <em>version_path=None</em>, <em>depends_on=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.generate_revision" title="Permalink to this definition">¶</a></dt> <dd><p>Generate a new revision file.</p> <p>This runs the <code class="docutils literal"><span class="pre">script.py.mako</span></code> template, given template arguments, and creates a new file.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> <li><span class="target" id="alembic.script.ScriptDirectory.generate_revision.params.revid"></span><strong>revid</strong><a class="paramlink headerlink reference internal" href="#alembic.script.ScriptDirectory.generate_revision.params.revid">¶</a> – String revision id. Typically this comes from <code class="docutils literal"><span class="pre">alembic.util.rev_id()</span></code>.</li> <li><span class="target" id="alembic.script.ScriptDirectory.generate_revision.params.message"></span><strong>message</strong><a class="paramlink headerlink reference internal" href="#alembic.script.ScriptDirectory.generate_revision.params.message">¶</a> – the revision message, the one passed by the -m argument to the <code class="docutils literal"><span class="pre">revision</span></code> command.</li> <li><span class="target" id="alembic.script.ScriptDirectory.generate_revision.params.head"></span><strong>head</strong><a class="paramlink headerlink reference internal" href="#alembic.script.ScriptDirectory.generate_revision.params.head">¶</a> – <p>the head revision to generate against. Defaults to the current “head” if no branches are present, else raises an exception.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 0.7.0.</span></p> </div> </li> <li><span class="target" id="alembic.script.ScriptDirectory.generate_revision.params.splice"></span><strong>splice</strong><a class="paramlink headerlink reference internal" href="#alembic.script.ScriptDirectory.generate_revision.params.splice">¶</a> – if True, allow the “head” version to not be an actual head; otherwise, the selected head must be a head (e.g. endpoint) revision.</li> <li><span class="target" id="alembic.script.ScriptDirectory.generate_revision.params.refresh"></span><strong>refresh</strong><a class="paramlink headerlink reference internal" href="#alembic.script.ScriptDirectory.generate_revision.params.refresh">¶</a> – deprecated.</li> </ul> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.get_base"> <code class="descname">get_base</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.get_base" title="Permalink to this definition">¶</a></dt> <dd><p>Return the “base” revision as a string.</p> <p>This is the revision number of the script that has a <code class="docutils literal"><span class="pre">down_revision</span></code> of None.</p> <p>If the script directory has multiple bases, an error is raised; <a class="reference internal" href="#alembic.script.ScriptDirectory.get_bases" title="alembic.script.ScriptDirectory.get_bases"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.get_bases()</span></code></a> should be preferred.</p> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.get_bases"> <code class="descname">get_bases</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.get_bases" title="Permalink to this definition">¶</a></dt> <dd><p>return all “base” revisions as strings.</p> <p>This is the revision number of all scripts that have a <code class="docutils literal"><span class="pre">down_revision</span></code> of None.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 0.7.0.</span></p> </div> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.get_current_head"> <code class="descname">get_current_head</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.get_current_head" title="Permalink to this definition">¶</a></dt> <dd><p>Return the current head revision.</p> <p>If the script directory has multiple heads due to branching, an error is raised; <a class="reference internal" href="#alembic.script.ScriptDirectory.get_heads" title="alembic.script.ScriptDirectory.get_heads"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.get_heads()</span></code></a> should be preferred.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a string revision number.</td> </tr> </tbody> </table> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <p class="last"><a class="reference internal" href="#alembic.script.ScriptDirectory.get_heads" title="alembic.script.ScriptDirectory.get_heads"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.get_heads()</span></code></a></p> </div> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.get_heads"> <code class="descname">get_heads</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.get_heads" title="Permalink to this definition">¶</a></dt> <dd><p>Return all “versioned head” revisions as strings.</p> <p>This is normally a list of length one, unless branches are present. The <a class="reference internal" href="#alembic.script.ScriptDirectory.get_current_head" title="alembic.script.ScriptDirectory.get_current_head"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.get_current_head()</span></code></a> method can be used normally when a script directory has only one head.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a tuple of string revision numbers.</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.get_revision"> <code class="descname">get_revision</code><span class="sig-paren">(</span><em>id_</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.get_revision" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> instance with the given rev id.</p> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <p class="last"><a class="reference internal" href="#alembic.script.ScriptDirectory.get_revisions" title="alembic.script.ScriptDirectory.get_revisions"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.get_revisions()</span></code></a></p> </div> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.get_revisions"> <code class="descname">get_revisions</code><span class="sig-paren">(</span><em>id_</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.get_revisions" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> instance with the given rev identifier, symbolic name, or sequence of identifiers.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 0.7.0.</span></p> </div> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.iterate_revisions"> <code class="descname">iterate_revisions</code><span class="sig-paren">(</span><em>upper</em>, <em>lower</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.iterate_revisions" title="Permalink to this definition">¶</a></dt> <dd><p>Iterate through script revisions, starting at the given upper revision identifier and ending at the lower.</p> <p>The traversal uses strictly the <cite>down_revision</cite> marker inside each migration script, so it is a requirement that upper >= lower, else you’ll get nothing back.</p> <p>The iterator yields <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> objects.</p> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <p class="last"><a class="reference internal" href="#alembic.script.revision.RevisionMap.iterate_revisions" title="alembic.script.revision.RevisionMap.iterate_revisions"><code class="xref py py-meth docutils literal"><span class="pre">RevisionMap.iterate_revisions()</span></code></a></p> </div> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.run_env"> <code class="descname">run_env</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.run_env" title="Permalink to this definition">¶</a></dt> <dd><p>Run the script environment.</p> <p>This basically runs the <code class="docutils literal"><span class="pre">env.py</span></code> script present in the migration environment. It is called exclusively by the command functions in <a class="reference internal" href="commands.html#module-alembic.command" title="alembic.command"><code class="xref py py-mod docutils literal"><span class="pre">alembic.command</span></code></a>.</p> </dd></dl> <dl class="method"> <dt id="alembic.script.ScriptDirectory.walk_revisions"> <code class="descname">walk_revisions</code><span class="sig-paren">(</span><em>base='base'</em>, <em>head='heads'</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.ScriptDirectory.walk_revisions" title="Permalink to this definition">¶</a></dt> <dd><p>Iterate through all revisions.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> <li><span class="target" id="alembic.script.ScriptDirectory.walk_revisions.params.base"></span><strong>base</strong><a class="paramlink headerlink reference internal" href="#alembic.script.ScriptDirectory.walk_revisions.params.base">¶</a> – the base revision, or “base” to start from the empty revision.</li> <li><span class="target" id="alembic.script.ScriptDirectory.walk_revisions.params.head"></span><strong>head</strong><a class="paramlink headerlink reference internal" href="#alembic.script.ScriptDirectory.walk_revisions.params.head">¶</a> – <p>the head revision; defaults to “heads” to indicate all head revisions. May also be “head” to indicate a single head revision.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 0.7.0: </span>the “head” identifier now refers to the head of a non-branched repository only; use “heads” to refer to the set of all head branches simultaneously.</p> </div> </li> </ul> </td> </tr> </tbody> </table> </dd></dl> </dd></dl> <dl class="class"> <dt id="alembic.script.Script"> <em class="property">class </em><code class="descclassname">alembic.script.</code><code class="descname">Script</code><span class="sig-paren">(</span><em>module</em>, <em>rev_id</em>, <em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.Script" title="Permalink to this definition">¶</a></dt> <dd><p>Represent a single revision file in a <code class="docutils literal"><span class="pre">versions/</span></code> directory.</p> <p>The <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> instance is returned by methods such as <a class="reference internal" href="#alembic.script.ScriptDirectory.iterate_revisions" title="alembic.script.ScriptDirectory.iterate_revisions"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.iterate_revisions()</span></code></a>.</p> <dl class="attribute"> <dt id="alembic.script.Script.doc"> <code class="descname">doc</code><a class="headerlink" href="#alembic.script.Script.doc" title="Permalink to this definition">¶</a></dt> <dd><p>Return the docstring given in the script.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.Script.longdoc"> <code class="descname">longdoc</code><a class="headerlink" href="#alembic.script.Script.longdoc" title="Permalink to this definition">¶</a></dt> <dd><p>Return the docstring given in the script.</p> </dd></dl> </dd></dl> <div class="section" id="revision"> <h2>Revision<a class="headerlink" href="#revision" title="Permalink to this headline">¶</a></h2> <p>The <a class="reference internal" href="#alembic.script.revision.RevisionMap" title="alembic.script.revision.RevisionMap"><code class="xref py py-class docutils literal"><span class="pre">RevisionMap</span></code></a> object serves as the basis for revision management, used exclusively by <a class="reference internal" href="#alembic.script.ScriptDirectory" title="alembic.script.ScriptDirectory"><code class="xref py py-class docutils literal"><span class="pre">ScriptDirectory</span></code></a>.</p> <span class="target" id="module-alembic.script.revision"></span><dl class="class"> <dt id="alembic.script.revision.Revision"> <em class="property">class </em><code class="descclassname">alembic.script.revision.</code><code class="descname">Revision</code><span class="sig-paren">(</span><em>revision</em>, <em>down_revision</em>, <em>dependencies=None</em>, <em>branch_labels=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.revision.Revision" title="Permalink to this definition">¶</a></dt> <dd><p>Base class for revisioned objects.</p> <p>The <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> class is the base of the more public-facing <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> object, which represents a migration script. The mechanics of revision management and traversal are encapsulated within <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a>, while <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> applies this logic to Python files in a version directory.</p> <dl class="attribute"> <dt id="alembic.script.revision.Revision.branch_labels"> <code class="descname">branch_labels</code><em class="property"> = None</em><a class="headerlink" href="#alembic.script.revision.Revision.branch_labels" title="Permalink to this definition">¶</a></dt> <dd><p>Optional string/tuple of symbolic names to apply to this revision’s branch</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.dependencies"> <code class="descname">dependencies</code><em class="property"> = None</em><a class="headerlink" href="#alembic.script.revision.Revision.dependencies" title="Permalink to this definition">¶</a></dt> <dd><p>Additional revisions which this revision is dependent on.</p> <p>From a migration standpoint, these dependencies are added to the down_revision to form the full iteration. However, the separation of down_revision from “dependencies” is to assist in navigating a history that contains many branches, typically a multi-root scenario.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.down_revision"> <code class="descname">down_revision</code><em class="property"> = None</em><a class="headerlink" href="#alembic.script.revision.Revision.down_revision" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal"><span class="pre">down_revision</span></code> identifier(s) within the migration script.</p> <p>Note that the total set of “down” revisions is down_revision + dependencies.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.is_base"> <code class="descname">is_base</code><a class="headerlink" href="#alembic.script.revision.Revision.is_base" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if this <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> is a ‘base’ revision.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.is_branch_point"> <code class="descname">is_branch_point</code><a class="headerlink" href="#alembic.script.revision.Revision.is_branch_point" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if this <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> is a branch point.</p> <p>A branchpoint is defined as a <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> which is referred to by more than one succeeding <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a>, that is more than one <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> has a <cite>down_revision</cite> identifier pointing here.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.is_head"> <code class="descname">is_head</code><a class="headerlink" href="#alembic.script.revision.Revision.is_head" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if this <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> is a ‘head’ revision.</p> <p>This is determined based on whether any other <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> within the <a class="reference internal" href="#alembic.script.ScriptDirectory" title="alembic.script.ScriptDirectory"><code class="xref py py-class docutils literal"><span class="pre">ScriptDirectory</span></code></a> refers to this <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a>. Multiple heads can be present.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.is_merge_point"> <code class="descname">is_merge_point</code><a class="headerlink" href="#alembic.script.revision.Revision.is_merge_point" title="Permalink to this definition">¶</a></dt> <dd><p>Return True if this <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> is a merge point.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.nextrev"> <code class="descname">nextrev</code><em class="property"> = frozenset([])</em><a class="headerlink" href="#alembic.script.revision.Revision.nextrev" title="Permalink to this definition">¶</a></dt> <dd><p>following revisions, based on down_revision only.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.Revision.revision"> <code class="descname">revision</code><em class="property"> = None</em><a class="headerlink" href="#alembic.script.revision.Revision.revision" title="Permalink to this definition">¶</a></dt> <dd><p>The string revision number.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="alembic.script.revision.RevisionMap"> <em class="property">class </em><code class="descclassname">alembic.script.revision.</code><code class="descname">RevisionMap</code><span class="sig-paren">(</span><em>generator</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.revision.RevisionMap" title="Permalink to this definition">¶</a></dt> <dd><p>Maintains a map of <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> objects.</p> <p><a class="reference internal" href="#alembic.script.revision.RevisionMap" title="alembic.script.revision.RevisionMap"><code class="xref py py-class docutils literal"><span class="pre">RevisionMap</span></code></a> is used by <a class="reference internal" href="#alembic.script.ScriptDirectory" title="alembic.script.ScriptDirectory"><code class="xref py py-class docutils literal"><span class="pre">ScriptDirectory</span></code></a> to maintain and traverse the collection of <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> objects, which are themselves instances of <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a>.</p> <p>Construct a new <a class="reference internal" href="#alembic.script.revision.RevisionMap" title="alembic.script.revision.RevisionMap"><code class="xref py py-class docutils literal"><span class="pre">RevisionMap</span></code></a>.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.script.revision.RevisionMap.params.generator"></span><strong>generator</strong><a class="paramlink headerlink reference internal" href="#alembic.script.revision.RevisionMap.params.generator">¶</a> – a zero-arg callable that will generate an iterable of <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> instances to be used. These are typically <a class="reference internal" href="#alembic.script.Script" title="alembic.script.Script"><code class="xref py py-class docutils literal"><span class="pre">Script</span></code></a> subclasses within regular Alembic use.</td> </tr> </tbody> </table> <dl class="method"> <dt id="alembic.script.revision.RevisionMap.add_revision"> <code class="descname">add_revision</code><span class="sig-paren">(</span><em>revision</em>, <em>_replace=False</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.revision.RevisionMap.add_revision" title="Permalink to this definition">¶</a></dt> <dd><p>add a single revision to an existing map.</p> <p>This method is for single-revision use cases, it’s not appropriate for fully populating an entire revision map.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.RevisionMap.bases"> <code class="descname">bases</code><a class="headerlink" href="#alembic.script.revision.RevisionMap.bases" title="Permalink to this definition">¶</a></dt> <dd><p>All “base” revisions as strings.</p> <p>These are revisions that have a <code class="docutils literal"><span class="pre">down_revision</span></code> of None, or empty tuple.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a tuple of string revision numbers.</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="alembic.script.revision.RevisionMap.get_current_head"> <code class="descname">get_current_head</code><span class="sig-paren">(</span><em>branch_label=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.revision.RevisionMap.get_current_head" title="Permalink to this definition">¶</a></dt> <dd><p>Return the current head revision.</p> <p>If the script directory has multiple heads due to branching, an error is raised; <a class="reference internal" href="#alembic.script.ScriptDirectory.get_heads" title="alembic.script.ScriptDirectory.get_heads"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.get_heads()</span></code></a> should be preferred.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.script.revision.RevisionMap.get_current_head.params.branch_label"></span><strong>branch_label</strong><a class="paramlink headerlink reference internal" href="#alembic.script.revision.RevisionMap.get_current_head.params.branch_label">¶</a> – optional branch name which will limit the heads considered to those which include that branch_label.</td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a string revision number.</td> </tr> </tbody> </table> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <p class="last"><a class="reference internal" href="#alembic.script.ScriptDirectory.get_heads" title="alembic.script.ScriptDirectory.get_heads"><code class="xref py py-meth docutils literal"><span class="pre">ScriptDirectory.get_heads()</span></code></a></p> </div> </dd></dl> <dl class="method"> <dt id="alembic.script.revision.RevisionMap.get_revision"> <code class="descname">get_revision</code><span class="sig-paren">(</span><em>id_</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.revision.RevisionMap.get_revision" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> instance with the given rev id.</p> <p>If a symbolic name such as “head” or “base” is given, resolves the identifier into the current head or base revision. If the symbolic name refers to multiples, <code class="xref py py-class docutils literal"><span class="pre">MultipleHeads</span></code> is raised.</p> <p>Supports partial identifiers, where the given identifier is matched against all identifiers that start with the given characters; if there is exactly one match, that determines the full revision.</p> </dd></dl> <dl class="method"> <dt id="alembic.script.revision.RevisionMap.get_revisions"> <code class="descname">get_revisions</code><span class="sig-paren">(</span><em>id_</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.revision.RevisionMap.get_revisions" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> instances with the given rev id or identifiers.</p> <p>May be given a single identifier, a sequence of identifiers, or the special symbols “head” or “base”. The result is a tuple of one or more identifiers, or an empty tuple in the case of “base”.</p> <p>In the cases where ‘head’, ‘heads’ is requested and the revision map is empty, returns an empty tuple.</p> <p>Supports partial identifiers, where the given identifier is matched against all identifiers that start with the given characters; if there is exactly one match, that determines the full revision.</p> </dd></dl> <dl class="attribute"> <dt id="alembic.script.revision.RevisionMap.heads"> <code class="descname">heads</code><a class="headerlink" href="#alembic.script.revision.RevisionMap.heads" title="Permalink to this definition">¶</a></dt> <dd><p>All “head” revisions as strings.</p> <p>This is normally a tuple of length one, unless unmerged branches are present.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a tuple of string revision numbers.</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="alembic.script.revision.RevisionMap.iterate_revisions"> <code class="descname">iterate_revisions</code><span class="sig-paren">(</span><em>upper</em>, <em>lower</em>, <em>implicit_base=False</em>, <em>inclusive=False</em>, <em>assert_relative_length=True</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.script.revision.RevisionMap.iterate_revisions" title="Permalink to this definition">¶</a></dt> <dd><p>Iterate through script revisions, starting at the given upper revision identifier and ending at the lower.</p> <p>The traversal uses strictly the <cite>down_revision</cite> marker inside each migration script, so it is a requirement that upper >= lower, else you’ll get nothing back.</p> <p>The iterator yields <a class="reference internal" href="#alembic.script.revision.Revision" title="alembic.script.revision.Revision"><code class="xref py py-class docutils literal"><span class="pre">Revision</span></code></a> objects.</p> </dd></dl> </dd></dl> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Script Directory</a><ul> <li><a class="reference internal" href="#revision">Revision</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="autogenerate.html" title="previous chapter">Autogeneration</a></p> <h4>Next topic</h4> <p class="topless"><a href="ddl.html" title="next chapter">DDL Internals</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/api/script.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="ddl.html" title="DDL Internals" >next</a> |</li> <li class="right" > <a href="autogenerate.html" title="Autogeneration" >previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Alembic 0.8.3 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >API Details</a> »</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2010-2015, Mike Bayer. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1. </div> </body> </html>