You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
8.6 KiB

6 years ago
6 years ago
6 years ago
  1. exports.up = knex => {
  2. return knex.schema
  3. // =====================================
  4. // MODEL TABLES
  5. // =====================================
  6. // ASSETS ------------------------------
  7. .createTable('assets', table => {
  8. table.increments('id').primary()
  9. table.string('filename').notNullable()
  10. table.string('basename').notNullable()
  11. table.string('ext').notNullable()
  12. table.enum('kind', ['binary', 'image']).notNullable().defaultTo('binary')
  13. table.string('mime').notNullable().defaultTo('application/octet-stream')
  14. table.integer('fileSize').unsigned().comment('In kilobytes')
  15. table.json('metadata')
  16. table.string('createdAt').notNullable()
  17. table.string('updatedAt').notNullable()
  18. })
  19. // ASSET FOLDERS -----------------------
  20. .createTable('assetFolders', table => {
  21. table.increments('id').primary()
  22. table.string('name').notNullable()
  23. table.string('slug').notNullable()
  24. table.integer('parentId').unsigned().references('id').inTable('assetFolders')
  25. })
  26. // AUTHENTICATION ----------------------
  27. .createTable('authentication', table => {
  28. table.increments('id').primary()
  29. table.string('key').notNullable().unique()
  30. table.boolean('isEnabled').notNullable().defaultTo(false)
  31. table.json('config').notNullable()
  32. table.boolean('selfRegistration').notNullable().defaultTo(false)
  33. table.json('domainWhitelist').notNullable()
  34. table.json('autoEnrollGroups').notNullable()
  35. })
  36. // COMMENTS ----------------------------
  37. .createTable('comments', table => {
  38. table.increments('id').primary()
  39. table.text('content').notNullable()
  40. table.string('createdAt').notNullable()
  41. table.string('updatedAt').notNullable()
  42. })
  43. // EDITORS -----------------------------
  44. .createTable('editors', table => {
  45. table.increments('id').primary()
  46. table.string('key').notNullable().unique()
  47. table.boolean('isEnabled').notNullable().defaultTo(false)
  48. table.json('config').notNullable()
  49. })
  50. // GROUPS ------------------------------
  51. .createTable('groups', table => {
  52. table.increments('id').primary()
  53. table.string('name').notNullable()
  54. table.string('createdAt').notNullable()
  55. table.string('updatedAt').notNullable()
  56. })
  57. // LOCALES -----------------------------
  58. .createTable('locales', table => {
  59. table.increments('id').primary()
  60. table.string('code', 2).notNullable().unique()
  61. table.json('strings')
  62. table.boolean('isRTL').notNullable().defaultTo(false)
  63. table.string('name').notNullable()
  64. table.string('nativeName').notNullable()
  65. table.string('createdAt').notNullable()
  66. table.string('updatedAt').notNullable()
  67. })
  68. // PAGE HISTORY ------------------------
  69. .createTable('pageHistory', table => {
  70. table.increments('id').primary()
  71. table.string('path').notNullable()
  72. table.string('title').notNullable()
  73. table.string('description')
  74. table.boolean('isPrivate').notNullable().defaultTo(false)
  75. table.boolean('isPublished').notNullable().defaultTo(false)
  76. table.string('publishStartDate')
  77. table.string('publishEndDate')
  78. table.text('content')
  79. table.string('contentType').notNullable()
  80. table.string('createdAt').notNullable()
  81. })
  82. // PAGES -------------------------------
  83. .createTable('pages', table => {
  84. table.increments('id').primary()
  85. table.string('path').notNullable()
  86. table.string('title').notNullable()
  87. table.string('description')
  88. table.boolean('isPrivate').notNullable().defaultTo(false)
  89. table.boolean('isPublished').notNullable().defaultTo(false)
  90. table.string('publishStartDate')
  91. table.string('publishEndDate')
  92. table.text('content')
  93. table.text('render')
  94. table.string('contentType').notNullable()
  95. table.string('createdAt').notNullable()
  96. table.string('updatedAt').notNullable()
  97. })
  98. // SETTINGS ----------------------------
  99. .createTable('settings', table => {
  100. table.increments('id').primary()
  101. table.string('key').notNullable().unique()
  102. table.json('value')
  103. table.string('updatedAt').notNullable()
  104. })
  105. // STORAGE -----------------------------
  106. .createTable('storage', table => {
  107. table.increments('id').primary()
  108. table.string('key').notNullable().unique()
  109. table.boolean('isEnabled').notNullable().defaultTo(false)
  110. table.enum('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
  111. table.json('config')
  112. })
  113. // TAGS --------------------------------
  114. .createTable('tags', table => {
  115. table.increments('id').primary()
  116. table.string('tag').notNullable().unique()
  117. table.string('title')
  118. table.string('createdAt').notNullable()
  119. table.string('updatedAt').notNullable()
  120. })
  121. // USERS -------------------------------
  122. .createTable('users', table => {
  123. table.increments('id').primary()
  124. table.string('email').notNullable()
  125. table.string('name').notNullable()
  126. table.string('providerId')
  127. table.string('password')
  128. table.boolean('tfaIsActive').notNullable().defaultTo(false)
  129. table.string('tfaSecret')
  130. table.enum('role', ['admin', 'guest', 'user']).notNullable().defaultTo('guest')
  131. table.string('jobTitle').defaultTo('')
  132. table.string('location').defaultTo('')
  133. table.string('pictureUrl')
  134. table.string('timezone').notNullable().defaultTo('America/New_York')
  135. table.string('createdAt').notNullable()
  136. table.string('updatedAt').notNullable()
  137. })
  138. // =====================================
  139. // RELATION TABLES
  140. // =====================================
  141. // PAGE HISTORY TAGS ---------------------------
  142. .createTable('pageHistoryTags', table => {
  143. table.increments('id').primary()
  144. table.integer('pageId').unsigned().references('id').inTable('pageHistory').onDelete('CASCADE')
  145. table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
  146. })
  147. // PAGE TAGS ---------------------------
  148. .createTable('pageTags', table => {
  149. table.increments('id').primary()
  150. table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
  151. table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
  152. })
  153. // USER GROUPS -------------------------
  154. .createTable('userGroups', table => {
  155. table.increments('id').primary()
  156. table.integer('userId').unsigned().references('id').inTable('users').onDelete('CASCADE')
  157. table.integer('groupId').unsigned().references('id').inTable('groups').onDelete('CASCADE')
  158. })
  159. // =====================================
  160. // REFERENCES
  161. // =====================================
  162. .table('assets', table => {
  163. table.integer('folderId').unsigned().references('id').inTable('assetFolders')
  164. table.integer('authorId').unsigned().references('id').inTable('users')
  165. })
  166. .table('comments', table => {
  167. table.integer('pageId').unsigned().references('id').inTable('pages')
  168. table.integer('authorId').unsigned().references('id').inTable('users')
  169. })
  170. .table('pageHistory', table => {
  171. table.integer('pageId').unsigned().references('id').inTable('pages')
  172. table.string('editorKey').references('key').inTable('editors')
  173. table.string('localeCode', 2).references('code').inTable('locales')
  174. table.integer('authorId').unsigned().references('id').inTable('users')
  175. })
  176. .table('pages', table => {
  177. table.string('editorKey').references('key').inTable('editors')
  178. table.string('localeCode', 2).references('code').inTable('locales')
  179. table.integer('authorId').unsigned().references('id').inTable('users')
  180. table.integer('creatorId').unsigned().references('id').inTable('users')
  181. })
  182. .table('users', table => {
  183. table.string('providerKey').references('key').inTable('authentication').notNullable().defaultTo('local')
  184. table.string('localeCode', 2).references('code').inTable('locales').notNullable().defaultTo('en')
  185. table.string('defaultEditor').references('key').inTable('editors').notNullable().defaultTo('markdown')
  186. table.unique(['providerKey', 'email'])
  187. })
  188. }
  189. exports.down = knex => {
  190. return knex.schema
  191. .dropTableIfExists('userGroups')
  192. .dropTableIfExists('pageTags')
  193. .dropTableIfExists('assets')
  194. .dropTableIfExists('assetFolders')
  195. .dropTableIfExists('comments')
  196. .dropTableIfExists('groups')
  197. .dropTableIfExists('locales')
  198. .dropTableIfExists('pages')
  199. .dropTableIfExists('settings')
  200. .dropTableIfExists('tags')
  201. .dropTableIfExists('users')
  202. }