From 1f8746bd0387b51b9c3ad803c066f639015d7949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D0=BB=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D1=83?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BC?= Date: Thu, 19 Mar 2026 23:02:28 +0300 Subject: [PATCH] Fix MongoDB class map hierarchy for inherited Content property --- .../Persistence/Mongo/MongoDbMapConfigurator.cs | 5 ++--- docker/docker-compose.yml | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/backend/src/Modules/Chats/Infrastructure/Persistence/Mongo/MongoDbMapConfigurator.cs b/backend/src/Modules/Chats/Infrastructure/Persistence/Mongo/MongoDbMapConfigurator.cs index f63556b..205f73a 100644 --- a/backend/src/Modules/Chats/Infrastructure/Persistence/Mongo/MongoDbMapConfigurator.cs +++ b/backend/src/Modules/Chats/Infrastructure/Persistence/Mongo/MongoDbMapConfigurator.cs @@ -31,6 +31,7 @@ public static class MongoDbMapConfigurator cm.MapField("_deletedFor").SetElementName("DeletedFor"); cm.MapField("_readBy").SetElementName("ReadBy"); cm.MapField("_reactions").SetElementName("Reactions"); + cm.MapProperty(c => c.Content).SetSerializer(new EncryptedStringSerializer()); cm.MapProperty(c => c.Quote).SetSerializer(new EncryptedStringSerializer()); cm.SetIsRootClass(true); }); @@ -39,7 +40,6 @@ public static class MongoDbMapConfigurator { cm.AutoMap(); cm.SetDiscriminator("TextMessage"); - cm.MapProperty(c => c.Content).SetSerializer(new EncryptedStringSerializer()); }); BsonClassMap.RegisterClassMap(cm => @@ -47,14 +47,13 @@ public static class MongoDbMapConfigurator cm.AutoMap(); cm.MapField("_media").SetElementName("Media"); cm.SetDiscriminator("MediaMessage"); - cm.MapProperty(c => c.Caption).SetSerializer(new EncryptedStringSerializer()); + cm.UnmapProperty(c => c.Caption); // Avoid DB duplication, Content is already saved }); BsonClassMap.RegisterClassMap(cm => { cm.AutoMap(); cm.SetDiscriminator("StoryMessage"); - cm.MapProperty(c => c.Content).SetSerializer(new EncryptedStringSerializer()); cm.MapProperty(c => c.InternalStoryMediaUrl).SetSerializer(new EncryptedStringSerializer()); }); diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 9c0afa1..d64c4aa 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,7 +4,7 @@ services: container_name: knot-db restart: always env_file: - - .env + - ../.env volumes: - postgres_data:/var/lib/postgresql/data ports: @@ -17,7 +17,7 @@ services: container_name: knot-server restart: always env_file: - - .env + - ../.env depends_on: - db - minio @@ -30,7 +30,7 @@ services: container_name: knot-minio restart: always env_file: - - .env + - ../.env ports: - "9000:9000" - "9001:9001" @@ -55,7 +55,7 @@ services: ports: - "9090:80" env_file: - - .env + - ../.env depends_on: - server