From a1b966a22bb1563c732c1df3a8cfa51acd677262 Mon Sep 17 00:00:00 2001 From: Ivan Budakov Date: Mon, 19 Oct 2026 17:29:04 +0300 Subject: [PATCH] feat: initial Flask skeleton with PostgreSQL --- .gitignore | 3 +++ app/__init__.py | 0 app/config.py | 12 +++++++++++ app/db.py | 8 ++++++++ app/main.py | 18 +++++++++++++++++ app/models.py | 3 +++ app/templates/index.html | 43 ++++++++++++++++++++++++++++++++++++++++ requirements.txt | 16 +++++++++++++++ 8 files changed, 103 insertions(+) create mode 100644 .gitignore create mode 100644 app/__init__.py create mode 100644 app/config.py create mode 100644 app/db.py create mode 100644 app/main.py create mode 100644 app/models.py create mode 100644 app/templates/index.html create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0ee3b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv/ +__pycache__/ +*.pyc diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/config.py b/app/config.py new file mode 100644 index 0000000..145aae3 --- /dev/null +++ b/app/config.py @@ -0,0 +1,12 @@ +import os +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent.parent + +POSTGRES_USER = os.getenv("POSTGRES_USER", "morozovka") +POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD", "rf-slf-1945") +POSTGRES_DB = os.getenv("POSTGRES_DB", "morozovka_portal") +POSTGRES_HOST = os.getenv("POSTGRES_HOST", "127.0.0.1") +POSTGRES_PORT = os.getenv("POSTGRES_PORT", "5432") + +DATABASE_URL = f"postgresql+psycopg2://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}" diff --git a/app/db.py b/app/db.py new file mode 100644 index 0000000..7bc3553 --- /dev/null +++ b/app/db.py @@ -0,0 +1,8 @@ +from sqlmodel import SQLModel, create_engine +from .config import DATABASE_URL + +engine = create_engine(DATABASE_URL, echo=False) + +def init_db(): + """Создает все таблицы в БД.""" + SQLModel.metadata.create_all(engine) diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..c86ba8b --- /dev/null +++ b/app/main.py @@ -0,0 +1,18 @@ +from flask import Flask, render_template, jsonify +from .db import init_db + +app = Flask(__name__) + +# Инициализируем БД при старте (в будущем заменим на Alembic миграции) +with app.app_context(): + init_db() + +@app.route("/healthz") +def healthz(): + """Проверка жизнеспособности сервиса.""" + return jsonify({"status": "ok", "service": "morozovka-portal"}) + +@app.route("/") +def index(): + """Главная страница портала.""" + return render_template("index.html") diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..103f019 --- /dev/null +++ b/app/models.py @@ -0,0 +1,3 @@ +from sqlmodel import SQLModel + +# Здесь будут модели User, Project и т.д. diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..a401eaa --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,43 @@ + + + + + + Morozovka Portal + + + +

Morozovka Portal

+

Скелет системы успешно запущен! (Flask Edition)

+
Stage 1.2: OK
+ + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ebcf532 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +annotated-types==0.8.0 +blinker==1.9.0 +click==8.5.0 +Flask==3.1.3 +gunicorn==26.2.0 +itsdangerous==2.2.0 +Jinja2==3.1.6 +MarkupSafe==3.0.4 +psycopg2-binary==2.9.13 +pydantic==2.14.1 +pydantic_core==2.50.1 +SQLAlchemy==2.1.5 +sqlmodel==0.0.48 +typing-inspection==0.4.4 +typing_extensions==4.16.0 +Werkzeug==3.1.9