Skip to content

Commit

Permalink
Add annoying prompt for verdi database migrate (#2488)
Browse files Browse the repository at this point in the history
- Replace the existing yes/no confirmation with an annoying and scary three-stage prompt.
  The goal is to prevent casual use of verdi database migrate as it may not be possible
  to revert a database back to the pre v1.0 state.
- Add `NotImplementedError` when using `--force``. We want to keep the option available in the
  cmdline as a placeholder, but disable its use until the v1.0 are well tested and proven to be
  revertable.
  • Loading branch information
ConradJohnston authored and sphuber committed Feb 16, 2019
1 parent 9489070 commit dace59e
Showing 1 changed file with 60 additions and 7 deletions.
67 changes: 60 additions & 7 deletions aiida/cmdline/commands/cmd_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,67 @@ def database_migrate(force):
profile = manager.get_profile()
backend = manager._load_backend(schema_check=False) # pylint: disable=protected-access

if not force:
echo.echo_warning('Migrating your database might take a while.')
echo.echo_warning('Before continuing, make sure the daemon is stopped and you have a backup of your database.')
echo.echo_warning('', nl=False)
confirm_message = 'Are you really sure you want to migrate the database for profile "{}"?'.format(profile.name)
click.confirm(confirm_message, abort=True)
if force:
raise NotImplementedError('--force is disabled currently to prevent accidental migrations.')

echo.echo('\n' + '*' * 79 + '\n')
echo.echo_warning('Before continuing, make sure the daemon is stopped and you have a backup of your database.')
echo.echo_warning(
'It is ESSENTIAL to have a backup of your database - once you do this migration you can NEVER go back!')
echo.echo_warning('You will be committed to this new version of AiiDA.')
echo.echo_warning('Please be patient - migrating your database might take a while.')

backend.migrate()
echo.echo('\n' + '*' * 79 + '\n')

try:
# First prompt
backup_prompt = 'Have you got a back up of the database for profile "{}"?'.format(profile.name)
echo.echo_warning(backup_prompt)
echo.echo_warning('', nl=False)
confirm_message = 'Type "I DO HAVE A BACKUP"'
response = ''
while response != 'I DO HAVE A BACKUP':
response = click.prompt(confirm_message)

# Second prompt
echo.echo('')
echo.echo_warning('Have you stopped the daemon?')
echo.echo_warning('', nl=False)
confirm_message = 'Type "I HAVE STOPPED THE DAEMON"'
response = ''
while response != 'I HAVE STOPPED THE DAEMON':
response = click.prompt(confirm_message)

# Final prompt
echo.echo('')
message = 'Are you absolutely ready to migrate profile "{}"? This will be PERMANENT.'.format(profile.name)
echo.echo_warning(message)
echo.echo_warning('', nl=False)
confirm_message = 'Type "MAKE IT SO"'
response = ''
while response != 'MAKE IT SO':
response = click.prompt(confirm_message)

# Do the migration
echo.echo('\nRunning the migrations...\n')
backend.migrate()

except click.Abort:
echo.echo('\n')
echo.echo_critical('Cannot start the migration without a positive confirmation. '
'Your data has not been affected.')

# Below is the `old` behaviour from the `provenance_redesign branch`. We may replace the above
# with this in the future, but for v1.0.0b release, we're using the above logic to emphasise
# the severity of choosing to execute this migration.
# if not force:
# echo.echo_warning('Migrating your database might take a while.')
# echo.echo_warning('Before continuing, make sure the daemon is stopped and you have a backup of your database.')
# echo.echo_warning('', nl=False)
# confirm_message = 'Are you really sure you want to migrate the database for profile "{}"?'.format(profile.name)
# click.confirm(confirm_message, abort=True)

#backend.migrate()


@verdi_database.group('integrity')
Expand Down

0 comments on commit dace59e

Please sign in to comment.