728x90
1. entities.py
from uuid import UUID
from advanced_alchemy.base import UUIDAuditBase
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.dialects.postgresql import UUID as psql_UUID # postgresql ์์๋ string type ์ด ์๋ UUID type์ผ๋ก ๊ด๋ฆฌํ๊ธฐ ์ํด import
class IdempotencyKey(UUIDAuditBase):
idempotency_key: Mapped[UUID] = mapped_column(psql_UUID(as_uuid=True), unique=True, nullable=False)
2. auto ddl example code
from sqlalchemy import create_engine
from api.domain.credit.entities import IdempotencyKey
# ์ฐ๊ฒฐํ๊ณ ์ ํ๋ Database์ ์ ๋ณด๋ฅผ ์ค์
engine = create_engine("postgresql://postgres:{DATABASE_PASSWORD}@127.0.0.1:54322/postgres")
# ์๋์ผ๋ก DDL ์ ์์ฑํ์ฌ CREATE TABLE ์ ์คํํ๋ค.
IdempotencyKey.metadata.create_all(engine)
3. ๊ฒฐ๊ณผ
๋์ ๊ฒฝ์ฐ supabase ๋ฅผ ์ฌ์ฉํ๊ธฐ์ supabase web console์์ ํ์ธํด๋ณธ ๊ฒฐ๊ณผ ๋ค์๊ณผ ๊ฐ์ด table ์ด ์์ฑ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
728x90
'Backend ๐ป' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฉฑ๋ฑ์ฑ์ ๋ณด์ฅํ๋ ์์คํ ๊ฐ๋ฐํ๊ธฐ (5) | 2024.10.13 |
---|---|
[GitHub] REMOTE HOST IDENTIFICATION HAS CHANGED ํด๊ฒฐ๋ฐฉ๋ฒ (0) | 2023.03.26 |