diff --git a/README.md b/README.md index ce385ad..7dca65f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming +python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -21,6 +22,7 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db +python django_code/manage.py migrate --database=streaming_redirect_db ``` ### Database debug @@ -33,6 +35,7 @@ create database job; create database telegram; create database podcast; create database streaming; +create database streaming_redirect; @@ -43,6 +46,7 @@ drop database job; drop database telegram; drop database podcast; drop database streaming; +drop database streaming_redirect; ``` diff --git a/django_code/apps/streaming/apps.py b/django_code/apps/streaming/apps.py index 85d22eb..7c1d9dd 100644 --- a/django_code/apps/streaming/apps.py +++ b/django_code/apps/streaming/apps.py @@ -4,3 +4,4 @@ from django.apps import AppConfig class StreamingConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'apps.streaming' + label = 'streaming' diff --git a/django_code/apps/streaming_redirect/__init__.py b/django_code/apps/streaming_redirect/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/streaming_redirect/admin.py b/django_code/apps/streaming_redirect/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/django_code/apps/streaming_redirect/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django_code/apps/streaming_redirect/apps.py b/django_code/apps/streaming_redirect/apps.py new file mode 100644 index 0000000..20490bf --- /dev/null +++ b/django_code/apps/streaming_redirect/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class StreamingRedirectConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'apps.streaming_redirect' + label = 'streaming_redirect' diff --git a/django_code/apps/streaming_redirect/migrations/0001_initial.py b/django_code/apps/streaming_redirect/migrations/0001_initial.py new file mode 100644 index 0000000..25a1a55 --- /dev/null +++ b/django_code/apps/streaming_redirect/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 4.2.30 on 2026-08-07 10:54 + +import apps.streaming_redirect.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='urlData', + fields=[ + ('name', models.CharField(help_text='Name of the show', max_length=1000, primary_key=True, serialize=False)), + ('url_example', models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000)), + ('prefix', models.CharField(blank=True, help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=', max_length=1000, null=True)), + ('infix', models.CharField(blank=True, help_text='&episode=', max_length=1000, null=True)), + ('suffix', models.CharField(blank=True, max_length=1000, null=True)), + ('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')), + ('alias', models.CharField(default=apps.streaming_redirect.models.urlData.sanitize, max_length=1000)), + ], + options={ + 'db_table': 'redirectUrl', + }, + ), + ] diff --git a/django_code/apps/streaming_redirect/migrations/__init__.py b/django_code/apps/streaming_redirect/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/streaming_redirect/models.py b/django_code/apps/streaming_redirect/models.py new file mode 100644 index 0000000..1737edc --- /dev/null +++ b/django_code/apps/streaming_redirect/models.py @@ -0,0 +1,19 @@ +from django.db import models + +# Create your models here. +class urlData(models.Model): + def sanitize(self): + print(self) + return 1 + + name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show") + url_example = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5") + prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True) + infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True) + suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True) + addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) + alias = models.CharField(max_length=1000, default=sanitize) + + + class Meta: + db_table = 'redirectUrl' \ No newline at end of file diff --git a/django_code/apps/streaming_redirect/tests.py b/django_code/apps/streaming_redirect/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/django_code/apps/streaming_redirect/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django_code/apps/streaming_redirect/views.py b/django_code/apps/streaming_redirect/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/django_code/apps/streaming_redirect/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/django_code/core/routers.py b/django_code/core/routers.py index cc62513..ea65120 100644 --- a/django_code/core/routers.py +++ b/django_code/core/routers.py @@ -30,6 +30,9 @@ class ProjectDatabaseRouter: if model._meta.app_label == 'streaming': return 'streaming_db' + if model._meta.app_label == 'streaming_redirect': + return 'streaming_redirect_db' + return 'default' def db_for_write(self, model, **hints): @@ -56,14 +59,17 @@ class ProjectDatabaseRouter: if model._meta.app_label == 'streaming': return 'streaming_db' + if model._meta.app_label == 'streaming_redirect': + return 'streaming_redirect_db' + return 'default' def allow_relation(self, obj1, obj2, **hints): """Allow relations if both models are in the same database.""" # Prevents accidental foreign key relationships across different physical DBs if ( - obj1._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming'] or - obj2._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming'] + obj1._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming', 'streaming_redirect'] or + obj2._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming', 'streaming_redirect'] ): return obj1._meta.app_label == obj2._meta.app_label return None @@ -92,8 +98,11 @@ class ProjectDatabaseRouter: if app_label == 'streaming': return db == 'streaming_db' + if app_label == 'streaming_redirect': + return db == 'streaming_redirect_db' + # Ensure default Django apps (auth, sessions, etc.) don't migrate into simpsons/cloudmanager - if db in ['cloudmanager_db', 'simpsons_db', 'redirect_db', 'job_db', 'telegram_db', 'podcast_db', 'streaming_db']: + if db in ['cloudmanager_db', 'simpsons_db', 'redirect_db', 'job_db', 'telegram_db', 'podcast_db', 'streaming_db', 'streaming_redirect_db']: return False return None diff --git a/django_code/core/settings.py b/django_code/core/settings.py index 7ff2b56..58fd02b 100644 --- a/django_code/core/settings.py +++ b/django_code/core/settings.py @@ -51,6 +51,7 @@ INSTALLED_APPS = [ 'apps.telegram_communication.apps.TelegramCommunicationConfig', 'apps.podcast_aggregator.apps.PodcastAggregatorConfig', 'apps.streaming.apps.StreamingConfig', + 'apps.streaming_redirect.apps.StreamingRedirectConfig', 'import_export', 'djangoql', ] @@ -163,6 +164,14 @@ DATABASES = { 'HOST': os.environ.get('DB_HOST'), 'PORT': os.environ.get('DB_PORT'), }, + 'streaming_redirect_db': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'streaming_redirect', + 'USER': os.environ.get('DB_USERNAME'), + 'PASSWORD': os.environ.get('DB_PASSWORD'), + 'HOST': os.environ.get('DB_HOST'), + 'PORT': os.environ.get('DB_PORT'), + }, } DATABASE_ROUTERS = ['core.routers.ProjectDatabaseRouter'] #DATABASE_ROUTERS = [] diff --git a/infra/production/entrypoint.sh b/infra/production/entrypoint.sh index f501c9e..dfa8492 100644 --- a/infra/production/entrypoint.sh +++ b/infra/production/entrypoint.sh @@ -8,6 +8,7 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming +python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -17,6 +18,7 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db +python django_code/manage.py migrate --database=streaming_redirect_db python django_code/manage.py runserver "0.0.0.0:8000" diff --git a/infra/testing/entrypoint.sh b/infra/testing/entrypoint.sh index 44f6586..0071164 100644 --- a/infra/testing/entrypoint.sh +++ b/infra/testing/entrypoint.sh @@ -15,6 +15,7 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming +python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -24,6 +25,7 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db +python django_code/manage.py migrate --database=streaming_redirect_db python django_code/manage.py runserver "0.0.0.0:8000"