summaryrefslogtreecommitdiff
path: root/alembic/command.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-09-18 23:16:56 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-09-19 13:57:49 -0400
commitfdcc5bf973fec758eaf67cf8e8ad48985caffb65 (patch)
tree5c14bcff43139d96683b638a473899d2b7c9bf01 /alembic/command.py
parent3398e6b5a5175009c9d7047df0c1bbf9891c6610 (diff)
downloadalembic-fdcc5bf973fec758eaf67cf8e8ad48985caffb65.tar.gz
Add multiple revision support to stamp, support purge
Added new ``--purge`` flag to the ``alembic stamp`` command, which will unconditionally erase the version table before stamping anything. This is useful for development where non-existent version identifiers might be left within the table. Additionally, ``alembic.stamp`` now supports a list of revision identifiers, which are intended to allow setting up muliple heads at once. Overall handling of version identifiers within the ``alembic.stamp`` command has been improved with many new tests and use cases added. Fixes: #473 Change-Id: If06501b69afae9956df3d0bcd739063fb8042a02
Diffstat (limited to 'alembic/command.py')
-rw-r--r--alembic/command.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/alembic/command.py b/alembic/command.py
index c02db62..fde74d9 100644
--- a/alembic/command.py
+++ b/alembic/command.py
@@ -496,7 +496,7 @@ def current(config, verbose=False, head_only=False):
script.run_env()
-def stamp(config, revision, sql=False, tag=None):
+def stamp(config, revisions, sql=False, tag=None, purge=False):
"""'stamp' the revision table with the given revision; don't
run any migrations.
@@ -510,27 +510,45 @@ def stamp(config, revision, sql=False, tag=None):
``env.py`` scripts via the :class:`.EnvironmentContext.get_tag_argument`
method.
+ :param purge: delete all entries in the version table before stamping.
+
+ .. versionadded:: 1.2
+
"""
script = ScriptDirectory.from_config(config)
- starting_rev = None
- if ":" in revision:
- if not sql:
- raise util.CommandError("Range revision not allowed")
- starting_rev, revision = revision.split(":", 2)
+ if sql:
+ destination_revs = []
+ starting_rev = None
+ for revision in util.to_list(revisions):
+ if ":" in revision:
+ srev, revision = revision.split(":", 2)
+
+ if starting_rev != srev:
+ if starting_rev is None:
+ starting_rev = srev
+ else:
+ raise util.CommandError(
+ "Stamp operation with --sql only supports a "
+ "single starting revision at a time"
+ )
+ destination_revs.append(revision)
+ else:
+ destination_revs = util.to_list(revisions)
def do_stamp(rev, context):
- return script._stamp_revs(revision, rev)
+ return script._stamp_revs(util.to_tuple(destination_revs), rev)
with EnvironmentContext(
config,
script,
fn=do_stamp,
as_sql=sql,
- destination_rev=revision,
- starting_rev=starting_rev,
+ starting_rev=starting_rev if sql else None,
+ destination_rev=util.to_tuple(destination_revs),
tag=tag,
+ purge=purge,
):
script.run_env()