Spaces:
Build error
Build error
Create database/models.py
Browse files- database/models.py +39 -0
database/models.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Boolean, JSON
|
| 2 |
+
from sqlalchemy.ext.declarative import declarative_base
|
| 3 |
+
from sqlalchemy.orm import sessionmaker
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
from config.settings import settings
|
| 6 |
+
|
| 7 |
+
Base = declarative_base()
|
| 8 |
+
|
| 9 |
+
class RSSEntry(Base):
|
| 10 |
+
__tablename__ = "rss_entries"
|
| 11 |
+
|
| 12 |
+
id = Column(Integer, primary_key=True, index=True)
|
| 13 |
+
entry_id = Column(String, unique=True, index=True, nullable=False)
|
| 14 |
+
feed_url = Column(String, nullable=False)
|
| 15 |
+
title = Column(String)
|
| 16 |
+
link = Column(String)
|
| 17 |
+
published = Column(DateTime)
|
| 18 |
+
content = Column(String)
|
| 19 |
+
processed = Column(Boolean, default=False)
|
| 20 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 21 |
+
|
| 22 |
+
class InstagramPostRecord(Base):
|
| 23 |
+
__tablename__ = "instagram_posts"
|
| 24 |
+
|
| 25 |
+
id = Column(Integer, primary_key=True, index=True)
|
| 26 |
+
rss_entry_id = Column(String, index=True)
|
| 27 |
+
post_data = Column(JSON) # Store the generated post
|
| 28 |
+
image_url = Column(String)
|
| 29 |
+
drive_url = Column(String)
|
| 30 |
+
instagram_post_id = Column(String)
|
| 31 |
+
status = Column(String) # pending, posted, failed
|
| 32 |
+
error_message = Column(String, nullable=True)
|
| 33 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 34 |
+
posted_at = Column(DateTime, nullable=True)
|
| 35 |
+
|
| 36 |
+
# Create engine and session
|
| 37 |
+
engine = create_engine(settings.database_url)
|
| 38 |
+
Base.metadata.create_all(bind=engine)
|
| 39 |
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|