schema.sql 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. -- Schema update to query.sql must be referenced in queries located in query.sql
  2. -- and compiled into code with sqlc. Read README.md for details.
  3. CREATE TABLE IF NOT EXISTS ap_followers (
  4. "iri" TEXT NOT NULL,
  5. "inbox" TEXT NOT NULL,
  6. "name" TEXT,
  7. "username" TEXT NOT NULL,
  8. "image" TEXT,
  9. "request" TEXT NOT NULL,
  10. "request_object" BLOB,
  11. "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  12. "approved_at" TIMESTAMP,
  13. "disabled_at" TIMESTAMP,
  14. PRIMARY KEY (iri));
  15. CREATE INDEX iri_index ON ap_followers (iri);
  16. CREATE INDEX approved_at_index ON ap_followers (approved_at);
  17. CREATE TABLE IF NOT EXISTS ap_outbox (
  18. "iri" TEXT NOT NULL,
  19. "value" BLOB,
  20. "type" TEXT NOT NULL,
  21. "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  22. "live_notification" BOOLEAN DEFAULT FALSE,
  23. PRIMARY KEY (iri));
  24. CREATE INDEX iri ON ap_outbox (iri);
  25. CREATE INDEX type ON ap_outbox (type);
  26. CREATE INDEX live_notification ON ap_outbox (live_notification);
  27. CREATE TABLE IF NOT EXISTS ap_accepted_activities (
  28. "id" INTEGER NOT NULL PRIMARY KEY,
  29. "iri" TEXT NOT NULL,
  30. "actor" TEXT NOT NULL,
  31. "type" TEXT NOT NULL,
  32. "timestamp" TIMESTAMP NOT NULL
  33. );
  34. CREATE INDEX iri_actor_index ON ap_accepted_activities (iri,actor);
  35. CREATE TABLE IF NOT EXISTS ip_bans (
  36. "ip_address" TEXT NOT NULL PRIMARY KEY,
  37. "notes" TEXT,
  38. "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  39. );
  40. CREATE TABLE IF NOT EXISTS notifications (
  41. "id" INTEGER NOT NULL PRIMARY KEY,
  42. "channel" TEXT NOT NULL,
  43. "destination" TEXT NOT NULL,
  44. "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
  45. CREATE INDEX channel_index ON notifications (channel);
  46. CREATE TABLE IF NOT EXISTS users (
  47. "id" TEXT,
  48. "display_name" TEXT NOT NULL,
  49. "display_color" INTEGER NOT NULL,
  50. "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  51. "disabled_at" TIMESTAMP,
  52. "previous_names" TEXT DEFAULT '',
  53. "namechanged_at" TIMESTAMP,
  54. "scopes" TEXT,
  55. "authenticated_at" TIMESTAMP,
  56. "type" TEXT DEFAULT 'STANDARD',
  57. "last_used" DATETIME DEFAULT CURRENT_TIMESTAMP,
  58. PRIMARY KEY (id)
  59. );
  60. CREATE TABLE IF NOT EXISTS user_access_tokens (
  61. "token" TEXT NOT NULL PRIMARY KEY,
  62. "user_id" TEXT NOT NULL,
  63. "timestamp" DATE DEFAULT CURRENT_TIMESTAMP NOT NULL
  64. );
  65. CREATE TABLE IF NOT EXISTS auth (
  66. "id" INTEGER NOT NULL PRIMARY KEY,
  67. "user_id" TEXT NOT NULL,
  68. "token" TEXT NOT NULL,
  69. "type" TEXT NOT NULL,
  70. "timestamp" DATE DEFAULT CURRENT_TIMESTAMP NOT NULL
  71. );
  72. CREATE INDEX auth_token ON auth (token);
  73. CREATE TABLE IF NOT EXISTS messages (
  74. "id" string NOT NULL,
  75. "user_id" TEXT,
  76. "body" TEXT,
  77. "eventType" TEXT,
  78. "hidden_at" DATE,
  79. "timestamp" DATE,
  80. "title" TEXT,
  81. "subtitle" TEXT,
  82. "image" TEXT,
  83. "link" TEXT,
  84. PRIMARY KEY (id)
  85. );CREATE INDEX index ON messages (id, user_id, hidden_at, timestamp);
  86. CREATE INDEX id ON messages (id);
  87. CREATE INDEX user_id ON messages (user_id);
  88. CREATE INDEX hidden_at ON messages (hidden_at);
  89. CREATE INDEX timestamp ON messages (timestamp);