0020_buddy_feeds.up.sql 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. -- Migration: 0019_buddy_feeds
  2. -- Description: Create tables for buddy feed functionality
  3. -- Date: 2024-12-28
  4. -- Create buddy feeds table for storing user feed configurations
  5. CREATE TABLE IF NOT EXISTS buddy_feeds (
  6. id INTEGER PRIMARY KEY AUTOINCREMENT,
  7. screen_name VARCHAR(16) NOT NULL,
  8. feed_type VARCHAR(50) NOT NULL, -- 'rss', 'atom', 'status', 'blog', 'social'
  9. title TEXT,
  10. description TEXT,
  11. link TEXT,
  12. published_at INTEGER NOT NULL,
  13. created_at INTEGER NOT NULL,
  14. updated_at INTEGER NOT NULL,
  15. is_active BOOLEAN DEFAULT TRUE
  16. );
  17. -- Create indexes for efficient querying
  18. CREATE INDEX idx_buddy_feeds_screen_name ON buddy_feeds(screen_name);
  19. CREATE INDEX idx_buddy_feeds_published ON buddy_feeds(published_at);
  20. CREATE INDEX idx_buddy_feeds_type ON buddy_feeds(feed_type);
  21. CREATE INDEX idx_buddy_feeds_active ON buddy_feeds(is_active);
  22. -- Create buddy feed items table for individual feed entries
  23. CREATE TABLE IF NOT EXISTS buddy_feed_items (
  24. id INTEGER PRIMARY KEY AUTOINCREMENT,
  25. feed_id INTEGER NOT NULL,
  26. title TEXT NOT NULL,
  27. description TEXT,
  28. link TEXT,
  29. guid TEXT,
  30. author VARCHAR(16), -- Screen name of the author
  31. categories TEXT, -- JSON array of categories
  32. published_at INTEGER NOT NULL,
  33. created_at INTEGER NOT NULL,
  34. FOREIGN KEY (feed_id) REFERENCES buddy_feeds(id) ON DELETE CASCADE
  35. );
  36. -- Create indexes for feed items
  37. CREATE INDEX idx_feed_items_feed_id ON buddy_feed_items(feed_id);
  38. CREATE INDEX idx_feed_items_published ON buddy_feed_items(published_at);
  39. CREATE INDEX idx_feed_items_guid ON buddy_feed_items(guid);
  40. -- Create buddy feed subscriptions table for tracking who follows which feeds
  41. CREATE TABLE IF NOT EXISTS buddy_feed_subscriptions (
  42. id INTEGER PRIMARY KEY AUTOINCREMENT,
  43. subscriber_screen_name VARCHAR(16) NOT NULL,
  44. feed_id INTEGER NOT NULL,
  45. subscribed_at INTEGER NOT NULL,
  46. last_checked_at INTEGER,
  47. FOREIGN KEY (feed_id) REFERENCES buddy_feeds(id) ON DELETE CASCADE,
  48. UNIQUE(subscriber_screen_name, feed_id)
  49. );
  50. -- Create indexes for subscriptions
  51. CREATE INDEX idx_feed_subs_subscriber ON buddy_feed_subscriptions(subscriber_screen_name);
  52. CREATE INDEX idx_feed_subs_feed_id ON buddy_feed_subscriptions(feed_id);