1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Интеграция базы данных Postgresql

This commit is contained in:
MoonTestUse1
2024-12-28 07:06:33 +06:00
parent c5e079ca3a
commit 6909494575
4 changed files with 44 additions and 15 deletions

8
.gitignore vendored
View File

@@ -3,10 +3,10 @@ node_modules
__pycache__ __pycache__
*.pyc *.pyc
# Environment # # Environment
.env # .env
.env.local # .env.local
.env.*.local # .env.*.local
# Build # Build
dist dist

View File

@@ -1,20 +1,24 @@
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
import os
SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db" DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://support_user:support_password@localhost:5432/support_db")
engine = create_engine( engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} DATABASE_URL,
pool_size=5,
max_overflow=10,
pool_timeout=30,
pool_recycle=1800
) )
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base() Base = declarative_base()
def get_db(): def get_db():
db = SessionLocal() db = SessionLocal()
try: try:
yield db yield db
finally: finally:
db.close() db.close()

View File

@@ -8,4 +8,6 @@ python-jose[cryptography]==3.3.0
passlib[bcrypt]>=1.7.4 passlib[bcrypt]>=1.7.4
bcrypt>=4.0.1 bcrypt>=4.0.1
aiogram>=3.4.1 aiogram>=3.4.1
python-dotenv==1.0.1 python-dotenv==1.0.1
psycopg2-binary==2.9.9
alembic==1.13.1

View File

@@ -1,6 +1,25 @@
version: '3.8' version: '3.8'
services: services:
postgres:
image: postgres:15-alpine
container_name: support-postgres
environment:
POSTGRES_DB: support_db
POSTGRES_USER: support_user
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- app-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U support_user -d support_db"]
interval: 10s
timeout: 5s
retries: 5
frontend: frontend:
build: build:
context: . context: .
@@ -17,15 +36,19 @@ services:
dockerfile: docker/backend/Dockerfile dockerfile: docker/backend/Dockerfile
container_name: support-backend container_name: support-backend
environment: environment:
- TELEGRAM_BOT_TOKEN=7677506032:AAHEqNUr1lIUfNVbLwaWIaPeKKShsCyz3eo - DATABASE_URL=postgresql://support_user:${POSTGRES_PASSWORD}@postgres:5432/support_db
- TELEGRAM_CHAT_ID=-1002037023574 - TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
- TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}
ports: ports:
- "8000:8000" - "8000:8000"
volumes: volumes:
- ./backend:/app - ./backend:/app
- ./sql_app.db:/app/sql_app.db:rw - ./logs:/app/logs:rw
networks: networks:
- app-network - app-network
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped restart: unless-stopped
nginx: nginx:
@@ -36,7 +59,7 @@ services:
restart: unless-stopped restart: unless-stopped
ports: ports:
- "80:80" - "80:80"
- "443:443" # Добавляем порт для HTTPS - "443:443"
volumes: volumes:
- frontend_build:/usr/share/nginx/html - frontend_build:/usr/share/nginx/html
- ./docker/nginx/conf.d:/etc/nginx/conf.d - ./docker/nginx/conf.d:/etc/nginx/conf.d
@@ -47,7 +70,6 @@ services:
depends_on: depends_on:
- frontend - frontend
- backend - backend
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot: certbot:
image: certbot/certbot image: certbot/certbot
@@ -62,4 +84,5 @@ networks:
driver: bridge driver: bridge
volumes: volumes:
postgres_data:
frontend_build: frontend_build: