mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Интеграция базы данных Postgresql
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -3,10 +3,10 @@ node_modules
|
||||
__pycache__
|
||||
*.pyc
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
# # Environment
|
||||
# .env
|
||||
# .env.local
|
||||
# .env.*.local
|
||||
|
||||
# Build
|
||||
dist
|
||||
|
@@ -1,20 +1,24 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
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(
|
||||
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)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
db.close()
|
@@ -8,4 +8,6 @@ python-jose[cryptography]==3.3.0
|
||||
passlib[bcrypt]>=1.7.4
|
||||
bcrypt>=4.0.1
|
||||
aiogram>=3.4.1
|
||||
python-dotenv==1.0.1
|
||||
python-dotenv==1.0.1
|
||||
psycopg2-binary==2.9.9
|
||||
alembic==1.13.1
|
@@ -1,6 +1,25 @@
|
||||
version: '3.8'
|
||||
|
||||
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:
|
||||
build:
|
||||
context: .
|
||||
@@ -17,15 +36,19 @@ services:
|
||||
dockerfile: docker/backend/Dockerfile
|
||||
container_name: support-backend
|
||||
environment:
|
||||
- TELEGRAM_BOT_TOKEN=7677506032:AAHEqNUr1lIUfNVbLwaWIaPeKKShsCyz3eo
|
||||
- TELEGRAM_CHAT_ID=-1002037023574
|
||||
- DATABASE_URL=postgresql://support_user:${POSTGRES_PASSWORD}@postgres:5432/support_db
|
||||
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
|
||||
- TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./backend:/app
|
||||
- ./sql_app.db:/app/sql_app.db:rw
|
||||
- ./logs:/app/logs:rw
|
||||
networks:
|
||||
- app-network
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
@@ -36,7 +59,7 @@ services:
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443" # Добавляем порт для HTTPS
|
||||
- "443:443"
|
||||
volumes:
|
||||
- frontend_build:/usr/share/nginx/html
|
||||
- ./docker/nginx/conf.d:/etc/nginx/conf.d
|
||||
@@ -47,7 +70,6 @@ services:
|
||||
depends_on:
|
||||
- frontend
|
||||
- backend
|
||||
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
|
||||
|
||||
certbot:
|
||||
image: certbot/certbot
|
||||
@@ -62,4 +84,5 @@ networks:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
frontend_build:
|
Reference in New Issue
Block a user