Modify config files to support Mongo

pull/123/head
stijndcl 2022-07-25 19:07:57 +02:00
parent b54aed24e8
commit 665d677941
6 changed files with 83 additions and 34 deletions

View File

@ -38,6 +38,19 @@ jobs:
POSTGRES_DB: didier_pytest
POSTGRES_USER: pytest
POSTGRES_PASSWORD: pytest
mongo:
image: mongo:5.0
options: >-
--health-cmd mongo
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 27018:27017
env:
MONGO_DB: didier_pytest
MONGO_USER: pytest
MONGO_PASSWORD: pytest
steps:
- uses: actions/checkout@v3
- name: Setup Python

View File

@ -6,16 +6,16 @@ from sqlalchemy.orm import sessionmaker
import settings
encoded_password = quote_plus(settings.DB_PASSWORD)
encoded_password = quote_plus(settings.POSTGRES_PASS)
engine = create_async_engine(
URL.create(
drivername="postgresql+asyncpg",
username=settings.DB_USERNAME,
username=settings.POSTGRES_USER,
password=encoded_password,
host=settings.DB_HOST,
port=settings.DB_PORT,
database=settings.DB_NAME,
host=settings.POSTGRES_HOST,
port=settings.POSTGRES_PORT,
database=settings.POSTGRES_DB,
),
pool_pre_ping=True,
future=True,

View File

@ -0,0 +1,21 @@
version: '3.9'
services:
postgres-pytest:
image: postgres:14
container_name: didier-pytest
restart: always
environment:
- POSTGRES_DB=didier_pytest
- POSTGRES_USER=pytest
- POSTGRES_PASSWORD=pytest
ports:
- "5433:5432"
mongo-pytest:
image: mongo:5.0
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=pytest
- MONGO_INITDB_ROOT_PASSWORD=pytest
- MONGO_INITDB_DATABASE=didier_pytest
ports:
- "27018:27017"

View File

@ -1,26 +1,28 @@
version: '3.9'
services:
db:
postgres:
image: postgres:14
container_name: didier
restart: always
environment:
- POSTGRES_DB=${DB_NAME:-didier_dev}
- POSTGRES_USER=${DB_USERNAME:-postgres}
- POSTGRES_PASSWORD=${DB_PASSWORD:-postgres}
- POSTGRES_DB=${POSTGRES_DB:-didier_dev}
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASS:-postgres}
ports:
- "${DB_PORT:-5432}:${DB_PORT:-5432}"
- "${POSTGRES_PORT:-5432}:${POSTGRES_PORT:-5432}"
volumes:
- db:/var/lib/postgresql/data
db-pytest:
image: postgres:14
container_name: didier-pytest
- postgres:/var/lib/postgresql/data
mongo:
image: mongo:5.0
restart: always
environment:
- POSTGRES_DB=didier_pytest
- POSTGRES_USER=pytest
- POSTGRES_PASSWORD=pytest
- MONGO_INITDB_ROOT_USERNAME=${MONGO_USER:-root}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASS:-root}
- MONGO_INITDB_DATABASE=${MONGO_DB:-didier_dev}
ports:
- "5433:5432"
- "${MONGO_PORT:-27017}:${MONGO_PORT:-27017}"
volumes:
db:
- mongo:/data/db
volumes:
postgres:
mongo:

View File

@ -42,10 +42,15 @@ ignore_missing_imports = true
[tool.pytest.ini_options]
asyncio_mode = "auto"
env = [
"DB_NAME = didier_pytest",
"DB_USERNAME = pytest",
"DB_PASSWORD = pytest",
"DB_HOST = localhost",
"DB_PORT = 5433",
"MONGO_DB = didier_pytest",
"MONGO_USER = pytest",
"MONGO_PASS = pytest",
"MONGO_HOST = localhost",
"MONGO_PORT = 27018",
"POSTGRES_DB = didier_pytest",
"POSTGRES_USER = pytest",
"POSTGRES_PASS = pytest",
"POSTGRES_HOST = localhost",
"POSTGRES_PORT = 5433",
"DISCORD_TOKEN = token"
]

View File

@ -9,11 +9,11 @@ env.read_env()
__all__ = [
"SANDBOX",
"LOGFILE",
"DB_NAME",
"DB_USERNAME",
"DB_PASSWORD",
"DB_HOST",
"DB_PORT",
"POSTGRES_DB",
"POSTGRES_USER",
"POSTGRES_PASS",
"POSTGRES_HOST",
"POSTGRES_PORT",
"DISCORD_TOKEN",
"DISCORD_READY_MESSAGE",
"DISCORD_STATUS_MESSAGE",
@ -33,11 +33,19 @@ SEMESTER: int = env.int("SEMESTER", 2)
YEAR: int = env.int("YEAR", 3)
"""Database"""
DB_NAME: str = env.str("DB_NAME", "didier")
DB_USERNAME: str = env.str("DB_USERNAME", "postgres")
DB_PASSWORD: str = env.str("DB_PASSWORD", "")
DB_HOST: str = env.str("DB_HOST", "localhost")
DB_PORT: int = env.int("DB_PORT", "5432")
# MongoDB
MONGO_DB: str = env.str("MONGO_DB", "didier")
MONGO_USER: str = env.str("MONGO_USER", "root")
MONGO_PASS: str = env.str("MONGO_PASS", "root")
MONGO_HOST: str = env.str("MONGO_HOST", "localhost")
MONGO_PORT: int = env.int("MONGO_PORT", "27017")
# PostgreSQL
POSTGRES_DB: str = env.str("POSTGRES_DB", "didier")
POSTGRES_USER: str = env.str("POSTGRES_USER", "postgres")
POSTGRES_PASS: str = env.str("POSTGRES_PASS", "")
POSTGRES_HOST: str = env.str("POSTGRES_HOST", "localhost")
POSTGRES_PORT: int = env.int("POSTGRES_PORT", "5432")
"""Discord"""
DISCORD_TOKEN: str = env.str("DISCORD_TOKEN")