old_contents: import os.path
  from migrate.versioning import api
  from flask.ext.script import Manager, prompt_bool
  
  from config import SQLALCHEMY_DATABASE_URI
  from config import SQLALCHEMY_MIGRATE_REPO
  
  from viscount import app
  from viscount.database import db
  
  manager = Manager(usage="Perform database operations")
  
  @manager.command
  def drop():
  	"Drops database tables"
  	if prompt_bool("Are you sure you want to lose all your data"):
  		db.drop_all()
  
  @manager.command
  def create(default_data=True, sample_data=False):
  	"Creates database tables from sqlalchemy models"
  	db.create_all()
  	if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
  		api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
  		api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	populate(default_data, sample_data)
  
  
  @manager.command
  def recreate(default_data=True, sample_data=False):
  	"Recreates database tables (same as issuing 'drop' and then 'create')"
  	drop()
  	create(default_data, sample_data)
  
  
  @manager.command
  def populate(default_data=False, sample_data=False):
  	"Populate database with default data"
  
  	if default_data:
  		from viscount.database import init_defaults
  		init_defaults()
  
  	if sample_data:
  		from viscount.database import init_samples
  		init_sample(s)
  
  @manager.command
  def migrate():
  	"Migrate data model"
  
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1))
  	tmp_module = imp.new_module('old_model')
  	old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	exec(old_model, tmp_module.__dict__)
  	script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
  	open(migration, "wt").write(script)
  	api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	print('New migration saved as ' + migration)
  	print('Current database version: ' + str(v))
  
  @manager.command
  def upgrade():
  	"Upgrade data model"
  
  	api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	print('Current database version: ' + str(v))
  
  @manager.command
  def downgrade():
  	"Downgrade data model"
  
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	api.downgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, v - 1)
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	print('Current database version: ' + str(v))
  
new_contents: import os.path
  from migrate.versioning import api
  from flask.ext.script import Manager, prompt_bool
  
  from config import SQLALCHEMY_DATABASE_URI
  from config import SQLALCHEMY_MIGRATE_REPO
  
  from viscount import app
  from viscount.database import db
  
  manager = Manager(usage="Perform database operations")
  
  @manager.command
  def drop():
  	"Drops database tables"
  	if prompt_bool("Are you sure you want to lose all your data"):
  		db.drop_all()
  
  @manager.command
  def create(default_data=True, sample_data=True):
  	"Creates database tables from sqlalchemy models"
  	db.create_all()
  	if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
  		api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
  		api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	populate(default_data, sample_data)
  
  
  @manager.command
  def recreate(default_data=True, sample_data=True):
  	"Recreates database tables (same as issuing 'drop' and then 'create')"
  	drop()
  	create(default_data, sample_data)
  
  
  @manager.command
  def populate(default_data=False, sample_data=False):
  	"Populate database with default data"
  
  	if default_data:
  		from viscount.database import init_defaults
  		init_defaults()
  
  	if sample_data:
  		from viscount.database import init_samples
  		init_samples()
  
  @manager.command
  def migrate():
  	"Migrate data model"
  
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1))
  	tmp_module = imp.new_module('old_model')
  	old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	exec(old_model, tmp_module.__dict__)
  	script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
  	open(migration, "wt").write(script)
  	api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	print('New migration saved as ' + migration)
  	print('Current database version: ' + str(v))
  
  @manager.command
  def upgrade():
  	"Upgrade data model"
  
  	api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	print('Current database version: ' + str(v))
  
  @manager.command
  def downgrade():
  	"Downgrade data model"
  
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	api.downgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, v - 1)
  	v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  	print('Current database version: ' + str(v))
  
subject: fix create sample data for recreate target