Commit fc014701 authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Fix load docs only one time

parent 71e1b7aa
Pipeline #139482 passed with stages
in 10 minutes and 13 seconds
......@@ -54,7 +54,7 @@ def db(ctx, server, name):
@click.argument('initdata', type=click.File('rb'), nargs=-1)
@click.make_pass_decorator(Database)
def init(database, initdata):
management.init_db(database, initdata)
management.init_db(database, initdata=initdata)
click.secho(
'Sucessfully initialized database {}.'.format(database.name),
fg='green'
......
......@@ -21,14 +21,16 @@ def check_server_maintenance_mode(server):
def set_server_maintenance(server, value):
server.maintenance(value)
def init_db(database, initdata):
def init_db(database, initdata=None, docs=None):
if not Expressions.GROUP.match(database.name):
raise ManagementException(
'Database for group should have the form "group[0-9]+"'
)
database.create_if_not_exists()
if len(initdata) > 0:
if initdata is not None and len(initdata) > 0:
database.bulk_create(utils.import_docs(initdata))
if docs is not None:
database.bulk_create(docs)
database.security({
'members': { 'roles': ['_admin', database.name, 'mgmt_backup'] },
'admins': { 'roles': ['_admin'] }
......@@ -81,6 +83,7 @@ def init_server(server, usersfile, passwordsfile, initdata):
writer = utils.csv_writer(passwordsfile)
users = utils.import_csv(usersfile)
groups = defaultdict(list)
docs = utils.import_docs(initdata)
for i, (username, group) in enumerate(users):
if not Expressions.GROUP.match(group):
raise ManagementException(
......@@ -94,7 +97,7 @@ def init_server(server, usersfile, passwordsfile, initdata):
database.server = server
database.name = group
if not database.exists():
init_db(database, initdata)
init_db(database, docs=docs)
for username in users:
user = User()
user.server = server
......
Supports Markdown
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