From e8add494a8153df5a0de400e91a37514b4bc2445 Mon Sep 17 00:00:00 2001 From: DJensen94 <79864006+DJensen94@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:27:05 -0700 Subject: [PATCH] Add new app and models Add new app and models --- .../xfd_api/management/commands/syncmdl.py | 0 .../src/xfd_django/xfd_django/db_routers.py | 32 +++++++++++++++++++ backend/src/xfd_django/xfd_django/settings.py | 10 ++++++ .../src/xfd_django/xfd_mini_dl/__init__.py | 0 backend/src/xfd_django/xfd_mini_dl/admin.py | 3 ++ backend/src/xfd_django/xfd_mini_dl/apps.py | 6 ++++ .../xfd_mini_dl/migrations/__init__.py | 0 backend/src/xfd_django/xfd_mini_dl/models.py | 3 ++ backend/src/xfd_django/xfd_mini_dl/tests.py | 3 ++ backend/src/xfd_django/xfd_mini_dl/views.py | 3 ++ 10 files changed, 60 insertions(+) create mode 100644 backend/src/xfd_django/xfd_api/management/commands/syncmdl.py create mode 100644 backend/src/xfd_django/xfd_django/db_routers.py create mode 100644 backend/src/xfd_django/xfd_mini_dl/__init__.py create mode 100644 backend/src/xfd_django/xfd_mini_dl/admin.py create mode 100644 backend/src/xfd_django/xfd_mini_dl/apps.py create mode 100644 backend/src/xfd_django/xfd_mini_dl/migrations/__init__.py create mode 100644 backend/src/xfd_django/xfd_mini_dl/models.py create mode 100644 backend/src/xfd_django/xfd_mini_dl/tests.py create mode 100644 backend/src/xfd_django/xfd_mini_dl/views.py diff --git a/backend/src/xfd_django/xfd_api/management/commands/syncmdl.py b/backend/src/xfd_django/xfd_api/management/commands/syncmdl.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/src/xfd_django/xfd_django/db_routers.py b/backend/src/xfd_django/xfd_django/db_routers.py new file mode 100644 index 00000000..e0a9bc66 --- /dev/null +++ b/backend/src/xfd_django/xfd_django/db_routers.py @@ -0,0 +1,32 @@ +class MyAppRouter: + def db_for_read(self, model, **hints): + # Specify the app you want to route to the mini_data_lake database + if model._meta.app_label == 'dmz_mini_dl': + return 'mini_data_lake' + return 'default' # All other models go to the default database + + def db_for_write(self, model, **hints): + if model._meta.app_label == 'dmz_mini_dl': + return 'mini_data_lake' + return 'default' # All other models go to the default database + + def allow_relation(self, obj1, obj2, **hints): + # Check the app labels of both objects + app_label1 = obj1._meta.app_label + app_label2 = obj2._meta.app_label + + # If both objects are from the specific app, allow the relation + if app_label1 == 'dmz_mini_dl' and app_label2 == 'dmz_mini_dl': + return True + + # If only one of them is from the specific app, disallow the relation + if app_label1 == 'dmz_mini_dl' or app_label2 == 'dmz_mini_dl': + return False + + # Allow relations between all other models + return True + + def allow_migrate(self, db, app_label, model_name=None, **hints): + if app_label == 'dmz_mini_dl': + return db == 'mini_data_lake' # Migrate the specific app to the mini_data_lake database + return db == 'default' # All other apps migrate to the default database \ No newline at end of file diff --git a/backend/src/xfd_django/xfd_django/settings.py b/backend/src/xfd_django/xfd_django/settings.py index 9d2bd670..5f36ffad 100644 --- a/backend/src/xfd_django/xfd_django/settings.py +++ b/backend/src/xfd_django/xfd_django/settings.py @@ -89,9 +89,19 @@ "TEST": { "NAME": "crossfeed_test", # Name of the test database }, + }, + "mini_data_lake": { + 'ENGINE': "django.db.backends.postgresql_psycopg2", # Replace with your database engine + 'NAME': os.getenv("mdl_database"), + 'USER': os.getenv('mdl_user'), + 'PASSWORD': os.getenv('mdl_password'), + 'HOST': os.getenv('mdl_host'), + 'PORT': os.getenv('mdl_port'), } } +DATABASE_ROUTERS = ['xfd_django.db_routers.MyAppRouter'] + # ElastiCache AWS ELASTICACHE_ENDPOINT = os.getenv("ELASTICACHE_ENDPOINT") diff --git a/backend/src/xfd_django/xfd_mini_dl/__init__.py b/backend/src/xfd_django/xfd_mini_dl/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/src/xfd_django/xfd_mini_dl/admin.py b/backend/src/xfd_django/xfd_mini_dl/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/backend/src/xfd_django/xfd_mini_dl/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/src/xfd_django/xfd_mini_dl/apps.py b/backend/src/xfd_django/xfd_mini_dl/apps.py new file mode 100644 index 00000000..26052fb6 --- /dev/null +++ b/backend/src/xfd_django/xfd_mini_dl/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class XfdMiniDlConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'xfd_mini_dl' diff --git a/backend/src/xfd_django/xfd_mini_dl/migrations/__init__.py b/backend/src/xfd_django/xfd_mini_dl/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/src/xfd_django/xfd_mini_dl/models.py b/backend/src/xfd_django/xfd_mini_dl/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/backend/src/xfd_django/xfd_mini_dl/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/backend/src/xfd_django/xfd_mini_dl/tests.py b/backend/src/xfd_django/xfd_mini_dl/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/backend/src/xfd_django/xfd_mini_dl/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/src/xfd_django/xfd_mini_dl/views.py b/backend/src/xfd_django/xfd_mini_dl/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/backend/src/xfd_django/xfd_mini_dl/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.