修改model默认时间为服务器时间
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from datetime import datetime
|
||||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
||||||
from sqlalchemy.orm import DeclarativeBase
|
from sqlalchemy.orm import DeclarativeBase
|
||||||
from sqlalchemy import Column, String, Integer, DateTime, Text, JSON, Index, text
|
from sqlalchemy import Column, String, Integer, DateTime, Text, JSON, Index, text
|
||||||
@@ -22,7 +23,7 @@ class CallbackFailureLog(Base):
|
|||||||
request_url = Column(String(500), nullable=False, comment="请求URL")
|
request_url = Column(String(500), nullable=False, comment="请求URL")
|
||||||
request_headers = Column(JSON, nullable=False, comment="请求头")
|
request_headers = Column(JSON, nullable=False, comment="请求头")
|
||||||
request_body = Column(JSON, nullable=False, comment="请求体")
|
request_body = Column(JSON, nullable=False, comment="请求体")
|
||||||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
created_at = Column(DateTime, default=datetime.now(), comment="创建时间")
|
||||||
|
|
||||||
|
|
||||||
class CallbackFailureData(Base):
|
class CallbackFailureData(Base):
|
||||||
@@ -36,7 +37,7 @@ class CallbackFailureData(Base):
|
|||||||
status_description = Column(String(200), nullable=False, comment="状态描述")
|
status_description = Column(String(200), nullable=False, comment="状态描述")
|
||||||
raw_data = Column(Text, nullable=False, comment="原始回调数据JSON字符串")
|
raw_data = Column(Text, nullable=False, comment="原始回调数据JSON字符串")
|
||||||
calldate = Column(DateTime, nullable=True, comment="通话日期")
|
calldate = Column(DateTime, nullable=True, comment="通话日期")
|
||||||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
created_at = Column(DateTime, default=datetime.now(), comment="创建时间")
|
||||||
|
|
||||||
|
|
||||||
class ExternalApiLog(Base):
|
class ExternalApiLog(Base):
|
||||||
@@ -51,21 +52,15 @@ class ExternalApiLog(Base):
|
|||||||
response_headers = Column(JSON, nullable=False, comment="外部接口响应头")
|
response_headers = Column(JSON, nullable=False, comment="外部接口响应头")
|
||||||
response_body = Column(Text, nullable=False, comment="外部接口响应体")
|
response_body = Column(Text, nullable=False, comment="外部接口响应体")
|
||||||
retry_count = Column(Integer, default=0, comment="重试次数")
|
retry_count = Column(Integer, default=0, comment="重试次数")
|
||||||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
created_at = Column(DateTime, default=datetime.now(), comment="创建时间")
|
||||||
|
|
||||||
|
|
||||||
# 创建数据库引擎
|
# 创建数据库引擎
|
||||||
engine = create_async_engine(
|
engine = create_async_engine(settings.database_url, echo=settings.debug, future=True)
|
||||||
settings.database_url,
|
|
||||||
echo=settings.debug,
|
|
||||||
future=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# 创建会话工厂
|
# 创建会话工厂
|
||||||
AsyncSessionLocal = async_sessionmaker(
|
AsyncSessionLocal = async_sessionmaker(
|
||||||
engine,
|
engine, class_=AsyncSession, expire_on_commit=False
|
||||||
class_=AsyncSession,
|
|
||||||
expire_on_commit=False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -84,10 +79,14 @@ async def init_db():
|
|||||||
await conn.run_sync(Base.metadata.create_all)
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
|
|
||||||
# 检查并创建手机号索引
|
# 检查并创建手机号索引
|
||||||
await conn.execute(text("""
|
await conn.execute(
|
||||||
|
text(
|
||||||
|
"""
|
||||||
CREATE INDEX IF NOT EXISTS idx_phone_number
|
CREATE INDEX IF NOT EXISTS idx_phone_number
|
||||||
ON callback_failure_data (phone_number)
|
ON callback_failure_data (phone_number)
|
||||||
"""))
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
logger.info("✅ 数据库表结构初始化完成")
|
logger.info("✅ 数据库表结构初始化完成")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user