greedot TODO

gosu·2024년 1월 23일
0
post-custom-banner

greedot TODO

지금까지 한 것

  • fast api 공부
  • db 설계
from sqlalchemy import create_engine

from sqlalchemy import create_engine, Column, Integer, String, Date, Enum, ForeignKey, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from enum import unique, Enum as PyEnum

Base = declarative_base()

@unique
class RoleEnum(PyEnum):
    ADMIN = "ADMIN"
    MANAGER = "MANAGER"
    MEMBER = "MEMBER"

@unique
class StatusEnum(PyEnum):
    ACTIVATE = "ACTIVATE"
    DISABLED = "DISABLED"

@unique
class GradeEnum(PyEnum):
    FREE = "FREE"
    BASIC = "BASIC"
    PREMIUM = "PREMIUM"

@unique
class LogTypeEnum(PyEnum):
    SENDTALK = "SENDTALK"
    RECEIVEDTALK = "RECEIVEDTALK"
    CLICKED = "CLICKED"

@unique
class LogTypeEnum(PyEnum):
    SENDTALK = "SENDTALK"
    RECEIVEDTALK = "RECEIVEDTALK"
    CLICKED = "CLICKED"

class Member(Base):
    __tablename__ = 'member'
    
    id = Column('member_id', Integer, primary_key=True, autoincrement=True)
    email = Column(String(255), nullable=False)
    nickname = Column(String(255), nullable=False)
    password = Column(String(255), nullable=False)
    role = Column(Enum(RoleEnum), nullable=False)
    status = Column(Enum(StatusEnum), nullable=False)
    grade = Column(Enum(GradeEnum), nullable=False)
    register_at = Column(Date, nullable=False)
    
    gree = relationship("Gree", back_populates="member")
    logs = relationship("Logs", back_populates="member")
    
class Gree(Base):
    __tablename__ = 'gree'
    
    id = Column('gree_id', Integer, primary_key=True, autoincrement=True)
    member_id = Column(Integer, ForeignKey('member.member_id'), nullable=False)
    gree_name = Column(String(255), nullable=False)
    root_path = Column(String(255), nullable=False)
    prompt_character = Column(String(255))  # Should be a relationship if it's an enum
    prompt_age = Column(Integer)
    prompt_mbti = Column(String(255))  # Should be a relationship if it's an enum
    register_at = Column(Date, nullable=False)
    
    member = relationship("Member", back_populates="gree")
    logs = relationship("Logs", back_populates="gree")
    
class Logs(Base):
    __tablename__ = 'logs'
    
    id = Column('log_id', Integer, primary_key=True, autoincrement=True)
    gree_id = Column(Integer, ForeignKey('gree.gree_id'), nullable=False)
    member_id = Column(Integer, ForeignKey('member.member_id'), nullable=False)
    log_type = Column(Enum(LogTypeEnum), nullable=False)
    talk = Column(String(255))
    register_at = Column(Date, nullable=False)

    member = relationship("Member", back_populates="logs")
    gree = relationship("Gree", back_populates="logs")





# 데이터베이스 설정
SERVER_HOST = "database-1.c3mqckcawht2.ap-southeast-2.rds.amazonaws.com"
USERNAME = "admin"
PASSWORD = "63814110"
DATABASE_NAME = "greedot"

# SQLAlchemy 엔진 생성
engine = create_engine(f"mysql+pymysql://{USERNAME}:{PASSWORD}@{SERVER_HOST}/{DATABASE_NAME}")

# 데이터베이스에 테이블 생성
Base.metadata.create_all(engine)

TODO

  • sqlalchemy 공부
  • 1대N 관계 제대로 매핑할 것
profile
개발자 블로그 ^0^
post-custom-banner

0개의 댓글