LATEST__SCHEMA.sql 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. -- migration_history
  2. CREATE TABLE migration_history (
  3. version TEXT NOT NULL PRIMARY KEY,
  4. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW())
  5. );
  6. -- system_setting
  7. CREATE TABLE system_setting (
  8. name TEXT NOT NULL PRIMARY KEY,
  9. value TEXT NOT NULL,
  10. description TEXT NOT NULL
  11. );
  12. -- user
  13. CREATE TABLE "user" (
  14. id SERIAL PRIMARY KEY,
  15. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  16. updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  17. row_status TEXT NOT NULL DEFAULT 'NORMAL',
  18. username TEXT NOT NULL UNIQUE,
  19. role TEXT NOT NULL DEFAULT 'USER',
  20. email TEXT NOT NULL DEFAULT '',
  21. nickname TEXT NOT NULL DEFAULT '',
  22. password_hash TEXT NOT NULL,
  23. avatar_url TEXT NOT NULL,
  24. description TEXT NOT NULL DEFAULT ''
  25. );
  26. -- user_setting
  27. CREATE TABLE user_setting (
  28. user_id INTEGER NOT NULL,
  29. key TEXT NOT NULL,
  30. value TEXT NOT NULL,
  31. UNIQUE(user_id, key)
  32. );
  33. -- memo
  34. CREATE TABLE memo (
  35. id SERIAL PRIMARY KEY,
  36. uid TEXT NOT NULL UNIQUE,
  37. creator_id INTEGER NOT NULL,
  38. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  39. updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  40. row_status TEXT NOT NULL DEFAULT 'NORMAL',
  41. content TEXT NOT NULL,
  42. visibility TEXT NOT NULL DEFAULT 'PRIVATE',
  43. tags JSONB NOT NULL DEFAULT '[]',
  44. payload JSONB NOT NULL DEFAULT '{}'
  45. );
  46. -- memo_organizer
  47. CREATE TABLE memo_organizer (
  48. memo_id INTEGER NOT NULL,
  49. user_id INTEGER NOT NULL,
  50. pinned INTEGER NOT NULL DEFAULT 0,
  51. UNIQUE(memo_id, user_id)
  52. );
  53. -- memo_relation
  54. CREATE TABLE memo_relation (
  55. memo_id INTEGER NOT NULL,
  56. related_memo_id INTEGER NOT NULL,
  57. type TEXT NOT NULL,
  58. UNIQUE(memo_id, related_memo_id, type)
  59. );
  60. -- resource
  61. CREATE TABLE resource (
  62. id SERIAL PRIMARY KEY,
  63. uid TEXT NOT NULL UNIQUE,
  64. creator_id INTEGER NOT NULL,
  65. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  66. updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  67. filename TEXT NOT NULL,
  68. blob BYTEA,
  69. type TEXT NOT NULL DEFAULT '',
  70. size INTEGER NOT NULL DEFAULT 0,
  71. memo_id INTEGER DEFAULT NULL,
  72. storage_type TEXT NOT NULL DEFAULT '',
  73. reference TEXT NOT NULL DEFAULT '',
  74. payload TEXT NOT NULL DEFAULT '{}'
  75. );
  76. -- activity
  77. CREATE TABLE activity (
  78. id SERIAL PRIMARY KEY,
  79. creator_id INTEGER NOT NULL,
  80. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  81. type TEXT NOT NULL DEFAULT '',
  82. level TEXT NOT NULL DEFAULT 'INFO',
  83. payload JSONB NOT NULL DEFAULT '{}'
  84. );
  85. -- idp
  86. CREATE TABLE idp (
  87. id SERIAL PRIMARY KEY,
  88. name TEXT NOT NULL,
  89. type TEXT NOT NULL,
  90. identifier_filter TEXT NOT NULL DEFAULT '',
  91. config JSONB NOT NULL DEFAULT '{}'
  92. );
  93. -- inbox
  94. CREATE TABLE inbox (
  95. id SERIAL PRIMARY KEY,
  96. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  97. sender_id INTEGER NOT NULL,
  98. receiver_id INTEGER NOT NULL,
  99. status TEXT NOT NULL,
  100. message TEXT NOT NULL
  101. );
  102. -- webhook
  103. CREATE TABLE webhook (
  104. id SERIAL PRIMARY KEY,
  105. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  106. updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  107. row_status TEXT NOT NULL DEFAULT 'NORMAL',
  108. creator_id INTEGER NOT NULL,
  109. name TEXT NOT NULL,
  110. url TEXT NOT NULL
  111. );
  112. -- reaction
  113. CREATE TABLE reaction (
  114. id SERIAL PRIMARY KEY,
  115. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  116. creator_id INTEGER NOT NULL,
  117. content_id TEXT NOT NULL,
  118. reaction_type TEXT NOT NULL,
  119. UNIQUE(creator_id, content_id, reaction_type)
  120. );