-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables.py
More file actions
36 lines (29 loc) · 1.29 KB
/
Copy pathtables.py
File metadata and controls
36 lines (29 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from sqlalchemy import JSON, Boolean, Index, Integer, String, text
from sqlalchemy.orm import Mapped, mapped_column
from library.adapters.database.base import BaseTable, IdentifableMixin, TimestampedMixin
class BookTable(BaseTable, TimestampedMixin, IdentifableMixin):
__tablename__ = "books"
__table_args__ = (
Index(
None,
"title",
"year",
"author",
unique=True,
postgresql_where="deleted_at IS NULL",
),
)
title: Mapped[str] = mapped_column(String(255), nullable=False)
year: Mapped[int] = mapped_column(Integer, nullable=False)
author: Mapped[str] = mapped_column(String(255), nullable=False)
class UserTable(BaseTable, TimestampedMixin, IdentifableMixin):
__tablename__ = "users"
username: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
password_hash: Mapped[str | None] = mapped_column(String(255), nullable=True)
is_superuser: Mapped[bool] = mapped_column(
Boolean, nullable=False, server_default=text("false"), default=False
)
permissions: Mapped[list[str]] = mapped_column(
JSON, nullable=False, server_default=text("'[]'::json"), default=list
)