LATEST__SCHEMA.sql 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. -- migration_history
  2. CREATE TABLE migration_history (
  3. version TEXT NOT NULL PRIMARY KEY,
  4. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now'))
  5. );
  6. -- system_setting
  7. CREATE TABLE system_setting (
  8. name TEXT NOT NULL,
  9. value TEXT NOT NULL,
  10. description TEXT NOT NULL DEFAULT '',
  11. UNIQUE(name)
  12. );
  13. -- user
  14. CREATE TABLE user (
  15. id INTEGER PRIMARY KEY AUTOINCREMENT,
  16. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  17. updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  18. row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
  19. username TEXT NOT NULL UNIQUE,
  20. role TEXT NOT NULL CHECK (role IN ('HOST', 'ADMIN', 'USER')) DEFAULT 'USER',
  21. email TEXT NOT NULL DEFAULT '',
  22. nickname TEXT NOT NULL DEFAULT '',
  23. password_hash TEXT NOT NULL,
  24. open_id TEXT NOT NULL UNIQUE,
  25. avatar_url TEXT NOT NULL DEFAULT ''
  26. );
  27. -- user_setting
  28. CREATE TABLE user_setting (
  29. user_id INTEGER NOT NULL,
  30. key TEXT NOT NULL,
  31. value TEXT NOT NULL,
  32. UNIQUE(user_id, key)
  33. );
  34. -- memo
  35. CREATE TABLE memo (
  36. id INTEGER PRIMARY KEY AUTOINCREMENT,
  37. creator_id INTEGER NOT NULL,
  38. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  39. updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  40. row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
  41. content TEXT NOT NULL DEFAULT '',
  42. visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE'
  43. );
  44. -- memo_organizer
  45. CREATE TABLE memo_organizer (
  46. id INTEGER PRIMARY KEY AUTOINCREMENT,
  47. memo_id INTEGER NOT NULL,
  48. user_id INTEGER NOT NULL,
  49. pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0,
  50. UNIQUE(memo_id, user_id)
  51. );
  52. -- shortcut
  53. CREATE TABLE shortcut (
  54. id INTEGER PRIMARY KEY AUTOINCREMENT,
  55. creator_id INTEGER NOT NULL,
  56. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  57. updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  58. row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
  59. title TEXT NOT NULL DEFAULT '',
  60. payload TEXT NOT NULL DEFAULT '{}'
  61. );
  62. -- resource
  63. CREATE TABLE resource (
  64. id INTEGER PRIMARY KEY AUTOINCREMENT,
  65. creator_id INTEGER NOT NULL,
  66. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  67. updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  68. filename TEXT NOT NULL DEFAULT '',
  69. blob BLOB DEFAULT NULL,
  70. external_link TEXT NOT NULL DEFAULT '',
  71. type TEXT NOT NULL DEFAULT '',
  72. size INTEGER NOT NULL DEFAULT 0,
  73. internal_path TEXT NOT NULL DEFAULT '',
  74. public_id TEXT NOT NULL DEFAULT '',
  75. UNIQUE(id, public_id)
  76. );
  77. -- memo_resource
  78. CREATE TABLE memo_resource (
  79. memo_id INTEGER NOT NULL,
  80. resource_id INTEGER NOT NULL,
  81. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  82. updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  83. UNIQUE(memo_id, resource_id)
  84. );
  85. -- tag
  86. CREATE TABLE tag (
  87. name TEXT NOT NULL,
  88. creator_id INTEGER NOT NULL,
  89. UNIQUE(name, creator_id)
  90. );
  91. -- activity
  92. CREATE TABLE activity (
  93. id INTEGER PRIMARY KEY AUTOINCREMENT,
  94. creator_id INTEGER NOT NULL,
  95. created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
  96. type TEXT NOT NULL DEFAULT '',
  97. level TEXT NOT NULL CHECK (level IN ('INFO', 'WARN', 'ERROR')) DEFAULT 'INFO',
  98. payload TEXT NOT NULL DEFAULT '{}'
  99. );
  100. -- storage
  101. CREATE TABLE storage (
  102. id INTEGER PRIMARY KEY AUTOINCREMENT,
  103. name TEXT NOT NULL,
  104. type TEXT NOT NULL,
  105. config TEXT NOT NULL DEFAULT '{}'
  106. );
  107. -- idp
  108. CREATE TABLE idp (
  109. id INTEGER PRIMARY KEY AUTOINCREMENT,
  110. name TEXT NOT NULL,
  111. type TEXT NOT NULL,
  112. identifier_filter TEXT NOT NULL DEFAULT '',
  113. config TEXT NOT NULL DEFAULT '{}'
  114. );