From a4d214964ab46b77ae27c4e0718f46af779569bd Mon Sep 17 00:00:00 2001 From: OuYingJun1024 <1034284404@qq.com> Date: Wed, 27 May 2026 21:03:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20crud=20=E5=B9=B6=E5=85=A5=20reposit?= =?UTF-8?q?ories=20+=20alembic=20=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8E=BB=20hex=20=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 数据访问层统一: app/crud/{ad_reward,savings,signin,task,wallet}.py 移入 app/repositories/(与 user.py 同目录),删除 crud/;更新 10 处 import (api/v1/* + scripts/* + repositories 内部交叉引用 app.crud→app.repositories) - alembic/versions 9 个迁移文件去掉 hex 前缀,改成可读文件名(如 welfare_tables_coin_account_coin_txn.py);**仅重命名文件**,文件内 revision/down_revision 不动 → 迁移链与已迁移库的 alembic_version 不受影响 (alembic heads/history 验证链完好,单一 head c8d9e0f1a2b3) - 测试: 37 passed(1 个 coupon 代理失败为连不到 pricebot 上游的环境问题,与本次无关) Co-Authored-By: Claude Opus 4.7 --- .../{c8d9e0f1a2b3_ad_reward_record.py => ad_reward_record.py} | 0 ...f76f_cash_transaction_table.py => cash_transaction_table.py} | 0 .../{9c559acc164a_init_user_table.py => init_user_table.py} | 0 ...67c0e2ab_savings_record_table.py => savings_record_table.py} | 0 ...c2d3e4f5a6_savings_shop_dishes.py => savings_shop_dishes.py} | 0 ...d9e0f1b2_unique_wechat_openid.py => unique_wechat_openid.py} | 0 ...wechat_nickname_avatar.py => user_wechat_nickname_avatar.py} | 0 ...unt_coin_txn_.py => welfare_tables_coin_account_coin_txn.py} | 0 ...der_and_user_openid.py => withdraw_order_and_user_openid.py} | 0 app/api/v1/ad.py | 2 +- app/api/v1/savings.py | 2 +- app/api/v1/signin.py | 2 +- app/api/v1/tasks.py | 2 +- app/api/v1/wallet.py | 2 +- app/{crud => repositories}/ad_reward.py | 2 +- app/{crud => repositories}/savings.py | 0 app/{crud => repositories}/signin.py | 2 +- app/{crud => repositories}/task.py | 2 +- app/{crud => repositories}/wallet.py | 0 scripts/reconcile_withdraws.py | 2 +- scripts/sim_pangle_callback.py | 2 +- 21 files changed, 10 insertions(+), 10 deletions(-) rename alembic/versions/{c8d9e0f1a2b3_ad_reward_record.py => ad_reward_record.py} (100%) rename alembic/versions/{3d9cb19df76f_cash_transaction_table.py => cash_transaction_table.py} (100%) rename alembic/versions/{9c559acc164a_init_user_table.py => init_user_table.py} (100%) rename alembic/versions/{bf2a67c0e2ab_savings_record_table.py => savings_record_table.py} (100%) rename alembic/versions/{b1c2d3e4f5a6_savings_shop_dishes.py => savings_shop_dishes.py} (100%) rename alembic/versions/{a7c8d9e0f1b2_unique_wechat_openid.py => unique_wechat_openid.py} (100%) rename alembic/versions/{f5b2d3c4e6a7_user_wechat_nickname_avatar.py => user_wechat_nickname_avatar.py} (100%) rename alembic/versions/{357520ea3015_welfare_tables_coin_account_coin_txn_.py => welfare_tables_coin_account_coin_txn.py} (100%) rename alembic/versions/{e4a1c2b3d4f5_withdraw_order_and_user_openid.py => withdraw_order_and_user_openid.py} (100%) rename app/{crud => repositories}/ad_reward.py (98%) rename app/{crud => repositories}/savings.py (100%) rename app/{crud => repositories}/signin.py (98%) rename app/{crud => repositories}/task.py (97%) rename app/{crud => repositories}/wallet.py (100%) diff --git a/alembic/versions/c8d9e0f1a2b3_ad_reward_record.py b/alembic/versions/ad_reward_record.py similarity index 100% rename from alembic/versions/c8d9e0f1a2b3_ad_reward_record.py rename to alembic/versions/ad_reward_record.py diff --git a/alembic/versions/3d9cb19df76f_cash_transaction_table.py b/alembic/versions/cash_transaction_table.py similarity index 100% rename from alembic/versions/3d9cb19df76f_cash_transaction_table.py rename to alembic/versions/cash_transaction_table.py diff --git a/alembic/versions/9c559acc164a_init_user_table.py b/alembic/versions/init_user_table.py similarity index 100% rename from alembic/versions/9c559acc164a_init_user_table.py rename to alembic/versions/init_user_table.py diff --git a/alembic/versions/bf2a67c0e2ab_savings_record_table.py b/alembic/versions/savings_record_table.py similarity index 100% rename from alembic/versions/bf2a67c0e2ab_savings_record_table.py rename to alembic/versions/savings_record_table.py diff --git a/alembic/versions/b1c2d3e4f5a6_savings_shop_dishes.py b/alembic/versions/savings_shop_dishes.py similarity index 100% rename from alembic/versions/b1c2d3e4f5a6_savings_shop_dishes.py rename to alembic/versions/savings_shop_dishes.py diff --git a/alembic/versions/a7c8d9e0f1b2_unique_wechat_openid.py b/alembic/versions/unique_wechat_openid.py similarity index 100% rename from alembic/versions/a7c8d9e0f1b2_unique_wechat_openid.py rename to alembic/versions/unique_wechat_openid.py diff --git a/alembic/versions/f5b2d3c4e6a7_user_wechat_nickname_avatar.py b/alembic/versions/user_wechat_nickname_avatar.py similarity index 100% rename from alembic/versions/f5b2d3c4e6a7_user_wechat_nickname_avatar.py rename to alembic/versions/user_wechat_nickname_avatar.py diff --git a/alembic/versions/357520ea3015_welfare_tables_coin_account_coin_txn_.py b/alembic/versions/welfare_tables_coin_account_coin_txn.py similarity index 100% rename from alembic/versions/357520ea3015_welfare_tables_coin_account_coin_txn_.py rename to alembic/versions/welfare_tables_coin_account_coin_txn.py diff --git a/alembic/versions/e4a1c2b3d4f5_withdraw_order_and_user_openid.py b/alembic/versions/withdraw_order_and_user_openid.py similarity index 100% rename from alembic/versions/e4a1c2b3d4f5_withdraw_order_and_user_openid.py rename to alembic/versions/withdraw_order_and_user_openid.py diff --git a/app/api/v1/ad.py b/app/api/v1/ad.py index 45026a4..57fcd19 100644 --- a/app/api/v1/ad.py +++ b/app/api/v1/ad.py @@ -19,7 +19,7 @@ from app.core import rewards from app.core.config import settings from app.integrations import pangle from app.core.ratelimit import rate_limit -from app.crud import ad_reward as crud_ad +from app.repositories import ad_reward as crud_ad from app.schemas.ad import AdRewardStatusOut, PangleCallbackOut, TestGrantOut logger = logging.getLogger("shagua.ad") diff --git a/app/api/v1/savings.py b/app/api/v1/savings.py index c0db8f0..50e756d 100644 --- a/app/api/v1/savings.py +++ b/app/api/v1/savings.py @@ -12,7 +12,7 @@ import logging from fastapi import APIRouter, Query from app.api.deps import CurrentUser, DbSession -from app.crud import savings as crud_savings +from app.repositories import savings as crud_savings from app.schemas.welfare import ( SavingsBattleOut, SavingsRecordOut, diff --git a/app/api/v1/signin.py b/app/api/v1/signin.py index 1880d93..3bd440a 100644 --- a/app/api/v1/signin.py +++ b/app/api/v1/signin.py @@ -11,7 +11,7 @@ import logging from fastapi import APIRouter, HTTPException, status from app.api.deps import CurrentUser, DbSession -from app.crud import signin as crud_signin +from app.repositories import signin as crud_signin from app.schemas.welfare import SigninResultOut, SigninStatusOut logger = logging.getLogger("shagua.signin") diff --git a/app/api/v1/tasks.py b/app/api/v1/tasks.py index 0faa995..beaaf5d 100644 --- a/app/api/v1/tasks.py +++ b/app/api/v1/tasks.py @@ -11,7 +11,7 @@ import logging from fastapi import APIRouter, HTTPException, status from app.api.deps import CurrentUser, DbSession -from app.crud import task as crud_task +from app.repositories import task as crud_task from app.schemas.welfare import TaskClaimResultOut, TaskListOut, TaskOut logger = logging.getLogger("shagua.tasks") diff --git a/app/api/v1/wallet.py b/app/api/v1/wallet.py index 2ac0373..4b57894 100644 --- a/app/api/v1/wallet.py +++ b/app/api/v1/wallet.py @@ -20,7 +20,7 @@ from app.core.rewards import ( WITHDRAW_MAX_CENTS, WITHDRAW_MIN_CENTS, ) -from app.crud import wallet as crud_wallet +from app.repositories import wallet as crud_wallet from app.models.user import User from app.schemas.welfare import ( BindWechatRequest, diff --git a/app/crud/ad_reward.py b/app/repositories/ad_reward.py similarity index 98% rename from app/crud/ad_reward.py rename to app/repositories/ad_reward.py index 2422bd0..bb7d008 100644 --- a/app/crud/ad_reward.py +++ b/app/repositories/ad_reward.py @@ -15,7 +15,7 @@ from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Session from app.core.rewards import AD_REWARD_COIN, DAILY_AD_REWARD_LIMIT, cn_today -from app.crud import wallet as crud_wallet +from app.repositories import wallet as crud_wallet from app.models.ad_reward import AdRewardRecord from app.models.user import User diff --git a/app/crud/savings.py b/app/repositories/savings.py similarity index 100% rename from app/crud/savings.py rename to app/repositories/savings.py diff --git a/app/crud/signin.py b/app/repositories/signin.py similarity index 98% rename from app/crud/signin.py rename to app/repositories/signin.py index 2084816..024f5dc 100644 --- a/app/crud/signin.py +++ b/app/repositories/signin.py @@ -14,7 +14,7 @@ from sqlalchemy import select from sqlalchemy.orm import Session from app.core.rewards import SIGNIN_CYCLE_LEN, SIGNIN_REWARDS, cn_today, signin_reward -from app.crud import wallet as crud_wallet +from app.repositories import wallet as crud_wallet from app.models.signin import SigninRecord diff --git a/app/crud/task.py b/app/repositories/task.py similarity index 97% rename from app/crud/task.py rename to app/repositories/task.py index cf40172..9012243 100644 --- a/app/crud/task.py +++ b/app/repositories/task.py @@ -10,7 +10,7 @@ from sqlalchemy import select from sqlalchemy.orm import Session from app.core.rewards import TASK_REWARDS -from app.crud import wallet as crud_wallet +from app.repositories import wallet as crud_wallet from app.models.task import UserTask diff --git a/app/crud/wallet.py b/app/repositories/wallet.py similarity index 100% rename from app/crud/wallet.py rename to app/repositories/wallet.py diff --git a/scripts/reconcile_withdraws.py b/scripts/reconcile_withdraws.py index 90c9c21..9e1fb20 100644 --- a/scripts/reconcile_withdraws.py +++ b/scripts/reconcile_withdraws.py @@ -20,7 +20,7 @@ try: except Exception: # noqa: BLE001 pass -from app.crud import wallet as crud_wallet +from app.repositories import wallet as crud_wallet from app.db.session import SessionLocal diff --git a/scripts/sim_pangle_callback.py b/scripts/sim_pangle_callback.py index 8b03a49..52e767d 100644 --- a/scripts/sim_pangle_callback.py +++ b/scripts/sim_pangle_callback.py @@ -30,7 +30,7 @@ from sqlalchemy import select # noqa: E402 from app.integrations import pangle # noqa: E402 from app.core.config import settings # noqa: E402 from app.core.rewards import AD_REWARD_COIN # noqa: E402 -from app.crud import wallet as crud_wallet # noqa: E402 +from app.repositories import wallet as crud_wallet # noqa: E402 from app.db.session import SessionLocal # noqa: E402 from app.main import app # noqa: E402 from app.models.user import User # noqa: E402