2018-05-19 20:40:07 +00:00
|
|
|
exports.up = knex => {
|
|
|
|
return knex.schema
|
2018-05-20 22:50:51 +00:00
|
|
|
// =====================================
|
|
|
|
// MODEL TABLES
|
|
|
|
// =====================================
|
|
|
|
// ASSETS ------------------------------
|
|
|
|
.createTable('assets', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('filename').notNullable()
|
|
|
|
table.string('basename').notNullable()
|
|
|
|
table.string('ext').notNullable()
|
|
|
|
table.enum('kind', ['binary', 'image']).notNullable().defaultTo('binary')
|
|
|
|
table.string('mime').notNullable().defaultTo('application/octet-stream')
|
|
|
|
table.integer('fileSize').unsigned().comment('In kilobytes')
|
2018-08-16 01:57:28 +00:00
|
|
|
table.json('metadata')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
|
|
|
// ASSET FOLDERS -----------------------
|
|
|
|
.createTable('assetFolders', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('name').notNullable()
|
|
|
|
table.string('slug').notNullable()
|
|
|
|
table.integer('parentId').unsigned().references('id').inTable('assetFolders')
|
|
|
|
})
|
2018-05-28 18:46:55 +00:00
|
|
|
// AUTHENTICATION ----------------------
|
|
|
|
.createTable('authentication', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('key').notNullable().primary()
|
2018-05-28 18:46:55 +00:00
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
2018-08-16 01:57:28 +00:00
|
|
|
table.json('config').notNullable()
|
2018-06-25 06:44:40 +00:00
|
|
|
table.boolean('selfRegistration').notNullable().defaultTo(false)
|
2018-08-16 01:57:28 +00:00
|
|
|
table.json('domainWhitelist').notNullable()
|
|
|
|
table.json('autoEnrollGroups').notNullable()
|
2018-05-28 18:46:55 +00:00
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// COMMENTS ----------------------------
|
|
|
|
.createTable('comments', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.text('content').notNullable()
|
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
2018-05-28 18:46:55 +00:00
|
|
|
// EDITORS -----------------------------
|
|
|
|
.createTable('editors', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('key').notNullable().primary()
|
2018-05-28 18:46:55 +00:00
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
2018-08-16 01:57:28 +00:00
|
|
|
table.json('config').notNullable()
|
2018-05-28 18:46:55 +00:00
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// GROUPS ------------------------------
|
2018-05-19 20:40:07 +00:00
|
|
|
.createTable('groups', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-19 20:40:07 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('name').notNullable()
|
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// LOCALES -----------------------------
|
2018-05-19 20:40:07 +00:00
|
|
|
.createTable('locales', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('code', 2).notNullable().primary()
|
2018-08-16 01:57:28 +00:00
|
|
|
table.json('strings')
|
2018-05-19 20:40:07 +00:00
|
|
|
table.boolean('isRTL').notNullable().defaultTo(false)
|
|
|
|
table.string('name').notNullable()
|
|
|
|
table.string('nativeName').notNullable()
|
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
2018-09-01 19:15:44 +00:00
|
|
|
// LOGGING ----------------------------
|
|
|
|
.createTable('loggers', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('key').notNullable().primary()
|
2018-09-01 19:15:44 +00:00
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
|
|
|
table.string('level').notNullable().defaultTo('warn')
|
|
|
|
table.json('config')
|
|
|
|
})
|
2018-09-29 19:39:09 +00:00
|
|
|
// NAVIGATION ----------------------------
|
|
|
|
.createTable('navigation', table => {
|
|
|
|
table.charset('utf8mb4')
|
|
|
|
table.string('key').notNullable().primary()
|
|
|
|
table.json('config')
|
|
|
|
})
|
2018-07-23 01:13:01 +00:00
|
|
|
// PAGE HISTORY ------------------------
|
|
|
|
.createTable('pageHistory', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-07-23 01:13:01 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('path').notNullable()
|
2018-09-16 00:58:23 +00:00
|
|
|
table.string('hash').notNullable()
|
2018-07-23 01:13:01 +00:00
|
|
|
table.string('title').notNullable()
|
|
|
|
table.string('description')
|
|
|
|
table.boolean('isPrivate').notNullable().defaultTo(false)
|
|
|
|
table.boolean('isPublished').notNullable().defaultTo(false)
|
|
|
|
table.string('publishStartDate')
|
|
|
|
table.string('publishEndDate')
|
|
|
|
table.text('content')
|
2018-07-30 02:23:33 +00:00
|
|
|
table.string('contentType').notNullable()
|
2018-07-23 01:13:01 +00:00
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// PAGES -------------------------------
|
|
|
|
.createTable('pages', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('path').notNullable()
|
2018-09-16 00:58:23 +00:00
|
|
|
table.string('hash').notNullable()
|
2018-05-20 22:50:51 +00:00
|
|
|
table.string('title').notNullable()
|
|
|
|
table.string('description')
|
2018-05-28 18:46:55 +00:00
|
|
|
table.boolean('isPrivate').notNullable().defaultTo(false)
|
2018-05-20 22:50:51 +00:00
|
|
|
table.boolean('isPublished').notNullable().defaultTo(false)
|
2018-08-19 05:22:59 +00:00
|
|
|
table.string('privateNS')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.string('publishStartDate')
|
|
|
|
table.string('publishEndDate')
|
|
|
|
table.text('content')
|
2018-08-09 04:07:15 +00:00
|
|
|
table.text('render')
|
2018-07-30 02:23:33 +00:00
|
|
|
table.string('contentType').notNullable()
|
2018-05-20 22:50:51 +00:00
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
2018-08-27 02:38:08 +00:00
|
|
|
// RENDERERS ---------------------------
|
2018-08-20 05:02:57 +00:00
|
|
|
.createTable('renderers', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('key').notNullable().primary()
|
2018-09-01 19:15:44 +00:00
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
|
|
|
table.json('config')
|
|
|
|
})
|
|
|
|
// SEARCH ------------------------------
|
|
|
|
.createTable('searchEngines', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('key').notNullable().primary()
|
2018-08-20 05:02:57 +00:00
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
|
|
|
table.json('config')
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// SETTINGS ----------------------------
|
2018-05-19 20:40:07 +00:00
|
|
|
.createTable('settings', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('key').notNullable().primary()
|
2018-08-16 01:57:28 +00:00
|
|
|
table.json('value')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
2018-05-28 18:46:55 +00:00
|
|
|
// STORAGE -----------------------------
|
|
|
|
.createTable('storage', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-09-08 19:49:36 +00:00
|
|
|
table.string('key').notNullable().primary()
|
2018-05-28 18:46:55 +00:00
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
2018-08-20 05:02:57 +00:00
|
|
|
table.string('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
|
2018-08-16 01:57:28 +00:00
|
|
|
table.json('config')
|
2018-05-28 18:46:55 +00:00
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// TAGS --------------------------------
|
|
|
|
.createTable('tags', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('tag').notNullable().unique()
|
|
|
|
table.string('title')
|
2018-05-19 20:40:07 +00:00
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// USERS -------------------------------
|
2018-05-19 20:40:07 +00:00
|
|
|
.createTable('users', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-19 20:40:07 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('email').notNullable()
|
|
|
|
table.string('name').notNullable()
|
|
|
|
table.string('providerId')
|
|
|
|
table.string('password')
|
|
|
|
table.boolean('tfaIsActive').notNullable().defaultTo(false)
|
|
|
|
table.string('tfaSecret')
|
|
|
|
table.enum('role', ['admin', 'guest', 'user']).notNullable().defaultTo('guest')
|
2018-05-28 18:46:55 +00:00
|
|
|
table.string('jobTitle').defaultTo('')
|
|
|
|
table.string('location').defaultTo('')
|
|
|
|
table.string('pictureUrl')
|
|
|
|
table.string('timezone').notNullable().defaultTo('America/New_York')
|
2018-05-19 20:40:07 +00:00
|
|
|
table.string('createdAt').notNullable()
|
|
|
|
table.string('updatedAt').notNullable()
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// =====================================
|
|
|
|
// RELATION TABLES
|
|
|
|
// =====================================
|
2018-07-23 01:13:01 +00:00
|
|
|
// PAGE HISTORY TAGS ---------------------------
|
|
|
|
.createTable('pageHistoryTags', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-07-23 01:13:01 +00:00
|
|
|
table.increments('id').primary()
|
|
|
|
table.integer('pageId').unsigned().references('id').inTable('pageHistory').onDelete('CASCADE')
|
|
|
|
table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// PAGE TAGS ---------------------------
|
|
|
|
.createTable('pageTags', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.increments('id').primary()
|
2018-05-21 03:27:06 +00:00
|
|
|
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
|
|
|
|
table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
|
2018-05-20 22:50:51 +00:00
|
|
|
})
|
|
|
|
// USER GROUPS -------------------------
|
2018-05-19 20:40:07 +00:00
|
|
|
.createTable('userGroups', table => {
|
2018-09-16 00:58:23 +00:00
|
|
|
table.charset('utf8mb4')
|
2018-05-19 20:40:07 +00:00
|
|
|
table.increments('id').primary()
|
2018-05-21 03:27:06 +00:00
|
|
|
table.integer('userId').unsigned().references('id').inTable('users').onDelete('CASCADE')
|
|
|
|
table.integer('groupId').unsigned().references('id').inTable('groups').onDelete('CASCADE')
|
2018-05-19 20:40:07 +00:00
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
// =====================================
|
|
|
|
// REFERENCES
|
|
|
|
// =====================================
|
|
|
|
.table('assets', table => {
|
|
|
|
table.integer('folderId').unsigned().references('id').inTable('assetFolders')
|
|
|
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
|
|
|
})
|
|
|
|
.table('comments', table => {
|
|
|
|
table.integer('pageId').unsigned().references('id').inTable('pages')
|
|
|
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
|
|
|
})
|
2018-07-23 01:13:01 +00:00
|
|
|
.table('pageHistory', table => {
|
|
|
|
table.integer('pageId').unsigned().references('id').inTable('pages')
|
|
|
|
table.string('editorKey').references('key').inTable('editors')
|
|
|
|
table.string('localeCode', 2).references('code').inTable('locales')
|
|
|
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
.table('pages', table => {
|
2018-07-22 04:29:39 +00:00
|
|
|
table.string('editorKey').references('key').inTable('editors')
|
|
|
|
table.string('localeCode', 2).references('code').inTable('locales')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
2018-07-23 01:13:01 +00:00
|
|
|
table.integer('creatorId').unsigned().references('id').inTable('users')
|
2018-05-20 22:50:51 +00:00
|
|
|
})
|
|
|
|
.table('users', table => {
|
2018-07-22 04:29:39 +00:00
|
|
|
table.string('providerKey').references('key').inTable('authentication').notNullable().defaultTo('local')
|
|
|
|
table.string('localeCode', 2).references('code').inTable('locales').notNullable().defaultTo('en')
|
2018-05-28 18:46:55 +00:00
|
|
|
table.string('defaultEditor').references('key').inTable('editors').notNullable().defaultTo('markdown')
|
|
|
|
|
2018-07-22 04:29:39 +00:00
|
|
|
table.unique(['providerKey', 'email'])
|
2018-05-20 22:50:51 +00:00
|
|
|
})
|
2018-05-19 20:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.down = knex => {
|
|
|
|
return knex.schema
|
|
|
|
.dropTableIfExists('userGroups')
|
2018-08-27 02:38:08 +00:00
|
|
|
.dropTableIfExists('pageHistoryTags')
|
|
|
|
.dropTableIfExists('pageHistory')
|
2018-05-20 22:50:51 +00:00
|
|
|
.dropTableIfExists('pageTags')
|
|
|
|
.dropTableIfExists('assets')
|
|
|
|
.dropTableIfExists('assetFolders')
|
|
|
|
.dropTableIfExists('comments')
|
2018-08-27 02:38:08 +00:00
|
|
|
.dropTableIfExists('editors')
|
2018-05-19 20:40:07 +00:00
|
|
|
.dropTableIfExists('groups')
|
|
|
|
.dropTableIfExists('locales')
|
2018-09-29 19:39:09 +00:00
|
|
|
.dropTableIfExists('navigation')
|
2018-05-20 22:50:51 +00:00
|
|
|
.dropTableIfExists('pages')
|
2018-08-27 02:38:08 +00:00
|
|
|
.dropTableIfExists('renderers')
|
2018-05-19 20:40:07 +00:00
|
|
|
.dropTableIfExists('settings')
|
2018-08-27 02:38:08 +00:00
|
|
|
.dropTableIfExists('storage')
|
2018-05-20 22:50:51 +00:00
|
|
|
.dropTableIfExists('tags')
|
2018-05-19 20:40:07 +00:00
|
|
|
.dropTableIfExists('users')
|
|
|
|
}
|