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.
269 lines
11 KiB
269 lines
11 KiB
6 years ago
|
exports.up = knex => {
|
||
|
return knex.schema
|
||
|
// =====================================
|
||
|
// MODEL TABLES
|
||
|
// =====================================
|
||
5 years ago
|
// ANALYTICS ---------------------------
|
||
|
.createTable('analytics', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.json('config').notNullable()
|
||
|
})
|
||
6 years ago
|
// ASSETS ------------------------------
|
||
|
.createTable('assets', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.string('filename').notNullable()
|
||
5 years ago
|
table.string('hash').notNullable().defaultTo('')
|
||
6 years ago
|
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')
|
||
|
table.json('metadata')
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
|
||
|
table.integer('folderId').unsigned().references('id').inTable('assetFolders')
|
||
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
||
|
})
|
||
5 years ago
|
// ASSET DATA --------------------------
|
||
|
.createTable('assetData', table => {
|
||
|
table.integer('id').primary()
|
||
|
table.binary('data').notNullable()
|
||
|
})
|
||
6 years ago
|
// ASSET FOLDERS -----------------------
|
||
|
.createTable('assetFolders', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.string('name').notNullable()
|
||
|
table.string('slug').notNullable()
|
||
|
table.integer('parentId').unsigned().references('id').inTable('assetFolders')
|
||
|
})
|
||
|
// AUTHENTICATION ----------------------
|
||
|
.createTable('authentication', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.json('config').notNullable()
|
||
|
table.boolean('selfRegistration').notNullable().defaultTo(false)
|
||
|
table.json('domainWhitelist').notNullable()
|
||
|
table.json('autoEnrollGroups').notNullable()
|
||
|
})
|
||
|
// COMMENTS ----------------------------
|
||
|
.createTable('comments', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.text('content').notNullable()
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pages')
|
||
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
||
|
})
|
||
|
// EDITORS -----------------------------
|
||
|
.createTable('editors', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.json('config').notNullable()
|
||
|
})
|
||
|
// GROUPS ------------------------------
|
||
|
.createTable('groups', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.string('name').notNullable()
|
||
|
table.json('permissions').notNullable()
|
||
|
table.json('pageRules').notNullable()
|
||
|
table.boolean('isSystem').notNullable().defaultTo(false)
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
|
// LOCALES -----------------------------
|
||
|
.createTable('locales', table => {
|
||
5 years ago
|
table.string('code', 5).notNullable().primary()
|
||
6 years ago
|
table.json('strings')
|
||
|
table.boolean('isRTL').notNullable().defaultTo(false)
|
||
|
table.string('name').notNullable()
|
||
|
table.string('nativeName').notNullable()
|
||
5 years ago
|
table.integer('availability').notNullable().defaultTo(0)
|
||
6 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
|
// LOGGING ----------------------------
|
||
|
.createTable('loggers', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.string('level').notNullable().defaultTo('warn')
|
||
|
table.json('config')
|
||
|
})
|
||
|
// NAVIGATION ----------------------------
|
||
|
.createTable('navigation', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.json('config')
|
||
|
})
|
||
|
// PAGE HISTORY ------------------------
|
||
|
.createTable('pageHistory', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.string('path').notNullable()
|
||
|
table.string('hash').notNullable()
|
||
|
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')
|
||
|
table.string('contentType').notNullable()
|
||
|
table.string('createdAt').notNullable()
|
||
5 years ago
|
table.string('action').defaultTo('updated')
|
||
6 years ago
|
|
||
5 years ago
|
table.integer('pageId').unsigned()
|
||
6 years ago
|
table.string('editorKey').references('key').inTable('editors')
|
||
5 years ago
|
table.string('localeCode', 5).references('code').inTable('locales')
|
||
6 years ago
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
||
|
})
|
||
5 years ago
|
// PAGE LINKS --------------------------
|
||
|
.createTable('pageLinks', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
|
||
|
table.string('path').notNullable()
|
||
|
table.string('localeCode', 5).notNullable()
|
||
|
})
|
||
6 years ago
|
// PAGES -------------------------------
|
||
|
.createTable('pages', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.string('path').notNullable()
|
||
|
table.string('hash').notNullable()
|
||
|
table.string('title').notNullable()
|
||
|
table.string('description')
|
||
|
table.boolean('isPrivate').notNullable().defaultTo(false)
|
||
|
table.boolean('isPublished').notNullable().defaultTo(false)
|
||
|
table.string('privateNS')
|
||
|
table.string('publishStartDate')
|
||
|
table.string('publishEndDate')
|
||
|
table.text('content')
|
||
|
table.text('render')
|
||
|
table.json('toc')
|
||
|
table.string('contentType').notNullable()
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
|
||
|
table.string('editorKey').references('key').inTable('editors')
|
||
5 years ago
|
table.string('localeCode', 5).references('code').inTable('locales')
|
||
6 years ago
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
||
|
table.integer('creatorId').unsigned().references('id').inTable('users')
|
||
|
})
|
||
|
// PAGE TREE ---------------------------
|
||
|
.createTable('pageTree', table => {
|
||
5 years ago
|
table.integer('id').primary()
|
||
6 years ago
|
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')
|
||
|
|
||
5 years ago
|
table.integer('parent').unsigned().references('id').inTable('pageTree').onDelete('CASCADE')
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
|
||
5 years ago
|
table.string('localeCode', 5).references('code').inTable('locales')
|
||
6 years ago
|
})
|
||
|
// RENDERERS ---------------------------
|
||
|
.createTable('renderers', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.json('config')
|
||
|
})
|
||
|
// SEARCH ------------------------------
|
||
|
.createTable('searchEngines', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.json('config')
|
||
|
})
|
||
|
// SETTINGS ----------------------------
|
||
|
.createTable('settings', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.json('value')
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
|
// STORAGE -----------------------------
|
||
|
.createTable('storage', table => {
|
||
|
table.string('key').notNullable().primary()
|
||
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||
|
table.string('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
|
||
|
table.json('config')
|
||
5 years ago
|
table.string('syncInterval')
|
||
|
table.json('state')
|
||
6 years ago
|
})
|
||
|
// TAGS --------------------------------
|
||
|
.createTable('tags', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.string('tag').notNullable().unique()
|
||
|
table.string('title')
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
})
|
||
|
// USER KEYS ---------------------------
|
||
|
.createTable('userKeys', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.string('kind').notNullable()
|
||
|
table.string('token').notNullable()
|
||
|
table.string('createdAt').notNullable()
|
||
|
table.string('validUntil').notNullable()
|
||
|
|
||
|
table.integer('userId').unsigned().references('id').inTable('users')
|
||
|
})
|
||
|
// USERS -------------------------------
|
||
|
.createTable('users', table => {
|
||
|
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.string('jobTitle').defaultTo('')
|
||
|
table.string('location').defaultTo('')
|
||
|
table.string('pictureUrl')
|
||
|
table.string('timezone').notNullable().defaultTo('America/New_York')
|
||
|
table.boolean('isSystem').notNullable().defaultTo(false)
|
||
|
table.boolean('isActive').notNullable().defaultTo(false)
|
||
|
table.boolean('isVerified').notNullable().defaultTo(false)
|
||
5 years ago
|
table.boolean('mustChangePwd').notNullable().defaultTo(false)
|
||
6 years ago
|
table.string('createdAt').notNullable()
|
||
|
table.string('updatedAt').notNullable()
|
||
|
|
||
|
table.string('providerKey').references('key').inTable('authentication').notNullable().defaultTo('local')
|
||
5 years ago
|
table.string('localeCode', 5).references('code').inTable('locales').notNullable().defaultTo('en')
|
||
6 years ago
|
table.string('defaultEditor').references('key').inTable('editors').notNullable().defaultTo('markdown')
|
||
|
})
|
||
|
// =====================================
|
||
|
// RELATION TABLES
|
||
|
// =====================================
|
||
|
// PAGE HISTORY TAGS ---------------------------
|
||
|
.createTable('pageHistoryTags', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pageHistory').onDelete('CASCADE')
|
||
|
table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
|
||
|
})
|
||
|
// PAGE TAGS ---------------------------
|
||
|
.createTable('pageTags', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
|
||
|
table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
|
||
|
})
|
||
|
// USER GROUPS -------------------------
|
||
|
.createTable('userGroups', table => {
|
||
|
table.increments('id').primary()
|
||
|
table.integer('userId').unsigned().references('id').inTable('users').onDelete('CASCADE')
|
||
|
table.integer('groupId').unsigned().references('id').inTable('groups').onDelete('CASCADE')
|
||
|
})
|
||
|
// =====================================
|
||
|
// REFERENCES
|
||
|
// =====================================
|
||
|
.table('users', table => {
|
||
|
table.unique(['providerKey', 'email'])
|
||
|
})
|
||
5 years ago
|
// =====================================
|
||
|
// INDEXES
|
||
|
// =====================================
|
||
|
.table('pageLinks', table => {
|
||
|
table.index(['path', 'localeCode'])
|
||
|
})
|
||
6 years ago
|
}
|
||
|
|
||
5 years ago
|
exports.down = knex => { }
|