init
This commit is contained in:
30
new-planet-backend/app/db/base.py
Normal file
30
new-planet-backend/app/db/base.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import Column, DateTime, func
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class BaseModel(Base):
|
||||
"""Базовая модель с общими полями"""
|
||||
__abstract__ = True
|
||||
|
||||
id = Column(
|
||||
UUID(as_uuid=False),
|
||||
primary_key=True,
|
||||
default=lambda: str(uuid.uuid4()),
|
||||
nullable=False
|
||||
)
|
||||
created_at = Column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
nullable=False
|
||||
)
|
||||
updated_at = Column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
onupdate=func.now(),
|
||||
nullable=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user