From 86713fc75ff7e4e0bd51e875e9a0984cf651c33e Mon Sep 17 00:00:00 2001 From: Danamir Date: Mon, 10 Nov 2025 08:11:46 +0300 Subject: [PATCH] uncommited changes --- backend/create_new_db.py | 5 ++ backend/database.py | 15 +++++ backend/main.py | 37 +++++++++++ backend/migrate_data.py | 69 +++++++++++++++++++ backend/models.py | 82 +++++++++++++++++++++++ backend/requirements.txt | Bin 0 -> 592 bytes backend/routers/auditories.py | 18 +++++ backend/routers/components.py | 18 +++++ backend/routers/equipment_types.py | 17 +++++ backend/routers/oboruds.py | 24 +++++++ backend/routers/rashodniki.py | 17 +++++ backend/routers/zametki.py | 17 +++++ backend/schemas.py | 102 +++++++++++++++++++++++++++++ models.py | 90 ++++++++++++++++++------- requirements.txt | Bin 478 -> 0 bytes 15 files changed, 488 insertions(+), 23 deletions(-) create mode 100644 backend/create_new_db.py create mode 100644 backend/database.py create mode 100644 backend/main.py create mode 100644 backend/migrate_data.py create mode 100644 backend/models.py create mode 100644 backend/requirements.txt create mode 100644 backend/routers/auditories.py create mode 100644 backend/routers/components.py create mode 100644 backend/routers/equipment_types.py create mode 100644 backend/routers/oboruds.py create mode 100644 backend/routers/rashodniki.py create mode 100644 backend/routers/zametki.py create mode 100644 backend/schemas.py delete mode 100644 requirements.txt diff --git a/backend/create_new_db.py b/backend/create_new_db.py new file mode 100644 index 0000000..dece05e --- /dev/null +++ b/backend/create_new_db.py @@ -0,0 +1,5 @@ +from backend.models import Base +from backend.database import engine + +Base.metadata.drop_all(bind=engine) # Опционально, если вдруг есть +Base.metadata.create_all(bind=engine) \ No newline at end of file diff --git a/backend/database.py b/backend/database.py new file mode 100644 index 0000000..14d745a --- /dev/null +++ b/backend/database.py @@ -0,0 +1,15 @@ +# backend/database.py +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker, scoped_session + +SQLALCHEMY_DATABASE_URL = "sqlite:///./app.db" # или PostgreSQL URL + +engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}) +SessionLocal = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) + +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() diff --git a/backend/main.py b/backend/main.py new file mode 100644 index 0000000..a1e2ac4 --- /dev/null +++ b/backend/main.py @@ -0,0 +1,37 @@ +# backend/main.py +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +from backend.routers.equipment_types import equipment_types +from backend.routers.auditories import auditories +from backend.routers.oboruds import oboruds +from backend.routers.components import components +from backend.routers.rashodniki import consumables +from backend.routers.zametki import zametki + + + + +app = FastAPI() + +# Для фронтенда Vue.js +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # заменить на ['http://localhost:5173'] для безопасности + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +@app.get("/ping") +def ping(): + return {"message": "pong"} + + +# Подключение роутов +app.include_router(equipment_types) +app.include_router(auditories) +app.include_router(oboruds) +app.include_router(components) +app.include_router(consumables) +app.include_router(zametki) \ No newline at end of file diff --git a/backend/migrate_data.py b/backend/migrate_data.py new file mode 100644 index 0000000..c1c7689 --- /dev/null +++ b/backend/migrate_data.py @@ -0,0 +1,69 @@ +import sys +from sqlalchemy import create_engine, text +from sqlalchemy.orm import sessionmaker +from backend.database import SessionLocal as NewSession +from backend import models + +OLD_DB_URL = "sqlite:///./backend/old_app.db" +old_engine = create_engine(OLD_DB_URL, connect_args={"check_same_thread": False}) +OldSession = sessionmaker(bind=old_engine) +old_db = OldSession() + +new_db = NewSession() + +def log(msg: str): + print(f"[INFO] {msg}", file=sys.stderr) + +def migrate(): + log("Запуск переноса данных из old_app.db → app.db") + + # Тип оборудования по умолчанию + log("Добавление типа оборудования по умолчанию: 'Неизвестно'") + default_type = models.EquipmentType(name="Неизвестно") + new_db.add(default_type) + new_db.commit() + + # Перенос аудиторий + log("Перенос аудиторий...") + auditory_map = {} + aud_rows = old_db.execute(text("SELECT id, audnazvanie FROM auditory")).fetchall() + for aud in aud_rows: + new_aud = models.Auditory(audnazvanie=aud.audnazvanie) + new_db.add(new_aud) + new_db.flush() + auditory_map[aud.id] = new_aud.id + log(f" → перенесено: {len(aud_rows)}") + + # Перенос оборудования + log("Перенос оборудования...") + ob_rows = old_db.execute(text("SELECT * FROM oboruds")).fetchall() + for ob in ob_rows: + new_ob = models.Oboruds( + invNumber=ob.invNumber, + nazvanie=ob.nazvanie, + raspologenie=ob.raspologenie, + numberppasu=ob.numberppasu, + kolichestvo=ob.kolichestvo, + aud_id=auditory_map.get(ob.aud_id), + type_id=default_type.id + ) + new_db.add(new_ob) + log(f" → перенесено: {len(ob_rows)}") + + # Перенос заметок + log("Перенос заметок...") + z_rows = old_db.execute(text("SELECT * FROM zametki")).fetchall() + for z in z_rows: + new_z = models.Zametki( + txtzam=z.txtzam, + created_date=z.created_date, + rmdt=z.rmdt + ) + new_db.add(new_z) + log(f" → перенесено: {len(z_rows)}") + + new_db.commit() + log("✅ Перенос завершён успешно.") + +if __name__ == "__main__": + migrate() diff --git a/backend/models.py b/backend/models.py new file mode 100644 index 0000000..2a2d12b --- /dev/null +++ b/backend/models.py @@ -0,0 +1,82 @@ +# backend/models.py + +from sqlalchemy import Column, Integer, String, ForeignKey, DateTime +from sqlalchemy.orm import relationship, declarative_base +import datetime +from flask_sqlalchemy import SQLAlchemy + +Base = declarative_base() + +db = SQLAlchemy() + + + + + +class Auditory(Base): + __tablename__ = 'auditories' + + id = Column(Integer, primary_key=True) + audnazvanie = Column(String) + + oboruds = relationship("Oboruds", back_populates="auditory") + + +class EquipmentType(Base): + __tablename__ = 'equipment_types' + + id = Column(Integer, primary_key=True) + name = Column(String, unique=True, nullable=False) + + oboruds = relationship("Oboruds", back_populates="type") + + +class Oboruds(Base): + __tablename__ = 'oboruds' + + id = Column(Integer, primary_key=True) + invNumber = Column(Integer) + nazvanie = Column(String(500)) + raspologenie = Column(String(200)) + numberppasu = Column(String(100)) + kolichestvo = Column(Integer) + + aud_id = Column(Integer, ForeignKey("auditories.id")) + auditory = relationship("Auditory", back_populates="oboruds") + + type_id = Column(Integer, ForeignKey("equipment_types.id")) + type = relationship("EquipmentType", back_populates="oboruds") + + components = relationship("Component", back_populates="oborud") + consumables = relationship("Consumable", back_populates="oborud") + + +class Component(Base): + __tablename__ = 'components' + + id = Column(Integer, primary_key=True) + name = Column(String, nullable=False) + description = Column(String) + + oborud_id = Column(Integer, ForeignKey("oboruds.id")) + oborud = relationship("Oboruds", back_populates="components") + + +class Consumable(Base): + __tablename__ = 'consumables' + + id = Column(Integer, primary_key=True) + name = Column(String, nullable=False) + description = Column(String) + + oborud_id = Column(Integer, ForeignKey("oboruds.id")) + oborud = relationship("Oboruds", back_populates="consumables") + + +class Zametki(Base): + __tablename__ = 'zametki' + + id = Column(Integer, primary_key=True) + txtzam = Column(String(10000)) + created_date = Column(DateTime, default=datetime.datetime.utcnow) + rmdt = Column(DateTime) diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..fc366fb7727d8cf12f762bc101143cfb0084b895 GIT binary patch literal 592 zcmZ9J%}xSA5QOV&;-hF7cLhCg@a~290E7$+Y=mLMh|!l5G^RcVRBGPApN=Y9_#GC|>cASRDRr8pvIFm~*v8GB_skYbW#hOKADCxN zJfLUYn`Z9Yftn@N|Cl8>o247kP3gmS6w&In!Rnq&Dc7|8n-+T23p04_&^XXRt!mqD zsh@T1DyK55U8ioPO&7_ie660ETW)7>OxN>io+JM+ta^=W&Jx`(u(s8hI=0t1b{kiI Tt)H_#$>+&0s*N7OU>VVja~=|wFf200tcgyqhGz;i%ic)Z%0^8D7P0a`g*wpwgWwWs8!%On=dqtIc&% eZoAj?F`oQu?jnr#e&!m#_j9Qv*YQ+Y=A}Lr)kZ)7