auranexus / database /models.py
Ahmed766's picture
Upload database/models.py with huggingface_hub
7c7db8b verified
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, Boolean, ForeignKey, JSON
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship
from datetime import datetime
import uuid
Base = declarative_base()
class User(Base):
__tablename__ = "users"
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
email = Column(String, unique=True, nullable=False, index=True)
username = Column(String, unique=True, nullable=False, index=True)
hashed_password = Column(String, nullable=False)
is_active = Column(Boolean, default=True)
is_verified = Column(Boolean, default=False)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
content_items = relationship("ContentItem", back_populates="owner")
scheduled_posts = relationship("ScheduledPost", back_populates="owner")
class ContentItem(Base):
__tablename__ = "content_items"
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
owner_id = Column(String, ForeignKey("users.id"), nullable=False)
title = Column(String, nullable=False)
content_type = Column(String, nullable=False) # blog, social, video_script, etc.
original_prompt = Column(Text)
generated_content = Column(Text)
platform_specific_variants = Column(JSON) # Different versions for different platforms
tags = Column(JSON) # List of tags
status = Column(String, default="draft") # draft, published, archived
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
owner = relationship("User", back_populates="content_items")
scheduled_posts = relationship("ScheduledPost", back_populates="content_item")
class ScheduledPost(Base):
__tablename__ = "scheduled_posts"
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
owner_id = Column(String, ForeignKey("users.id"), nullable=False)
content_item_id = Column(String, ForeignKey("content_items.id"), nullable=False)
platform = Column(String, nullable=False) # twitter, instagram, youtube, etc.
scheduled_time = Column(DateTime, nullable=False)
status = Column(String, default="scheduled") # scheduled, published, failed
platform_metadata = Column(JSON) # Platform-specific metadata
published_at = Column(DateTime)
created_at = Column(DateTime, default=datetime.utcnow)
# Relationships
owner = relationship("User", back_populates="scheduled_posts")
content_item = relationship("ContentItem", back_populates="scheduled_posts")
class AIModelConfig(Base):
__tablename__ = "ai_model_configs"
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
model_name = Column(String, nullable=False)
model_type = Column(String, nullable=False) # text_generation, image_generation, embedding
provider = Column(String, nullable=False) # local, api
model_path = Column(String) # Path for local models
api_endpoint = Column(String) # Endpoint for API models
is_active = Column(Boolean, default=True)
config_params = Column(JSON) # Model-specific parameters
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
class PlatformCredential(Base):
__tablename__ = "platform_credentials"
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
user_id = Column(String, ForeignKey("users.id"), nullable=False)
platform = Column(String, nullable=False) # twitter, instagram, youtube, etc.
encrypted_credential = Column(String, nullable=False) # Encrypted OAuth tokens
scopes = Column(JSON) # Granted permissions
expires_at = Column(DateTime)
is_active = Column(Boolean, default=True)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
user = relationship("User")
# Database setup
DATABASE_URL = "sqlite:///./auranexus.db"
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def create_tables():
Base.metadata.create_all(bind=engine)