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_DB: didier_pytest
POSTGRES_USER: pytest POSTGRES_USER: pytest
POSTGRES_PASSWORD: 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: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Python - name: Setup Python

View File

@ -6,16 +6,16 @@ from sqlalchemy.orm import sessionmaker
import settings import settings
encoded_password = quote_plus(settings.DB_PASSWORD) encoded_password = quote_plus(settings.POSTGRES_PASS)
engine = create_async_engine( engine = create_async_engine(
URL.create( URL.create(
drivername="postgresql+asyncpg", drivername="postgresql+asyncpg",
username=settings.DB_USERNAME, username=settings.POSTGRES_USER,
password=encoded_password, password=encoded_password,
host=settings.DB_HOST, host=settings.POSTGRES_HOST,
port=settings.DB_PORT, port=settings.POSTGRES_PORT,
database=settings.DB_NAME, database=settings.POSTGRES_DB,
), ),
pool_pre_ping=True, pool_pre_ping=True,
future=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' version: '3.9'
services: services:
db: postgres:
image: postgres:14 image: postgres:14
container_name: didier container_name: didier
restart: always restart: always
environment: environment:
- POSTGRES_DB=${DB_NAME:-didier_dev} - POSTGRES_DB=${POSTGRES_DB:-didier_dev}
- POSTGRES_USER=${DB_USERNAME:-postgres} - POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${DB_PASSWORD:-postgres} - POSTGRES_PASSWORD=${POSTGRES_PASS:-postgres}
ports: ports:
- "${DB_PORT:-5432}:${DB_PORT:-5432}" - "${POSTGRES_PORT:-5432}:${POSTGRES_PORT:-5432}"
volumes: volumes:
- db:/var/lib/postgresql/data - postgres:/var/lib/postgresql/data
db-pytest: mongo:
image: postgres:14 image: mongo:5.0
container_name: didier-pytest
restart: always restart: always
environment: environment:
- POSTGRES_DB=didier_pytest - MONGO_INITDB_ROOT_USERNAME=${MONGO_USER:-root}
- POSTGRES_USER=pytest - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASS:-root}
- POSTGRES_PASSWORD=pytest - MONGO_INITDB_DATABASE=${MONGO_DB:-didier_dev}
ports: ports:
- "5433:5432" - "${MONGO_PORT:-27017}:${MONGO_PORT:-27017}"
volumes: volumes:
db: - mongo:/data/db
volumes:
postgres:
mongo:

View File

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

View File

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