Merge pull request #6026 from FinnStutzenstein/variableMediafileTablename
Setting for the mediafile database tablename
This commit is contained in:
commit
19a9eedf17
@ -103,6 +103,12 @@ DATABASE_HOST=
|
|||||||
DATABASE_PASSWORD=
|
DATABASE_PASSWORD=
|
||||||
DATABASE_PORT=
|
DATABASE_PORT=
|
||||||
DATABASE_USER=
|
DATABASE_USER=
|
||||||
|
MEDIAFILE_DATABASE_NAME=
|
||||||
|
MEDIAFILE_DATABASE_USER=
|
||||||
|
MEDIAFILE_DATABASE_PASSWORD=
|
||||||
|
MEDIAFILE_DATABASE_HOST=
|
||||||
|
MEDIAFILE_DATABASE_PORT=
|
||||||
|
MEDIAFILE_DATABASE_TABLENAME=
|
||||||
EMAIL_HOST=
|
EMAIL_HOST=
|
||||||
EMAIL_HOST_PASSWORD=
|
EMAIL_HOST_PASSWORD=
|
||||||
EMAIL_HOST_USER=
|
EMAIL_HOST_USER=
|
||||||
|
@ -72,6 +72,12 @@ x-osserver-env: &default-osserver-env
|
|||||||
DATABASE_PASSWORD: "ifenvelse(`DATABASE_PASSWORD', openslides)"
|
DATABASE_PASSWORD: "ifenvelse(`DATABASE_PASSWORD', openslides)"
|
||||||
DATABASE_PORT: ifenvelse(`DATABASE_PORT', 5432)
|
DATABASE_PORT: ifenvelse(`DATABASE_PORT', 5432)
|
||||||
DATABASE_USER: "ifenvelse(`DATABASE_USER', openslides)"
|
DATABASE_USER: "ifenvelse(`DATABASE_USER', openslides)"
|
||||||
|
MEDIAFILE_DATABASE_NAME: "read_env(`MEDIAFILE_DATABASE_NAME')"
|
||||||
|
MEDIAFILE_DATABASE_USER: "read_env(`MEDIAFILE_DATABASE_USER')"
|
||||||
|
MEDIAFILE_DATABASE_PASSWORD: "read_env(`MEDIAFILE_DATABASE_PASSWORD')"
|
||||||
|
MEDIAFILE_DATABASE_HOST: "read_env(`MEDIAFILE_DATABASE_HOST')"
|
||||||
|
MEDIAFILE_DATABASE_PORT: "read_env(`MEDIAFILE_DATABASE_PORT')"
|
||||||
|
MEDIAFILE_DATABASE_TABLENAME: "read_env(`MEDIAFILE_DATABASE_TABLENAME')"
|
||||||
DEFAULT_FROM_EMAIL: "ifenvelse(`DEFAULT_FROM_EMAIL', noreply@example.com)"
|
DEFAULT_FROM_EMAIL: "ifenvelse(`DEFAULT_FROM_EMAIL', noreply@example.com)"
|
||||||
EMAIL_HOST: "ifenvelse(`EMAIL_HOST', postfix)"
|
EMAIL_HOST: "ifenvelse(`EMAIL_HOST', postfix)"
|
||||||
EMAIL_HOST_PASSWORD: "ifenvelse(`EMAIL_HOST_PASSWORD',)"
|
EMAIL_HOST_PASSWORD: "ifenvelse(`EMAIL_HOST_PASSWORD',)"
|
||||||
@ -248,6 +254,8 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
|
|||||||
- CACHE_SIZE=ifenvelse(`CACHE_SIZE', 10)
|
- CACHE_SIZE=ifenvelse(`CACHE_SIZE', 10)
|
||||||
- CACHE_DATA_MIN_SIZE_KB=ifenvelse(`CACHE_DATA_MIN_SIZE_KB', 0)
|
- CACHE_DATA_MIN_SIZE_KB=ifenvelse(`CACHE_DATA_MIN_SIZE_KB', 0)
|
||||||
- CACHE_DATA_MAX_SIZE_KB=ifenvelse(`CACHE_DATA_MAX_SIZE_KB', 10240)
|
- CACHE_DATA_MAX_SIZE_KB=ifenvelse(`CACHE_DATA_MAX_SIZE_KB', 10240)
|
||||||
|
- DATABASE_NAME=read_env(`MEDIAFILE_DATABASE_NAME')
|
||||||
|
- DATABASE_TABLE=read_env(`MEDIAFILE_DATABASE_TABLENAME')
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- back
|
- back
|
||||||
|
@ -71,6 +71,12 @@ x-osserver-env: &default-osserver-env
|
|||||||
DATABASE_PASSWORD: "ifenvelse(`DATABASE_PASSWORD', openslides)"
|
DATABASE_PASSWORD: "ifenvelse(`DATABASE_PASSWORD', openslides)"
|
||||||
DATABASE_PORT: ifenvelse(`DATABASE_PORT', 5432)
|
DATABASE_PORT: ifenvelse(`DATABASE_PORT', 5432)
|
||||||
DATABASE_USER: "ifenvelse(`DATABASE_USER', openslides)"
|
DATABASE_USER: "ifenvelse(`DATABASE_USER', openslides)"
|
||||||
|
MEDIAFILE_DATABASE_NAME: "read_env(`MEDIAFILE_DATABASE_NAME')"
|
||||||
|
MEDIAFILE_DATABASE_USER: "read_env(`MEDIAFILE_DATABASE_USER')"
|
||||||
|
MEDIAFILE_DATABASE_PASSWORD: "read_env(`MEDIAFILE_DATABASE_PASSWORD')"
|
||||||
|
MEDIAFILE_DATABASE_HOST: "read_env(`MEDIAFILE_DATABASE_HOST')"
|
||||||
|
MEDIAFILE_DATABASE_PORT: "read_env(`MEDIAFILE_DATABASE_PORT')"
|
||||||
|
MEDIAFILE_DATABASE_TABLENAME: "read_env(`MEDIAFILE_DATABASE_TABLENAME')"
|
||||||
DEFAULT_FROM_EMAIL: "ifenvelse(`DEFAULT_FROM_EMAIL', noreply@example.com)"
|
DEFAULT_FROM_EMAIL: "ifenvelse(`DEFAULT_FROM_EMAIL', noreply@example.com)"
|
||||||
EMAIL_HOST: "ifenvelse(`EMAIL_HOST', postfix)"
|
EMAIL_HOST: "ifenvelse(`EMAIL_HOST', postfix)"
|
||||||
EMAIL_HOST_PASSWORD: "ifenvelse(`EMAIL_HOST_PASSWORD',)"
|
EMAIL_HOST_PASSWORD: "ifenvelse(`EMAIL_HOST_PASSWORD',)"
|
||||||
@ -271,6 +277,8 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
|
|||||||
- CACHE_SIZE=ifenvelse(`CACHE_SIZE', 10)
|
- CACHE_SIZE=ifenvelse(`CACHE_SIZE', 10)
|
||||||
- CACHE_DATA_MIN_SIZE_KB=ifenvelse(`CACHE_DATA_MIN_SIZE_KB', 0)
|
- CACHE_DATA_MIN_SIZE_KB=ifenvelse(`CACHE_DATA_MIN_SIZE_KB', 0)
|
||||||
- CACHE_DATA_MAX_SIZE_KB=ifenvelse(`CACHE_DATA_MAX_SIZE_KB', 10240)
|
- CACHE_DATA_MAX_SIZE_KB=ifenvelse(`CACHE_DATA_MAX_SIZE_KB', 10240)
|
||||||
|
- DATABASE_NAME=read_env(`MEDIAFILE_DATABASE_NAME')
|
||||||
|
- DATABASE_TABLE=read_env(`MEDIAFILE_DATABASE_TABLENAME')
|
||||||
deploy:
|
deploy:
|
||||||
replicas: ifenvelse(`MEDIA_SERVICE_REPLICAS', 2)
|
replicas: ifenvelse(`MEDIA_SERVICE_REPLICAS', 2)
|
||||||
restart_policy:
|
restart_policy:
|
||||||
|
@ -78,7 +78,7 @@ DATA_UPLOAD_MAX_MEMORY_SIZE = 104857600
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
"NAME": "openslides",
|
"NAME": get_env("DATABASE_NAME", "openslides"),
|
||||||
"USER": get_env("DATABASE_USER", "openslides"),
|
"USER": get_env("DATABASE_USER", "openslides"),
|
||||||
"PASSWORD": get_env("DATABASE_PASSWORD", "openslides"),
|
"PASSWORD": get_env("DATABASE_PASSWORD", "openslides"),
|
||||||
"HOST": get_env("DATABASE_HOST", "db"),
|
"HOST": get_env("DATABASE_HOST", "db"),
|
||||||
@ -88,13 +88,14 @@ DATABASES = {
|
|||||||
},
|
},
|
||||||
"mediafiles": {
|
"mediafiles": {
|
||||||
"ENGINE": "django.db.backends.postgresql",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
"NAME": "mediafiledata",
|
"NAME": get_env("MEDIAFILE_DATABASE_NAME", "mediafiledata"),
|
||||||
"USER": get_env("DATABASE_USER", "openslides"),
|
"USER": get_env("MEDIAFILE_DATABASE_USER", "openslides"),
|
||||||
"PASSWORD": get_env("DATABASE_PASSWORD", "openslides"),
|
"PASSWORD": get_env("MEDIAFILE_DATABASE_PASSWORD", "openslides"),
|
||||||
"HOST": get_env("DATABASE_HOST", "db"),
|
"HOST": get_env("MEDIAFILE_DATABASE_HOST", "db"),
|
||||||
"PORT": get_env("DATABASE_PORT", "5432"),
|
"PORT": get_env("MEDIAFILE_DATABASE_PORT", "5432"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
MEDIAFILE_DATABASE_TABLENAME = get_env("MEDIAFILE_DATABASE_TABLENAME", "mediafile_data")
|
||||||
|
|
||||||
# Redis
|
# Redis
|
||||||
REDIS_HOST = get_env("REDIS_HOST", "redis")
|
REDIS_HOST = get_env("REDIS_HOST", "redis")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from openslides.mediafiles.models import Mediafile
|
from openslides.mediafiles.models import Mediafile
|
||||||
@ -19,6 +20,10 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
path = cast(str, options.get("path"))
|
path = cast(str, options.get("path"))
|
||||||
|
|
||||||
|
mediafile_database_tablename = (
|
||||||
|
settings.MEDIAFILE_DATABASE_TABLENAME or "mediafile_data"
|
||||||
|
)
|
||||||
|
|
||||||
mediafile_count = 0
|
mediafile_count = 0
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
f.write("-- Generated file to import into the media service db\n")
|
f.write("-- Generated file to import into the media service db\n")
|
||||||
@ -27,7 +32,9 @@ class Command(BaseCommand):
|
|||||||
mediafile_count += 1
|
mediafile_count += 1
|
||||||
id = mediafile.id
|
id = mediafile.id
|
||||||
mimetype = mimetypes.guess_type(mediafile.mediafile.name)[0]
|
mimetype = mimetypes.guess_type(mediafile.mediafile.name)[0]
|
||||||
f.write("\nINSERT INTO mediafile_data (id, mimetype, data) VALUES ")
|
f.write(
|
||||||
|
f"\nINSERT INTO {mediafile_database_tablename} (id, mimetype, data) VALUES "
|
||||||
|
)
|
||||||
f.write(f"({id}, '{mimetype}', decode('")
|
f.write(f"({id}, '{mimetype}', decode('")
|
||||||
|
|
||||||
file_handle = open(mediafile.mediafile.path, "rb")
|
file_handle = open(mediafile.mediafile.path, "rb")
|
||||||
|
@ -28,7 +28,12 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
use_mediafile_database = "mediafiles" in connections
|
use_mediafile_database = "mediafiles" in connections
|
||||||
if use_mediafile_database:
|
if use_mediafile_database:
|
||||||
logger.info("Using a standalone mediafile database")
|
mediafile_database_tablename = (
|
||||||
|
settings.MEDIAFILE_DATABASE_TABLENAME or "mediafile_data"
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
f"Using a standalone mediafile database with the table '{mediafile_database_tablename}'"
|
||||||
|
)
|
||||||
|
|
||||||
max_upload_size = getattr(
|
max_upload_size = getattr(
|
||||||
settings, "MEDIAFILE_MAX_SIZE", 100 * 1024 * 1024
|
settings, "MEDIAFILE_MAX_SIZE", 100 * 1024 * 1024
|
||||||
@ -146,7 +151,7 @@ class MediafileViewSet(ModelViewSet):
|
|||||||
if use_mediafile_database:
|
if use_mediafile_database:
|
||||||
with connections["mediafiles"].cursor() as cursor:
|
with connections["mediafiles"].cursor() as cursor:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"INSERT INTO mediafile_data (id, data, mimetype) VALUES (%s, %s, %s)",
|
f"INSERT INTO {mediafile_database_tablename} (id, data, mimetype) VALUES (%s, %s, %s)",
|
||||||
[
|
[
|
||||||
db_mediafile.id,
|
db_mediafile.id,
|
||||||
mediafile.open().read(),
|
mediafile.open().read(),
|
||||||
@ -166,7 +171,7 @@ class MediafileViewSet(ModelViewSet):
|
|||||||
if use_mediafile_database:
|
if use_mediafile_database:
|
||||||
with connections["mediafiles"].cursor() as cursor:
|
with connections["mediafiles"].cursor() as cursor:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"DELETE FROM mediafile_data WHERE id IN %s",
|
f"DELETE FROM {mediafile_database_tablename} WHERE id IN %s",
|
||||||
[tuple(id for id in deleted_ids)],
|
[tuple(id for id in deleted_ids)],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user