old_contents: #!/usr/bin/env python
  
  # Copyright (C) 2016 University of Zurich.  All rights reserved.
  #
  # This file is part of MSRegistry Backend.
  #
  # MSRegistry Backend is free software: you can redistribute it and/or
  # modify it under the terms of the version 3 of the GNU Affero General
  # Public License as published by the Free Software Foundation, or any
  # other later version.
  #
  # MSRegistry Backend is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the version
  # 3 of the GNU Affero General Public License for more details.
  #
  # You should have received a copy of the version 3 of the GNU Affero
  # General Public License along with MSRegistry Backend.  If not, see 
  # <http://www.gnu.org/licenses/>.
  
  __author__ = "Filippo Panessa <filippo.panessa@uzh.ch>"
  __copyright__ = ("Copyright (c) 2016 S3IT, Zentrale Informatik,"
  " University of Zurich")
  
  import os
  
  from app import create_app, db
  from app.models import User, Survey
  
  from flask.ext.migrate import Migrate, MigrateCommand
  from flask.ext.script import Manager, prompt_bool
  
  
  app = create_app(os.getenv('FLASK_CONFIG') or 'DEFAULT')
  manager = Manager(app)
  migrate = Migrate(app, db)
  
  @manager.shell
  def make_shell_context():
      return dict(app=app, db=db, User=User, Survey=Survey)
  
  manager.add_command('db', MigrateCommand)
  
  @manager.command
  def test(coverage=False):
      """Run the unit tests."""
      if coverage and not os.environ.get('FLASK_COVERAGE'):
          import sys
          os.environ['FLASK_COVERAGE'] = '1'
          os.execvp(sys.executable, [sys.executable] + sys.argv)
      import unittest
      tests = unittest.TestLoader().discover('tests')
      unittest.TextTestRunner(verbosity=2).run(tests)
  
  
  @manager.command
  def profile(length=25, profile_dir=None):
      """Start the application under the code profiler."""
      from werkzeug.contrib.profiler import ProfilerMiddleware
      app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[length],
                                        profile_dir=profile_dir)
      app.run()
  
  
  @manager.command
  def deploy():
      """Run deployment tasks."""
      from flask.ext.migrate import upgrade
  
      # migrate database to latest revision
      upgrade()
  
  
  @manager.command
  def create():
      "Creates database tables"
      db.create_all()
      db.session.commit()
  
  
  @manager.command
  def drop():
      "Drops all database tables"
      if prompt_bool("Are you sure ? You will lose all your data !"):
          db.drop_all()
          db.session.commit()
  
  
  if __name__ == '__main__':
      manager.run()
  
  
new_contents: #!/usr/bin/env python
  
  # Copyright (C) 2016 University of Zurich.  All rights reserved.
  #
  # This file is part of MSRegistry Backend.
  #
  # MSRegistry Backend is free software: you can redistribute it and/or
  # modify it under the terms of the version 3 of the GNU Affero General
  # Public License as published by the Free Software Foundation, or any
  # other later version.
  #
  # MSRegistry Backend is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the version
  # 3 of the GNU Affero General Public License for more details.
  #
  # You should have received a copy of the version 3 of the GNU Affero
  # General Public License along with MSRegistry Backend.  If not, see 
  # <http://www.gnu.org/licenses/>.
  
  __author__ = "Filippo Panessa <filippo.panessa@uzh.ch>"
  __copyright__ = ("Copyright (c) 2016 S3IT, Zentrale Informatik,"
  " University of Zurich")
  
  import os
  
  from app import create_app, db
  from app.models import User, Survey
  
  from flask.ext.migrate import Migrate, MigrateCommand
  from flask.ext.script import Manager, prompt_bool
  
  
  app = create_app(os.getenv('FLASK_CONFIG') or 'DEFAULT')
  manager = Manager(app)
  migrate = Migrate(app, db)
  
  @manager.shell
  def make_shell_context():
      return dict(app=app, db=db, User=User, Survey=Survey)
  
  manager.add_command('db', MigrateCommand)
  
  @manager.command
  def test(coverage=False):
      """Run the unit tests."""
      if coverage and not os.environ.get('FLASK_COVERAGE'):
          import sys
          os.environ['FLASK_COVERAGE'] = '1'
          os.execvp(sys.executable, [sys.executable] + sys.argv)
      import unittest
      tests = unittest.TestLoader().discover('tests')
      unittest.TextTestRunner(verbosity=2).run(tests)
  
  
  @manager.command
  def profile(length=25, profile_dir=None):
      """Start the application under the code profiler."""
      from werkzeug.contrib.profiler import ProfilerMiddleware
      app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[length],
                                        profile_dir=profile_dir)
      app.run()
  
  
  @manager.command
  def deploy():
      """Run deployment tasks."""
      from flask.ext.migrate import upgrade
  
      # migrate database to latest revision
      upgrade()
  
  
  @manager.command
  def create():
      "Creates database tables"
      db.create_all()
  
  
  @manager.command
  def drop():
      "Drops all database tables"
      if prompt_bool("Are you sure ? You will lose all your data !"):
          db.drop_all()
  
  
  if __name__ == '__main__':
      manager.run()
  
  
subject: Remove unnecessary db.commit() from manager