LATEST__SCHEMA.sql 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. );
  25. -- user_setting
  26. CREATE TABLE user_setting (
  27. user_id INTEGER NOT NULL,
  28. key TEXT NOT NULL,
  29. value TEXT NOT NULL,
  30. UNIQUE(user_id, key)
  31. );
  32. -- memo
  33. CREATE TABLE memo (
  34. id SERIAL PRIMARY KEY,
  35. resource_name TEXT NOT NULL UNIQUE,
  36. creator_id INTEGER NOT NULL,
  37. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  38. updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  39. row_status TEXT NOT NULL DEFAULT 'NORMAL',
  40. content TEXT NOT NULL,
  41. visibility TEXT NOT NULL DEFAULT 'PRIVATE'
  42. );
  43. -- memo_organizer
  44. CREATE TABLE memo_organizer (
  45. memo_id INTEGER NOT NULL,
  46. user_id INTEGER NOT NULL,
  47. pinned INTEGER NOT NULL DEFAULT 0,
  48. UNIQUE(memo_id, user_id)
  49. );
  50. -- memo_relation
  51. CREATE TABLE memo_relation (
  52. memo_id INTEGER NOT NULL,
  53. related_memo_id INTEGER NOT NULL,
  54. type TEXT NOT NULL,
  55. UNIQUE(memo_id, related_memo_id, type)
  56. );
  57. -- resource
  58. CREATE TABLE resource (
  59. id SERIAL PRIMARY KEY,
  60. resource_name TEXT NOT NULL UNIQUE,
  61. creator_id INTEGER NOT NULL,
  62. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  63. updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  64. filename TEXT NOT NULL,
  65. blob BYTEA,
  66. external_link TEXT NOT NULL,
  67. type TEXT NOT NULL DEFAULT '',
  68. size INTEGER NOT NULL DEFAULT 0,
  69. internal_path TEXT NOT NULL DEFAULT '',
  70. memo_id INTEGER DEFAULT NULL
  71. );
  72. -- tag
  73. CREATE TABLE tag (
  74. name TEXT NOT NULL,
  75. creator_id INTEGER NOT NULL,
  76. UNIQUE(name, creator_id)
  77. );
  78. -- activity
  79. CREATE TABLE activity (
  80. id SERIAL PRIMARY KEY,
  81. creator_id INTEGER NOT NULL,
  82. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  83. type TEXT NOT NULL DEFAULT '',
  84. level TEXT NOT NULL DEFAULT 'INFO',
  85. payload JSONB NOT NULL DEFAULT '{}'
  86. );
  87. -- storage
  88. CREATE TABLE storage (
  89. id SERIAL PRIMARY KEY,
  90. name TEXT NOT NULL,
  91. type TEXT NOT NULL,
  92. config JSONB NOT NULL DEFAULT '{}'
  93. );
  94. -- idp
  95. CREATE TABLE idp (
  96. id SERIAL PRIMARY KEY,
  97. name TEXT NOT NULL,
  98. type TEXT NOT NULL,
  99. identifier_filter TEXT NOT NULL DEFAULT '',
  100. config JSONB NOT NULL DEFAULT '{}'
  101. );
  102. -- inbox
  103. CREATE TABLE inbox (
  104. id SERIAL PRIMARY KEY,
  105. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  106. sender_id INTEGER NOT NULL,
  107. receiver_id INTEGER NOT NULL,
  108. status TEXT NOT NULL,
  109. message TEXT NOT NULL
  110. );
  111. -- webhook
  112. CREATE TABLE webhook (
  113. id SERIAL PRIMARY KEY,
  114. created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  115. updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
  116. row_status TEXT NOT NULL DEFAULT 'NORMAL',
  117. creator_id INTEGER NOT NULL,
  118. name TEXT NOT NULL,
  119. url TEXT NOT NULL
  120. );