merge aigpt
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
"""Initialize database with master data"""
|
||||
import asyncio
|
||||
from sqlalchemy import text, select, func
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.db.base import engine, Base, async_session
|
||||
from app.db.models import CardMaster
|
||||
@ -35,10 +36,14 @@ async def init_db():
|
||||
print("Inserting master data...")
|
||||
async with async_session() as session:
|
||||
# Check if master data already exists
|
||||
existing = await session.execute(
|
||||
"SELECT COUNT(*) FROM card_master"
|
||||
)
|
||||
count = existing.scalar()
|
||||
try:
|
||||
result = await session.execute(
|
||||
select(func.count()).select_from(CardMaster)
|
||||
)
|
||||
count = result.scalar()
|
||||
except Exception:
|
||||
# Table might not exist yet
|
||||
count = 0
|
||||
|
||||
if count == 0:
|
||||
# Insert card master data
|
||||
|
Reference in New Issue
Block a user