Skip to content

Commit

Permalink
Add edit command
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Sep 16, 2015
1 parent 0e035d1 commit e9c855c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ The application will now have a ``db`` command line option with several sub-comm

- ``manage.py db migrate [--message MESSAGE] [--sql] [--head HEAD] [--splice] [--branch-label BRANCH_LABEL] [--version-path VERSION_PATH] [--rev-id REV_ID]``
Equivalent to ``revision --autogenerate``. The migration script is populated with changes detected automatically. The generated script should to be reviewed and edited as not all types of changes can be detected. This command does not make any changes to the database.


- ``manage.py db edit <revision>``
Edit revision script(s) using $EDITOR.

- ``manage.py db upgrade [--sql] [--tag TAG] [--x-arg ARG] <revision>``
Upgrades the database. If ``revision`` isn't given then ``"head"`` is assumed.

Expand Down Expand Up @@ -150,6 +153,9 @@ The commands exposed by Flask-Migrate's interface to Flask-Script can also be ac
- ``migrate(directory='migrations', message=None, sql=False, head='head', splice=False, branch_label=None, version_path=None, rev_id=None)``
Creates an automatic revision script.

- ``edit(directory='migrations', revision='head')``
Edit revision script(s) using $EDITOR.

- ``merge(directory='migrations', revisions='', message=None, branch_label=None, rev_id=None)``
Merge two revisions together. Creates a new migration file.

Expand Down
14 changes: 14 additions & 0 deletions flask_migrate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ def migrate(directory=None, message=None, sql=False, head='head', splice=False,
command.revision(config, message, autogenerate=True, sql=sql)


@MigrateCommand.option('revision', nargs='?', default='head',
help="revision identifier")
@MigrateCommand.option('-d', '--directory', dest='directory', default=None,
help=("migration script directory (default is "
"'migrations')"))
def edit(revision='current', directory=None):
"""Upgrade to a later version"""
if alembic_version >= (0, 8, 0):
config = _get_config(directory)
command.edit(config, revision)
else:
raise RuntimeError('Alembic 0.8.0 or greater is required')


@MigrateCommand.option('--rev-id', dest='rev_id', default=None,
help=('Specify a hardcoded revision id instead of '
'generating one'))
Expand Down

0 comments on commit e9c855c

Please sign in to comment.