Skip to content
Snippets Groups Projects
Commit 0025c1c5 authored by Benjamin Ledel's avatar Benjamin Ledel
Browse files

* adjust index creation for lrs

parent a862d36e
No related branches found
No related tags found
1 merge request!1#155: fixed data disclosure tests for environments where no mongodb is...
......@@ -14,6 +14,7 @@ class Command(BaseCommand):
{"key": [("name", ASCENDING)], "name": "name_1"},
{"key": [("created_at", DESCENDING)], "name": "created_at_-1"},
{"key": [("name", ASCENDING), ("created_at", DESCENDING)], "name": "name_1_created_at_-1"},
{"key": [("context_id", HASHED), ("name", ASCENDING), ("created_at", DESCENDING)], "name": "context_name_1_created_at_-1"},
],
"statement": [
{"key": [("_id", ASCENDING)], "name": "_id_"},
......@@ -25,6 +26,14 @@ class Command(BaseCommand):
# Iterate through each collection and create indexes
for collection_name, indexes in collections_indexes.items():
if collection_name not in lrs_db.list_collection_names():
self.stdout.write(self.style.WARNING(
f"Collection '{collection_name}' does not exist. Creating collection..."
))
# Force collection creation by inserting and deleting a dummy doc
lrs_db[collection_name].insert_one({"_init": True})
lrs_db[collection_name].delete_one({"_init": True})
collection = lrs_db[collection_name]
self.stdout.write(self.style.SUCCESS(f"Creating indexes for collection: {collection_name}"))
for index in indexes:
......
......@@ -244,6 +244,7 @@ class BaseTestCase(TransactionTestCase):
def setUp(self):
call_command('check_and_apply_migrations')
call_command('create_mongo_index')
normal_user = CustomUser.objects.create_user(
self.test_user_email, self.test_user_password
)
......
......@@ -6,6 +6,9 @@
echo "Running database migrations and role setup..."
python manage.py check_and_apply_migrations
echo "Running mongodb check..."
python manage.py create_mongo_index
echo "Starting Gunicorn server with $WORKERS workers..."
exec env "$@" gunicorn \
--bind :80 \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment