diff --git a/.gitignore b/.gitignore index 92b4428..dc0ab78 100644 --- a/.gitignore +++ b/.gitignore @@ -162,4 +162,5 @@ cython_debug/ .vscode configs/main.json +mongo_entrypoint/.env tests/node_modules/ diff --git a/configs/test.json b/configs/test.json index c3ed931..1eb437f 100644 --- a/configs/test.json +++ b/configs/test.json @@ -1,6 +1,6 @@ { "database": { - "connect_url": "mongodb://admin:admin@db_test", + "connect_url": "mongodb://test:test@db_test/ELANDB", "name": "ELANDB" }, "auth": { diff --git a/docker-compose.yml b/docker-compose.yml index a9b3dae..de32c3e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,12 @@ services: db: image: mongo - volumes: - - /var/lib/elan/mongodb_data:/data/db - environment: - - MONGO_INITDB_ROOT_USERNAME=admin - - MONGO_INITDB_ROOT_PASSWORD=admin ports: - "27017:27017" + env_file: "mongo_entrypoint/.env" + volumes: + - ./mongo_entrypoint:/docker-entrypoint-initdb.d + - /var/lib/elan/mongodb_data:/data/db api: build: context: ./ @@ -22,10 +21,12 @@ services: db_test: image: mongo environment: - - MONGO_INITDB_ROOT_USERNAME=admin - - MONGO_INITDB_ROOT_PASSWORD=admin + - MONGO_ELANDB_USERNAME=test + - MONGO_ELANDB_PASSWORD=test ports: - "42042:42042" + volumes: + - ./mongo_entrypoint:/docker-entrypoint-initdb.d api_test: build: context: ./ diff --git a/mongo_entrypoint/init.js b/mongo_entrypoint/init.js new file mode 100644 index 0000000..db57a95 --- /dev/null +++ b/mongo_entrypoint/init.js @@ -0,0 +1,6 @@ +db = db.getSiblingDB("ELANDB"); +db.createUser({ + user: process.env.MONGO_ELANDB_USERNAME, + pwd: process.env.MONGO_ELANDB_PASSWORD, + roles: [{ role: "readWrite", db: "ELANDB" }] +}); diff --git a/src/db/types/domain.py b/src/db/types/domain.py index 0b8f518..33a74a7 100644 --- a/src/db/types/domain.py +++ b/src/db/types/domain.py @@ -1,12 +1,12 @@ -from typing import Literal -from pydantic import Field - -from utils.schemas import BaseModel - - -TargetType = Literal["user", "group", "contest"] - -class Entity(BaseModel): - id: str = Field(alias='_id') - target_type: TargetType - target_id: int +from typing import Literal +from pydantic import Field + +from utils.schemas import BaseModel + + +TargetType = Literal["user", "group", "contest"] + +class Entity(BaseModel): + id: str = Field(alias='_id') + target_type: TargetType + target_id: int