Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions backend/src/xfd_django/xfd_api/tasks/run_syncdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Third-Party Libraries
import django
from django.core.management import call_command

# Set the Django settings module
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xfd_django.settings")
Expand All @@ -12,44 +13,14 @@
# Initialize Django
django.setup()

# Third-Party Libraries
from xfd_api.tasks.syncdb_helpers import (
drop_all_tables,
manage_elasticsearch_indices,
populate_sample_data,
sync_es_organizations,
synchronize,
)


def handler(event, context):
"""Trigger syncdb."""
dangerouslyforce = event.get("dangerouslyforce", False)
populate = event.get("populate", False)

try:
# Drop and recreate the database if dangerouslyforce is true
if dangerouslyforce:
print("Dropping and recreating the database...")
drop_all_tables()

# Generate and apply migrations dynamically
print("Applying migrations dynamically...")
synchronize()

# Elasticsearch Index Management
manage_elasticsearch_indices(dangerouslyforce)

# Populate Sample Data
if populate:
print("Populating the database with sample data...")
populate_sample_data()
print("Sample data population complete.")

# Step 4: Sync organizations in ES

sync_es_organizations()

call_command("syncdb", dangerouslyforce=dangerouslyforce, populate=populate)
return {
"statusCode": 200,
"body": "Database synchronization completed successfully.",
Expand Down
Loading