update
This commit is contained in:
parent
898705ed51
commit
ba0c636ffc
29
database.py
29
database.py
@ -3,7 +3,7 @@ import os
|
||||
import uuid
|
||||
from sqlalchemy import (
|
||||
create_engine, Column, Integer, String, Float, DateTime, Boolean, Text,
|
||||
ForeignKey, UniqueConstraint, Index
|
||||
ForeignKey
|
||||
)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker, relationship
|
||||
@ -52,15 +52,10 @@ class InstaCursor(Base):
|
||||
__tablename__ = "insta_cursors"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
username = Column(String(150), nullable=False, unique=True)
|
||||
username = Column(String(150), nullable=False, unique=True) # unique → implicit unique index
|
||||
next_max_id = Column(String(255), nullable=True)
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("username", name="uq_insta_cursor_username"),
|
||||
Index("ix_insta_cursors_username", "username"),
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Instagram Account
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -68,8 +63,8 @@ class InstagramAccount(Base):
|
||||
__tablename__ = "instagram_accounts"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
seller_id = Column(UUID(as_uuid=True), nullable=False)
|
||||
username = Column(String(100), nullable=False, unique=True, index=True)
|
||||
seller_id = Column(UUID(as_uuid=True), nullable=False, index=True) # index for lookups by seller
|
||||
username = Column(String(100), nullable=False, unique=True) # unique → implicit unique index
|
||||
is_active = Column(Boolean, default=True)
|
||||
last_synced = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
@ -80,12 +75,6 @@ class InstagramAccount(Base):
|
||||
passive_deletes=True,
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("username", name="uq_instagram_accounts_username"),
|
||||
Index("ix_instagram_accounts_username", "username"),
|
||||
Index("ix_instagram_accounts_seller_id", "seller_id"),
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Instagram Post
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -99,8 +88,8 @@ class InstagramPost(Base):
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
ig_post_id = Column(String(100), nullable=False, unique=True, index=True)
|
||||
media_type = Column(String(10), nullable=False) # 'image', 'video', 'carousel'
|
||||
ig_post_id = Column(String(100), nullable=False, unique=True) # unique → implicit unique index
|
||||
media_type = Column(String(10), nullable=False, index=True) # 'image', 'video', 'carousel'
|
||||
caption = Column(Text, nullable=True)
|
||||
thumbnail_url = Column(Text, nullable=True)
|
||||
|
||||
@ -114,12 +103,6 @@ class InstagramPost(Base):
|
||||
|
||||
account = relationship("InstagramAccount", back_populates="posts")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("ig_post_id", name="uq_instagram_posts_ig_post_id"),
|
||||
Index("ix_instagram_posts_created_at", "created_at"),
|
||||
Index("ix_instagram_posts_media_type", "media_type"),
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Session dependency
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user