nininigold's picture
Upload folder using huggingface_hub
3cecacc verified
from sqlalchemy import Column, Integer, Float, String, DateTime, Boolean, JSON, ForeignKey, Enum as SQLEnum
from sqlalchemy.orm import relationship, backref
from datetime import datetime
from sqlalchemy.ext.declarative import declarative_base
from database import Base
class Subscription(Base):
__tablename__ = "subscriptions"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
plan_name = Column(String) # ๊ตฌ๋… ํ”Œ๋žœ ์ด๋ฆ„
start_time = Column(DateTime) # ๊ตฌ๋… ์‹œ์ž‘ ์‹œ๊ฐ„
end_time = Column(DateTime, nullable=True) # ๊ตฌ๋… ์ข…๋ฃŒ ์‹œ๊ฐ„
billing_key = Column(String) # ๊ฒฐ์ œ ํ‚ค
schedule_id = Column(String) # ์Šค์ผ€์ค„ ID
issue_id = Column(String) # ์ด์Šˆ ID
customer_id = Column(String) # ๊ณ ๊ฐ ID
billing_method = Column(String, nullable = True) # ๊ฒฐ์ œ ์ˆ˜๋‹จ, billing_key์™€ ์—ญํ• ์ด ๊ฒน์น ์ˆ˜๋„ ์žˆ๊ธดํ•จ
billing_cycle = Column(String, nullable = True) # ๊ฒฐ์ œ ์ฃผ๊ธฐ. year or month
next_billing_time = Column(DateTime, nullable=True) # ๋‹ค์Œ ๊ฒฐ์ œ ์‹œ๊ฐ„ #๊ฐ™์€ ์ผ์ž์ด๊ณ , ์—†๋Š” ๊ฒฝ์šฐ ๋ง์ผ
is_active = Column(Boolean, default=True) # ๊ตฌ๋… ํ™œ์„ฑ ์ƒํƒœ
deleted = Column(Boolean, default = False)
user = relationship("User", back_populates="subscriptions")
def __repr__(self):
return f"<Subscription(id={self.id}, user_id={self.user_id}, plan_name='{self.plan_name}', is_active={self.is_active})>"
class Payment(Base):
__tablename__ = "payments"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
subscription_id = Column(Integer, ForeignKey('subscriptions.id'), nullable=False)
portone_tx_id = Column(String) # ํฌํŠธ์› ์ฃผ๋ฌธ๋ฒˆํ˜ธ(ํŠธ๋žœ์žญ์…˜ ID)
amount = Column(Float) # ๊ฒฐ์ œ ๊ธˆ์•ก
currency = Column(String) # ๊ฒฐ์ œ ํ†ตํ™”
dollar_amount = Column(Float) # Scale ์ ์šฉ์—†๋Š”, ์ง„์งœ ๋‹ฌ๋Ÿฌ
payment_time = Column(DateTime, default=datetime.utcnow) # ๊ฒฐ์ œ ๋‚ ์งœ
payment_method = Column(String) # ๊ฒฐ์ œ ๋ฐฉ๋ฒ•
payment_id = Column(String) # ๊ฒฐ์ œ ID
issue_id = Column(String)
receipt_url = Column(String) # ์˜์ˆ˜์ฆ URL
status = Column(String) # ๊ฒฐ์ œ ์ƒํƒœ
user = relationship("User", back_populates="payments")
subscription = relationship("Subscription", backref=backref("payments", cascade="all, delete-orphan"))
deleted = Column(Boolean, default = False)
payment_number = Column(String, unique=True) # ๊ฒฐ์ œ ๋ฒˆํ˜ธ
def __repr__(self):
return f"<Payment(id={self.id}, user_id={self.user_id}, amount={self.amount}, currency='{self.currency}', status='{self.status}')>"
def generate_payment_number(self):
print(self.payment_time)
unique_string = f"{self.payment_time.strftime('%Y%m%d')}{self.user_id}{self.id:010d}"
return unique_string
class Billing_Key(Base):
__tablename__ = "billing_keys"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
billing_key = Column(String) # ๊ฒฐ์ œ ํ‚ค
deleted = Column(Boolean, default = False)
requested_at = Column(DateTime, default=datetime.utcnow) # ์š”์ฒญ ๋‚ ์งœ
payment_method = Column(String) # toss payments or paypal
billing_key_json = Column(JSON)
def __repr__(self):
return f"<Billing_Key(id={self.id}, user_id={self.user_id}, billing_key='{self.billing_key}', requested_at={self.requested_at})>"
class Exchange_Rate(Base):
__tablename__ = "exchange_rates"
id = Column(Integer, primary_key=True, index=True)
currency = Column(String) # ํ†ตํ™”
rate = Column(Float) # ํ™˜์œจ
updated_at = Column(DateTime, default=datetime.utcnow) # ์—…๋ฐ์ดํŠธ ๋‚ ์งœ
def __repr__(self):
return f"<Exchange_Rate(id={self.id}, currency='{self.currency}', rate={self.rate}, updated_at={self.updated_at})>"