From ba0c636ffca9b95462ffb120243a61ffe8e92ac6 Mon Sep 17 00:00:00 2001 From: Hossein Date: Thu, 25 Sep 2025 02:19:42 +0330 Subject: [PATCH] update --- database.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/database.py b/database.py index a67c65c..fa65f5d 100644 --- a/database.py +++ b/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 # -----------------------------------------------------------------------------