ifixkart-admin/Backend/migrate_wallet_db.py
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- Backend: FastAPI app with all models, services, schemas, routes
- Admin Panel: Next.js dashboard with all modules
  (CRM, POS, repairs, warranties, billing, notifications, etc.)
- Ecommerce: storefront (submodule) + product catalog
- AI Agents: .agents/ skill library for Antigravity IDE
- Docs: architecture, billing, notification gateway markdown
- Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
2026-10-13 12:59:47 +05:30

88 lines
3.4 KiB
Python

import ulid
from sqlalchemy import select
import app.models.db_base
from app.core.database.db_session import engine_commerce, SessionLocal, Base
from app.models.WalletModel import CustomerWallet, WalletTransaction
from app.models.SettingModel import Setting
def run_migration():
print("Creating wallet tables in Commerce DB...")
Base.metadata.create_all(bind=engine_commerce, tables=[CustomerWallet.__table__, WalletTransaction.__table__])
print("Wallet tables created/verified.")
print("Seeding/Verifying credit settings...")
db = SessionLocal()
try:
credit_settings = [
{
"setting_key": "credits_enabled",
"setting_value": {"value": True},
"description": "Master switch to enable/disable store credit rewards",
"is_public": True,
},
{
"setting_key": "credits_sales_percentage",
"setting_value": {"value": 5.0},
"description": "Store credit percentage earned on e-commerce sales orders",
"is_public": True,
},
{
"setting_key": "credits_sales_return_window_days",
"setting_value": {"value": 7},
"description": "Return window period in days before sales credit matures",
"is_public": True,
},
{
"setting_key": "credits_service_percentage",
"setting_value": {"value": 5.0},
"description": "Store credit percentage earned on completed repair service jobs",
"is_public": True,
},
{
"setting_key": "credits_service_claim_window_days",
"setting_value": {"value": 3},
"description": "Return/dispute window period in days before service credit matures",
"is_public": True,
},
{
"setting_key": "credits_minimum_order_value",
"setting_value": {"value": 0.0},
"description": "Minimum order/invoice amount required to earn credit",
"is_public": True,
},
{
"setting_key": "credits_expiry_days",
"setting_value": {"value": 365},
"description": "Days before matured credits expire (0 for no expiration)",
"is_public": True,
},
]
for s in credit_settings:
existing = db.execute(
select(Setting).where(Setting.setting_key == s["setting_key"])
).scalar_one_or_none()
if not existing:
db.add(Setting(
setting_id=str(ulid.ULID()),
setting_key=s["setting_key"],
group="credits",
type="json",
setting_value=s["setting_value"],
description=s["description"],
is_public=s["is_public"],
))
print(f" + Added Setting: {s['setting_key']}")
else:
print(f" = Setting exists: {s['setting_key']}")
db.commit()
print("Credit settings successfully synchronized.")
except Exception as e:
db.rollback()
print(f"Error during credit settings synchronization: {e}")
raise
finally:
db.close()
if __name__ == "__main__":
run_migration()