B2: Currency.code — remove unique=True, add tenant-scoped UniqueConstraint
This commit is contained in:
@@ -3,9 +3,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from sqlalchemy import Boolean, DateTime, Index, String
|
from sqlalchemy import Boolean, Index, String, UniqueConstraint
|
||||||
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
@@ -17,6 +16,7 @@ class Currency(Base, TenantMixin):
|
|||||||
|
|
||||||
__tablename__ = "currencies"
|
__tablename__ = "currencies"
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
UniqueConstraint("tenant_id", "code", name="uq_currency_tenant_code"),
|
||||||
Index("ix_currencies_tenant_code", "tenant_id", "code"),
|
Index("ix_currencies_tenant_code", "tenant_id", "code"),
|
||||||
Index("ix_currencies_tenant_default", "tenant_id", "is_default"),
|
Index("ix_currencies_tenant_default", "tenant_id", "is_default"),
|
||||||
)
|
)
|
||||||
@@ -24,7 +24,7 @@ class Currency(Base, TenantMixin):
|
|||||||
id: Mapped[uuid.UUID] = mapped_column(
|
id: Mapped[uuid.UUID] = mapped_column(
|
||||||
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
||||||
)
|
)
|
||||||
code: Mapped[str] = mapped_column(String(3), nullable=False, unique=True)
|
code: Mapped[str] = mapped_column(String(3), nullable=False)
|
||||||
name: Mapped[str] = mapped_column(String(50), nullable=False)
|
name: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||||
symbol: Mapped[str] = mapped_column(String(5), nullable=False)
|
symbol: Mapped[str] = mapped_column(String(5), nullable=False)
|
||||||
is_default: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
is_default: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user