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 => {
|
|
|
|
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()
|
2018-06-25 06:44:40 +00:00
|
|
|
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)
|
2018-08-11 01:00:20 +00:00
|
|
|
table.jsonb('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 => {
|
|
|
|
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 => {
|
|
|
|
table.increments('id').primary()
|
|
|
|
table.string('code', 2).notNullable().unique()
|
2018-05-20 22:50:51 +00:00
|
|
|
table.jsonb('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-07-23 01:13:01 +00:00
|
|
|
// 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')
|
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 => {
|
|
|
|
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')
|
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()
|
|
|
|
})
|
|
|
|
// SETTINGS ----------------------------
|
2018-05-19 20:40:07 +00:00
|
|
|
.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')
|
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 => {
|
|
|
|
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 => {
|
|
|
|
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 -------------------------
|
2018-05-19 20:40:07 +00:00
|
|
|
.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-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-05-20 22:50:51 +00:00
|
|
|
.dropTableIfExists('pageTags')
|
|
|
|
.dropTableIfExists('assets')
|
|
|
|
.dropTableIfExists('assetFolders')
|
|
|
|
.dropTableIfExists('comments')
|
2018-05-19 20:40:07 +00:00
|
|
|
.dropTableIfExists('groups')
|
|
|
|
.dropTableIfExists('locales')
|
2018-05-20 22:50:51 +00:00
|
|
|
.dropTableIfExists('pages')
|
2018-05-19 20:40:07 +00:00
|
|
|
.dropTableIfExists('settings')
|
2018-05-20 22:50:51 +00:00
|
|
|
.dropTableIfExists('tags')
|
2018-05-19 20:40:07 +00:00
|
|
|
.dropTableIfExists('users')
|
|
|
|
}
|