._.
This commit is contained in:
parent
bbca53c89c
commit
609f4c694f
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.idea
|
||||
.idea/
|
||||
.idea/
|
||||
.env
|
||||
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
32
app/infrastructure/database/database.py
Normal file
32
app/infrastructure/database/database.py
Normal file
@ -0,0 +1,32 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, Session
|
||||
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = "postgresql+pg8000://user:password@localhost/dbname"
|
||||
|
||||
__factory = None
|
||||
|
||||
|
||||
def init_db():
|
||||
import app.infrastructure.database.models.accessories
|
||||
import app.infrastructure.database.models.deliveries
|
||||
import app.infrastructure.database.models.orders
|
||||
import app.infrastructure.database.models.roles
|
||||
import app.infrastructure.database.models.statuses
|
||||
import app.infrastructure.database.models.steps
|
||||
import app.infrastructure.database.models.storage_accessories
|
||||
import app.infrastructure.database.models.storages
|
||||
import app.infrastructure.database.models.users
|
||||
|
||||
global __factory
|
||||
|
||||
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||
__factory = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
|
||||
def connect() -> Session:
|
||||
global __factory
|
||||
return __factory()
|
||||
3
app/infrastructure/database/models/__init__.py
Normal file
3
app/infrastructure/database/models/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR, Float
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class Accessories(base):
|
||||
class Accessories(Base):
|
||||
__tablename__ = 'accessories'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, DateTime, ForeignKey
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class Delivery(base):
|
||||
class Delivery(Base):
|
||||
__tablename__ = 'deliveries'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, DateTime, ForeignKey
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class Order(base):
|
||||
class Order(Base):
|
||||
__tablename__ = 'orders'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class Role(base):
|
||||
class Role(Base):
|
||||
__tablename__ = 'roles'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class Status(base):
|
||||
class Status(Base):
|
||||
__tablename__ = 'statuses'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, DateTime, ForeignKey
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class Step(base):
|
||||
class Step(Base):
|
||||
__tablename__ = 'steps'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, DateTime, ForeignKey
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class StorageAccessories(base):
|
||||
class StorageAccessories(Base):
|
||||
__tablename__ = 'storage_accessories'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, DateTime, ForeignKey, VARCHAR, Float
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import Column, Integer, VARCHAR, Float
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
class Storage(base):
|
||||
class Storage(Base):
|
||||
__tablename__ = 'storages'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR, ForeignKey
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
base = declarative_base()
|
||||
from app.infrastructure.database.models import Base
|
||||
|
||||
|
||||
|
||||
class User(base):
|
||||
class User(Base):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
@ -19,4 +17,4 @@ class User(base):
|
||||
|
||||
role = relationship('Role', back_populates='users')
|
||||
|
||||
orders = relationship('Order', back_populates='user')
|
||||
orders = relationship('Order', back_populates='user')
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from app.infrastructure.fastapi import routes
|
||||
from app.infrastructure.database.database import init_db
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
init_db() # Инициализация базы данных
|
||||
|
||||
# app.include_router(routes.router)
|
||||
Loading…
x
Reference in New Issue
Block a user