Commit fcb1a0f1 authored by François Ferry's avatar François Ferry
Browse files

fix(db-create): don't force to use --drop if there is no existing db.

related: #202
parent 0827e00b6a66
Pipeline #39258 passed with stage
in 1 minute and 30 seconds
......@@ -403,12 +403,17 @@ class CreateInstanceDBCommand(Command):
ASK.confirm('Create db user %s ?' % user, default_is_yes=False)):
helper.create_user(source['db-user'], source.get('db-password'))
print('-> user %s created.' % user)
if dbname in helper.list_databases(cursor) and should_drop_db():
cursor.execute('DROP DATABASE "%s"' % dbname)
else:
print('you may want to run "cubicweb-ctl db-create '
'--drop %s" to continue.' % config.appid)
return
if dbname in helper.list_databases(cursor):
if should_drop_db():
cursor.execute('DROP DATABASE "%s"' % dbname)
else:
print(
'The database %s already exists, but automatically dropping it '
'is currently forbidden. You may want to run '
'"cubicweb-ctl db-create --drop=y %s" to continue or '
'"cubicweb-ctl db-create --help" to get help.'
% (dbname, config.appid))
raise Exception('Not allowed to drop existing database.')
createdb(helper, source, dbcnx, cursor)
dbcnx.commit()
print('-> database %s created.' % dbname)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment