Upload database/models.py with huggingface_hub
Browse files- database/models.py +96 -0
database/models.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, Boolean, ForeignKey, JSON
|
| 2 |
+
from sqlalchemy.ext.declarative import declarative_base
|
| 3 |
+
from sqlalchemy.orm import sessionmaker, relationship
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import uuid
|
| 6 |
+
|
| 7 |
+
Base = declarative_base()
|
| 8 |
+
|
| 9 |
+
class User(Base):
|
| 10 |
+
__tablename__ = "users"
|
| 11 |
+
|
| 12 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 13 |
+
email = Column(String, unique=True, nullable=False, index=True)
|
| 14 |
+
username = Column(String, unique=True, nullable=False, index=True)
|
| 15 |
+
hashed_password = Column(String, nullable=False)
|
| 16 |
+
is_active = Column(Boolean, default=True)
|
| 17 |
+
is_verified = Column(Boolean, default=False)
|
| 18 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 19 |
+
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 20 |
+
|
| 21 |
+
# Relationships
|
| 22 |
+
content_items = relationship("ContentItem", back_populates="owner")
|
| 23 |
+
scheduled_posts = relationship("ScheduledPost", back_populates="owner")
|
| 24 |
+
|
| 25 |
+
class ContentItem(Base):
|
| 26 |
+
__tablename__ = "content_items"
|
| 27 |
+
|
| 28 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 29 |
+
owner_id = Column(String, ForeignKey("users.id"), nullable=False)
|
| 30 |
+
title = Column(String, nullable=False)
|
| 31 |
+
content_type = Column(String, nullable=False) # blog, social, video_script, etc.
|
| 32 |
+
original_prompt = Column(Text)
|
| 33 |
+
generated_content = Column(Text)
|
| 34 |
+
platform_specific_variants = Column(JSON) # Different versions for different platforms
|
| 35 |
+
tags = Column(JSON) # List of tags
|
| 36 |
+
status = Column(String, default="draft") # draft, published, archived
|
| 37 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 38 |
+
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 39 |
+
|
| 40 |
+
# Relationships
|
| 41 |
+
owner = relationship("User", back_populates="content_items")
|
| 42 |
+
scheduled_posts = relationship("ScheduledPost", back_populates="content_item")
|
| 43 |
+
|
| 44 |
+
class ScheduledPost(Base):
|
| 45 |
+
__tablename__ = "scheduled_posts"
|
| 46 |
+
|
| 47 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 48 |
+
owner_id = Column(String, ForeignKey("users.id"), nullable=False)
|
| 49 |
+
content_item_id = Column(String, ForeignKey("content_items.id"), nullable=False)
|
| 50 |
+
platform = Column(String, nullable=False) # twitter, instagram, youtube, etc.
|
| 51 |
+
scheduled_time = Column(DateTime, nullable=False)
|
| 52 |
+
status = Column(String, default="scheduled") # scheduled, published, failed
|
| 53 |
+
platform_metadata = Column(JSON) # Platform-specific metadata
|
| 54 |
+
published_at = Column(DateTime)
|
| 55 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 56 |
+
|
| 57 |
+
# Relationships
|
| 58 |
+
owner = relationship("User", back_populates="scheduled_posts")
|
| 59 |
+
content_item = relationship("ContentItem", back_populates="scheduled_posts")
|
| 60 |
+
|
| 61 |
+
class AIModelConfig(Base):
|
| 62 |
+
__tablename__ = "ai_model_configs"
|
| 63 |
+
|
| 64 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 65 |
+
model_name = Column(String, nullable=False)
|
| 66 |
+
model_type = Column(String, nullable=False) # text_generation, image_generation, embedding
|
| 67 |
+
provider = Column(String, nullable=False) # local, api
|
| 68 |
+
model_path = Column(String) # Path for local models
|
| 69 |
+
api_endpoint = Column(String) # Endpoint for API models
|
| 70 |
+
is_active = Column(Boolean, default=True)
|
| 71 |
+
config_params = Column(JSON) # Model-specific parameters
|
| 72 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 73 |
+
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 74 |
+
|
| 75 |
+
class PlatformCredential(Base):
|
| 76 |
+
__tablename__ = "platform_credentials"
|
| 77 |
+
|
| 78 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 79 |
+
user_id = Column(String, ForeignKey("users.id"), nullable=False)
|
| 80 |
+
platform = Column(String, nullable=False) # twitter, instagram, youtube, etc.
|
| 81 |
+
encrypted_credential = Column(String, nullable=False) # Encrypted OAuth tokens
|
| 82 |
+
scopes = Column(JSON) # Granted permissions
|
| 83 |
+
expires_at = Column(DateTime)
|
| 84 |
+
is_active = Column(Boolean, default=True)
|
| 85 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 86 |
+
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 87 |
+
|
| 88 |
+
user = relationship("User")
|
| 89 |
+
|
| 90 |
+
# Database setup
|
| 91 |
+
DATABASE_URL = "sqlite:///./auranexus.db"
|
| 92 |
+
engine = create_engine(DATABASE_URL)
|
| 93 |
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
| 94 |
+
|
| 95 |
+
def create_tables():
|
| 96 |
+
Base.metadata.create_all(bind=engine)
|