Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the duplicate UID check as it is not needed. #26

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def get_card(card_id: str) -> Optional[Card]:

return Card.parse_obj(card)


"""
async def get_card_by_uid(card_uid: str) -> Optional[Card]:
row = await db.fetchone(
"SELECT * FROM boltcards.cards WHERE uid = ?", (card_uid.upper(),)
Expand All @@ -98,7 +98,7 @@ async def get_card_by_uid(card_uid: str) -> Optional[Card]:
card = dict(**row)

return Card.parse_obj(card)

"""

async def get_card_by_external_id(external_id: str) -> Optional[Card]:
row = await db.fetchone(
Expand Down
37 changes: 37 additions & 0 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,40 @@ async def m001_initial(db):
);
"""
)

async def m002_remove_constraint_unique_uid(db):
"""
Do not check the duplicate UID so remove the constraint from DB.
"""
await db.execute(
"""
CREATE TABLE cardsnew (
id TEXT PRIMARY KEY UNIQUE,
wallet TEXT NOT NULL,
card_name TEXT NOT NULL,
uid TEXT NOT NULL,
external_id TEXT NOT NULL UNIQUE,
counter INT NOT NULL DEFAULT 0,
tx_limit TEXT NOT NULL,
daily_limit TEXT NOT NULL,
enable BOOL NOT NULL,
k0 TEXT NOT NULL DEFAULT '00000000000000000000000000000000',
k1 TEXT NOT NULL DEFAULT '00000000000000000000000000000000',
k2 TEXT NOT NULL DEFAULT '00000000000000000000000000000000',
prev_k0 TEXT NOT NULL DEFAULT '00000000000000000000000000000000',
prev_k1 TEXT NOT NULL DEFAULT '00000000000000000000000000000000',
prev_k2 TEXT NOT NULL DEFAULT '00000000000000000000000000000000',
otp TEXT NOT NULL DEFAULT '',
time TIMESTAMP NOT NULL DEFAULT """
+ db.timestamp_now
+ """
);
"""
)
await db.execute("INSERT INTO boltcards.cardsnew SELECT * FROM boltcards.cards;")
await db.execute("DROP TABLE boltcards.cards;")
await db.execute("ALTER TABLE boltcards.cardsnew RENAME TO cards;")




13 changes: 0 additions & 13 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
delete_card,
enable_disable_card,
get_card,
get_card_by_uid,
get_cards,
get_hits,
get_refunds,
Expand Down Expand Up @@ -82,12 +81,6 @@ async def api_card_update(
raise HTTPException(
detail="Not your card.", status_code=HTTPStatus.FORBIDDEN
)
checkUid = await get_card_by_uid(data.uid)
if checkUid and checkUid.id != card_id:
raise HTTPException(
detail="UID already registered. Delete registered card and try again.",
status_code=HTTPStatus.BAD_REQUEST,
)
card = await update_card(card_id, **data.dict())
assert card, "update_card should always return a card"
return card
Expand All @@ -102,12 +95,6 @@ async def api_card_create(
data: CreateCardData,
wallet: WalletTypeInfo = Depends(require_admin_key),
) -> Card:
checkUid = await get_card_by_uid(data.uid)
if checkUid:
raise HTTPException(
detail="UID already registered. Delete registered card and try again.",
status_code=HTTPStatus.BAD_REQUEST,
)
card = await create_card(wallet_id=wallet.wallet.id, data=data)
assert card, "create_card should always return a card"
return card
Expand Down