flatfile.schema 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. CREATE TABLE IF NOT EXISTS tag (
  2. id INTEGER PRIMARY KEY AUTOINCREMENT,
  3. name TEXT NOT NULL UNIQUE
  4. );
  5. CREATE TABLE IF NOT EXISTS posts_index (
  6. post_id INTEGER NOT NULL,
  7. tag_id INTEGER NOT NULL REFERENCES tag(id) ON DELETE CASCADE
  8. );
  9. CREATE INDEX IF NOT EXISTS tag_idx ON tag(name);
  10. CREATE VIEW IF NOT EXISTS posts AS SELECT p.post_id as id, t.name AS tag FROM posts_index AS p JOIN tag AS t ON t.id=p.tag_id;
  11. /* The intention is to read this entirely into memory at app startup */
  12. /* This should not incur significant costs, even with millions of posts. */
  13. CREATE TABLE IF NOT EXISTS routes (
  14. route TEXT NOT NULL UNIQUE,
  15. method_id TEXT NOT NULL REFERENCES methods(id) ON DELETE RESTRICT,
  16. callback_id TEXT NOT NULL REFERENCES callbacks(id) ON DELETE RESTRICT
  17. );
  18. /* Enum tables like this always require cleanup when there are no more references. */
  19. /* TODO ^^^ */
  20. CREATE TABLE IF NOT EXISTS methods (
  21. id INTEGER PRIMARY KEY AUTOINCREMENT,
  22. method TEXT NOT NULL
  23. );
  24. CREATE TABLE IF NOT EXISTS callbacks (
  25. id INTEGER PRIMARY KEY AUTOINCREMENT,
  26. callback TEXT NOT NULL
  27. );
  28. CREATE VIEW IF NOT EXISTS all_routes AS SELECT r.route AS route, m.method AS method, c.callback AS callback FROM routes AS r JOIN methods AS m ON m.id=r.method_id JOIN callbacks AS c ON c.id=r.callback_id;