mirror of https://github.com/requarks/wiki
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.
293 lines
12 KiB
293 lines
12 KiB
6 years ago
|
/* global WIKI */
|
||
|
|
||
7 years ago
|
exports.up = knex => {
|
||
6 years ago
|
const dbCompat = {
|
||
|
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`)
|
||
|
}
|
||
7 years ago
|
return knex.schema
|
||
7 years ago
|
// =====================================
|
||
|
// MODEL TABLES
|
||
|
// =====================================
|
||
|
// ASSETS ------------------------------
|
||
|
.createTable('assets', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
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')
|
||
6 years ago
|
table.json('metadata')
|
||
7 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
|
// ASSET FOLDERS -----------------------
|
||
|
.createTable('assetFolders', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
|
table.string('name').notNullable()
|
||
|
table.string('slug').notNullable()
|
||
|
table.integer('parentId').unsigned().references('id').inTable('assetFolders')
|
||
|
})
|
||
7 years ago
|
// AUTHENTICATION ----------------------
|
||
|
.createTable('authentication', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
7 years ago
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
6 years ago
|
table.json('config').notNullable()
|
||
7 years ago
|
table.boolean('selfRegistration').notNullable().defaultTo(false)
|
||
6 years ago
|
table.json('domainWhitelist').notNullable()
|
||
|
table.json('autoEnrollGroups').notNullable()
|
||
7 years ago
|
})
|
||
7 years ago
|
// COMMENTS ----------------------------
|
||
|
.createTable('comments', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
|
table.text('content').notNullable()
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
7 years ago
|
// EDITORS -----------------------------
|
||
|
.createTable('editors', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
7 years ago
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
6 years ago
|
table.json('config').notNullable()
|
||
7 years ago
|
})
|
||
7 years ago
|
// GROUPS ------------------------------
|
||
7 years ago
|
.createTable('groups', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
|
table.string('name').notNullable()
|
||
6 years ago
|
table.json('permissions').notNullable()
|
||
6 years ago
|
table.json('pageRules').notNullable()
|
||
6 years ago
|
table.boolean('isSystem').notNullable().defaultTo(false)
|
||
7 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
7 years ago
|
// LOCALES -----------------------------
|
||
7 years ago
|
.createTable('locales', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
5 years ago
|
table.string('code', 2).notNullable().primary()
|
||
6 years ago
|
table.json('strings')
|
||
7 years ago
|
table.boolean('isRTL').notNullable().defaultTo(false)
|
||
|
table.string('name').notNullable()
|
||
|
table.string('nativeName').notNullable()
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
6 years ago
|
// LOGGING ----------------------------
|
||
|
.createTable('loggers', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
6 years ago
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.string('level').notNullable().defaultTo('warn')
|
||
|
table.json('config')
|
||
|
})
|
||
6 years ago
|
// NAVIGATION ----------------------------
|
||
|
.createTable('navigation', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
|
table.json('config')
|
||
|
})
|
||
7 years ago
|
// PAGE HISTORY ------------------------
|
||
|
.createTable('pageHistory', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
|
table.string('path').notNullable()
|
||
6 years ago
|
table.string('hash').notNullable()
|
||
7 years ago
|
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')
|
||
7 years ago
|
table.string('contentType').notNullable()
|
||
7 years ago
|
table.string('createdAt').notNullable()
|
||
|
})
|
||
7 years ago
|
// PAGES -------------------------------
|
||
|
.createTable('pages', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
|
table.string('path').notNullable()
|
||
6 years ago
|
table.string('hash').notNullable()
|
||
7 years ago
|
table.string('title').notNullable()
|
||
|
table.string('description')
|
||
7 years ago
|
table.boolean('isPrivate').notNullable().defaultTo(false)
|
||
7 years ago
|
table.boolean('isPublished').notNullable().defaultTo(false)
|
||
6 years ago
|
table.string('privateNS')
|
||
7 years ago
|
table.string('publishStartDate')
|
||
|
table.string('publishEndDate')
|
||
|
table.text('content')
|
||
6 years ago
|
table.text('render')
|
||
6 years ago
|
table.json('toc')
|
||
7 years ago
|
table.string('contentType').notNullable()
|
||
7 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
6 years ago
|
// PAGE TREE ---------------------------
|
||
|
.createTable('pageTree', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.increments('id').primary()
|
||
|
table.string('path').notNullable()
|
||
|
table.integer('depth').unsigned().notNullable()
|
||
|
table.string('title').notNullable()
|
||
|
table.boolean('isPrivate').notNullable().defaultTo(false)
|
||
|
table.boolean('isFolder').notNullable().defaultTo(false)
|
||
|
table.string('privateNS')
|
||
|
})
|
||
6 years ago
|
// RENDERERS ---------------------------
|
||
6 years ago
|
.createTable('renderers', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
6 years ago
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.json('config')
|
||
|
})
|
||
|
// SEARCH ------------------------------
|
||
|
.createTable('searchEngines', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
6 years ago
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.json('config')
|
||
|
})
|
||
7 years ago
|
// SETTINGS ----------------------------
|
||
7 years ago
|
.createTable('settings', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
6 years ago
|
table.json('value')
|
||
7 years ago
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
7 years ago
|
// STORAGE -----------------------------
|
||
|
.createTable('storage', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.string('key').notNullable().primary()
|
||
7 years ago
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
6 years ago
|
table.string('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
|
||
6 years ago
|
table.json('config')
|
||
7 years ago
|
})
|
||
7 years ago
|
// TAGS --------------------------------
|
||
|
.createTable('tags', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
|
table.string('tag').notNullable().unique()
|
||
|
table.string('title')
|
||
7 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
6 years ago
|
// USER KEYS ---------------------------
|
||
|
.createTable('userKeys', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
6 years ago
|
table.increments('id').primary()
|
||
|
table.string('kind').notNullable()
|
||
6 years ago
|
table.string('token').notNullable()
|
||
6 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('validUntil').notNullable()
|
||
|
})
|
||
7 years ago
|
// USERS -------------------------------
|
||
7 years ago
|
.createTable('users', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
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')
|
||
7 years ago
|
table.string('jobTitle').defaultTo('')
|
||
|
table.string('location').defaultTo('')
|
||
|
table.string('pictureUrl')
|
||
|
table.string('timezone').notNullable().defaultTo('America/New_York')
|
||
6 years ago
|
table.boolean('isSystem').notNullable().defaultTo(false)
|
||
6 years ago
|
table.boolean('isActive').notNullable().defaultTo(false)
|
||
|
table.boolean('isVerified').notNullable().defaultTo(false)
|
||
7 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
7 years ago
|
// =====================================
|
||
|
// RELATION TABLES
|
||
|
// =====================================
|
||
7 years ago
|
// PAGE HISTORY TAGS ---------------------------
|
||
|
.createTable('pageHistoryTags', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pageHistory').onDelete('CASCADE')
|
||
|
table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
|
||
|
})
|
||
7 years ago
|
// PAGE TAGS ---------------------------
|
||
|
.createTable('pageTags', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
7 years ago
|
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
|
||
|
table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
|
||
7 years ago
|
})
|
||
|
// USER GROUPS -------------------------
|
||
7 years ago
|
.createTable('userGroups', table => {
|
||
6 years ago
|
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||
7 years ago
|
table.increments('id').primary()
|
||
7 years ago
|
table.integer('userId').unsigned().references('id').inTable('users').onDelete('CASCADE')
|
||
|
table.integer('groupId').unsigned().references('id').inTable('groups').onDelete('CASCADE')
|
||
7 years ago
|
})
|
||
7 years ago
|
// =====================================
|
||
|
// 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')
|
||
|
})
|
||
7 years ago
|
.table('pageHistory', table => {
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pages')
|
||
|
table.string('editorKey').references('key').inTable('editors')
|
||
5 years ago
|
table.string('localeCode', 2).references('code').inTable('locales')
|
||
7 years ago
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
||
|
})
|
||
7 years ago
|
.table('pages', table => {
|
||
7 years ago
|
table.string('editorKey').references('key').inTable('editors')
|
||
5 years ago
|
table.string('localeCode', 2).references('code').inTable('locales')
|
||
7 years ago
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
||
7 years ago
|
table.integer('creatorId').unsigned().references('id').inTable('users')
|
||
7 years ago
|
})
|
||
6 years ago
|
.table('pageTree', table => {
|
||
|
table.integer('parent').unsigned().references('id').inTable('pageTree')
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pages')
|
||
5 years ago
|
table.string('localeCode', 2).references('code').inTable('locales')
|
||
6 years ago
|
})
|
||
6 years ago
|
.table('userKeys', table => {
|
||
|
table.integer('userId').unsigned().references('id').inTable('users')
|
||
|
})
|
||
7 years ago
|
.table('users', table => {
|
||
7 years ago
|
table.string('providerKey').references('key').inTable('authentication').notNullable().defaultTo('local')
|
||
5 years ago
|
table.string('localeCode', 2).references('code').inTable('locales').notNullable().defaultTo('en')
|
||
7 years ago
|
table.string('defaultEditor').references('key').inTable('editors').notNullable().defaultTo('markdown')
|
||
|
|
||
7 years ago
|
table.unique(['providerKey', 'email'])
|
||
7 years ago
|
})
|
||
7 years ago
|
}
|
||
|
|
||
|
exports.down = knex => {
|
||
|
return knex.schema
|
||
|
.dropTableIfExists('userGroups')
|
||
6 years ago
|
.dropTableIfExists('pageHistoryTags')
|
||
|
.dropTableIfExists('pageHistory')
|
||
7 years ago
|
.dropTableIfExists('pageTags')
|
||
|
.dropTableIfExists('assets')
|
||
|
.dropTableIfExists('assetFolders')
|
||
|
.dropTableIfExists('comments')
|
||
6 years ago
|
.dropTableIfExists('editors')
|
||
7 years ago
|
.dropTableIfExists('groups')
|
||
|
.dropTableIfExists('locales')
|
||
6 years ago
|
.dropTableIfExists('navigation')
|
||
7 years ago
|
.dropTableIfExists('pages')
|
||
6 years ago
|
.dropTableIfExists('renderers')
|
||
7 years ago
|
.dropTableIfExists('settings')
|
||
6 years ago
|
.dropTableIfExists('storage')
|
||
7 years ago
|
.dropTableIfExists('tags')
|
||
6 years ago
|
.dropTableIfExists('userKeys')
|
||
7 years ago
|
.dropTableIfExists('users')
|
||
|
}
|