Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edit command #76

Merged
merged 1 commit into from
Sep 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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