29 lines
1.3 KiB
Python
29 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import DateTime, String, UniqueConstraint, text
|
|
from sqlalchemy.dialects.mysql import BIGINT, INTEGER, TINYINT
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from backend.db.base import Base
|
|
|
|
|
|
class Customer(Base):
|
|
__tablename__ = "customers"
|
|
__table_args__ = (UniqueConstraint("name", name="uniq_customer_name"),)
|
|
|
|
id: Mapped[int] = mapped_column(BIGINT(unsigned=True), primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
contact_email: Mapped[Optional[str]] = mapped_column(String(128))
|
|
is_active: Mapped[int] = mapped_column(TINYINT(1), nullable=False, server_default=text("1"))
|
|
quota_instances: Mapped[Optional[int]] = mapped_column(INTEGER(unsigned=True))
|
|
notes: Mapped[Optional[str]] = mapped_column(String(255))
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"), nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, server_default=text("CURRENT_TIMESTAMP"), onupdate=text("CURRENT_TIMESTAMP"), nullable=False
|
|
)
|
|
|
|
users: Mapped[list["User"]] = relationship("User", back_populates="customer")
|