lots of stuff
This commit is contained in:
parent
f946fbf7b8
commit
4be45f8f7c
9 changed files with 513 additions and 236 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import uuid
|
||||
from datetime import UTC, date, datetime, time
|
||||
from enum import Enum as PyEnum
|
||||
from typing import TypedDict
|
||||
|
|
@ -16,6 +17,7 @@ from sqlalchemy import (
|
|||
UniqueConstraint,
|
||||
select,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
|
|
@ -328,9 +330,20 @@ class Exchange(Base):
|
|||
"""Bitcoin exchange trades booked by users."""
|
||||
|
||||
__tablename__ = "exchanges"
|
||||
__table_args__ = (UniqueConstraint("slot_start", name="uq_exchange_slot_start"),)
|
||||
# Note: No unique constraint on slot_start to allow cancelled bookings
|
||||
# to be replaced. Application-level check in create_exchange ensures only
|
||||
# one BOOKED trade per slot. For existing databases, manually drop the
|
||||
# constraint: ALTER TABLE exchanges DROP CONSTRAINT IF EXISTS
|
||||
# uq_exchange_slot_start;
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
public_id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True),
|
||||
nullable=False,
|
||||
unique=True,
|
||||
index=True,
|
||||
default=uuid.uuid4,
|
||||
)
|
||||
user_id: Mapped[int] = mapped_column(
|
||||
Integer, ForeignKey("users.id"), nullable=False, index=True
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue