Mark-Lasfar
commited on
Commit
·
c8ee503
1
Parent(s):
ef26438
Fix ChunkedIteratorResult in SQLAlchemyUserDatabase and toggleBtn null error
Browse files- api/database.py +4 -3
- init_db.py +6 -2
api/database.py
CHANGED
|
@@ -8,6 +8,7 @@ from typing import AsyncGenerator
|
|
| 8 |
from fastapi import Depends
|
| 9 |
from datetime import datetime
|
| 10 |
import logging
|
|
|
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
|
@@ -16,15 +17,15 @@ SQLALCHEMY_DATABASE_URL = os.getenv("SQLALCHEMY_DATABASE_URL", "sqlite+aiosqlite
|
|
| 16 |
if not SQLALCHEMY_DATABASE_URL:
|
| 17 |
raise ValueError("SQLALCHEMY_DATABASE_URL is not set in environment variables.")
|
| 18 |
|
| 19 |
-
# إنشاء محرك async
|
| 20 |
-
async_engine = create_async_engine(SQLALCHEMY_DATABASE_URL, echo=True)
|
| 21 |
|
| 22 |
# إعداد جلسة async
|
| 23 |
AsyncSessionLocal = async_sessionmaker(
|
| 24 |
async_engine, expire_on_commit=False, class_=AsyncSession
|
| 25 |
)
|
| 26 |
|
| 27 |
-
#
|
| 28 |
Base = declarative_base()
|
| 29 |
|
| 30 |
class OAuthAccount(Base):
|
|
|
|
| 8 |
from fastapi import Depends
|
| 9 |
from datetime import datetime
|
| 10 |
import logging
|
| 11 |
+
import aiosqlite # تأكد من استيراد aiosqlite صراحةً
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
|
|
|
| 17 |
if not SQLALCHEMY_DATABASE_URL:
|
| 18 |
raise ValueError("SQLALCHEMY_DATABASE_URL is not set in environment variables.")
|
| 19 |
|
| 20 |
+
# إنشاء محرك async مع aiosqlite
|
| 21 |
+
async_engine = create_async_engine(SQLALCHEMY_DATABASE_URL, echo=True, connect_args={"check_same_thread": False})
|
| 22 |
|
| 23 |
# إعداد جلسة async
|
| 24 |
AsyncSessionLocal = async_sessionmaker(
|
| 25 |
async_engine, expire_on_commit=False, class_=AsyncSession
|
| 26 |
)
|
| 27 |
|
| 28 |
+
# باقي الكود زي ما هو...
|
| 29 |
Base = declarative_base()
|
| 30 |
|
| 31 |
class OAuthAccount(Base):
|
init_db.py
CHANGED
|
@@ -52,7 +52,7 @@ async def init_db():
|
|
| 52 |
if not test_user:
|
| 53 |
test_user = User(
|
| 54 |
email="[email protected]",
|
| 55 |
-
hashed_password=pwd_context.hash("testpassword123"),
|
| 56 |
is_active=True,
|
| 57 |
display_name="Test User"
|
| 58 |
)
|
|
@@ -83,4 +83,8 @@ async def init_db():
|
|
| 83 |
logger.info("Database initialization completed.")
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
if not test_user:
|
| 53 |
test_user = User(
|
| 54 |
email="[email protected]",
|
| 55 |
+
hashed_password=pwd_context.hash("testpassword123"),
|
| 56 |
is_active=True,
|
| 57 |
display_name="Test User"
|
| 58 |
)
|
|
|
|
| 83 |
logger.info("Database initialization completed.")
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
+
try:
|
| 87 |
+
asyncio.run(init_db())
|
| 88 |
+
except Exception as e:
|
| 89 |
+
logger.error(f"Failed to initialize database: {e}")
|
| 90 |
+
raise
|