wikijs-fork/server/db/migrations/2.0.0.js

205 lines
8.6 KiB
JavaScript
Raw Normal View History

exports.up = knex => {
return knex.schema
2018-05-20 22:50:51 +00:00
// =====================================
// MODEL TABLES
// =====================================
// ASSETS ------------------------------
.createTable('assets', table => {
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')
table.jsonb('metadata')
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
// 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')
})
2018-05-28 18:46:55 +00:00
// AUTHENTICATION ----------------------
.createTable('authentication', table => {
table.increments('id').primary()
table.string('key').notNullable().unique()
table.boolean('isEnabled').notNullable().defaultTo(false)
table.jsonb('config').notNullable()
table.boolean('selfRegistration').notNullable().defaultTo(false)
table.jsonb('domainWhitelist').notNullable()
table.jsonb('autoEnrollGroups').notNullable()
2018-05-28 18:46:55 +00:00
})
2018-05-20 22:50:51 +00:00
// COMMENTS ----------------------------
.createTable('comments', table => {
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 => {
table.increments('id').primary()
table.string('key').notNullable().unique()
table.boolean('isEnabled').notNullable().defaultTo(false)
table.jsonb('config').notNullable()
2018-05-28 18:46:55 +00:00
})
2018-05-20 22:50:51 +00:00
// GROUPS ------------------------------
.createTable('groups', table => {
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 -----------------------------
.createTable('locales', table => {
table.increments('id').primary()
table.string('code', 2).notNullable().unique()
2018-05-20 22:50:51 +00:00
table.jsonb('strings')
table.boolean('isRTL').notNullable().defaultTo(false)
table.string('name').notNullable()
table.string('nativeName').notNullable()
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
// PAGE HISTORY ------------------------
.createTable('pageHistory', table => {
table.increments('id').primary()
table.string('path').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()
})
2018-05-20 22:50:51 +00:00
// PAGES -------------------------------
.createTable('pages', table => {
table.increments('id').primary()
table.string('path').notNullable()
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)
table.string('publishStartDate')
table.string('publishEndDate')
table.text('content')
table.text('render')
table.string('contentType').notNullable()
2018-05-20 22:50:51 +00:00
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
// SETTINGS ----------------------------
.createTable('settings', table => {
table.increments('id').primary()
table.string('key').notNullable().unique()
2018-05-20 22:50:51 +00:00
table.jsonb('value')
table.string('updatedAt').notNullable()
})
2018-05-28 18:46:55 +00:00
// STORAGE -----------------------------
.createTable('storage', table => {
table.increments('id').primary()
table.string('key').notNullable().unique()
table.boolean('isEnabled').notNullable().defaultTo(false)
2018-06-26 02:04:47 +00:00
table.enum('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
2018-05-28 18:46:55 +00:00
table.jsonb('config')
})
2018-05-20 22:50:51 +00:00
// TAGS --------------------------------
.createTable('tags', table => {
table.increments('id').primary()
table.string('tag').notNullable().unique()
table.string('title')
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
2018-05-20 22:50:51 +00:00
// 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.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')
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
2018-05-20 22:50:51 +00:00
// =====================================
// 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')
})
2018-05-20 22:50:51 +00:00
// PAGE TAGS ---------------------------
.createTable('pageTags', table => {
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 -------------------------
.createTable('userGroups', table => {
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-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')
})
.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')
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
})
}
exports.down = knex => {
return knex.schema
.dropTableIfExists('userGroups')
2018-05-20 22:50:51 +00:00
.dropTableIfExists('pageTags')
.dropTableIfExists('assets')
.dropTableIfExists('assetFolders')
.dropTableIfExists('comments')
.dropTableIfExists('groups')
.dropTableIfExists('locales')
2018-05-20 22:50:51 +00:00
.dropTableIfExists('pages')
.dropTableIfExists('settings')
2018-05-20 22:50:51 +00:00
.dropTableIfExists('tags')
.dropTableIfExists('users')
}