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.string('title').notNullable()
|
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
|
|
|
table.boolean('useForm').notNullable().defaultTo(false)
|
|
|
|
table.jsonb('config').notNullable()
|
|
|
|
})
|
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.string('title').notNullable()
|
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
|
|
|
table.jsonb('config')
|
|
|
|
})
|
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-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.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.string('title').notNullable()
|
|
|
|
table.boolean('isEnabled').notNullable().defaultTo(false)
|
|
|
|
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
|
|
|
|
// =====================================
|
|
|
|
// 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')
|
|
|
|
})
|
|
|
|
.table('pages', table => {
|
2018-05-28 18:46:55 +00:00
|
|
|
table.string('editor').references('key').inTable('editors')
|
2018-05-20 22:50:51 +00:00
|
|
|
table.string('locale', 2).references('code').inTable('locales')
|
|
|
|
table.integer('authorId').unsigned().references('id').inTable('users')
|
|
|
|
})
|
|
|
|
.table('users', table => {
|
2018-05-28 18:46:55 +00:00
|
|
|
table.string('provider').references('key').inTable('authentication').notNullable().defaultTo('local')
|
|
|
|
table.string('locale', 2).references('code').inTable('locales').notNullable().defaultTo('en')
|
|
|
|
table.string('defaultEditor').references('key').inTable('editors').notNullable().defaultTo('markdown')
|
|
|
|
|
|
|
|
table.unique(['provider', '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')
|
|
|
|
}
|