-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
23 lines (19 loc) · 980 Bytes
/
model.py
File metadata and controls
23 lines (19 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from database import Base
from sqlalchemy import Column, Integer, String, DateTime, func, ForeignKey
from sqlalchemy.orm import relationship
class ShortURL(Base):
__tablename__ = "short_url"
uuid = Column(Integer, primary_key=True, index=True, autoincrement=True)
original_url = Column(String, nullable=False)
short_code = Column(String, unique=True, nullable=False, index=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
visit_count = Column(Integer, default=0)
access_log = relationship("AccessLog", back_populates="short_url")
class AccessLog(Base):
__tablename__ = "access_log"
uuid = Column(Integer, primary_key=True, index=True, autoincrement=True)
short_code = Column(
String, ForeignKey("short_url.short_code"), nullable=False, index=True
)
time_stamp = Column(DateTime(timezone=True), server_default=func.now())
short_url = relationship("ShortURL", back_populates="access_log")