fix: stable db migration + beta migration to stable

This commit is contained in:
NGPixel
2019-11-03 21:59:58 -05:00
parent e9afcfcd94
commit 8eddc4799e
27 changed files with 750 additions and 15 deletions

View File

@@ -1,15 +0,0 @@
exports.up = knex => {
return knex.schema
.table('pageHistory', table => {
table.string('action').defaultTo('updated')
table.dropForeign('pageId')
})
}
exports.down = knex => {
return knex.schema
.table('pageHistory', table => {
table.dropColumn('action')
table.integer('pageId').unsigned().references('id').inTable('pages')
})
}

View File

@@ -1,15 +0,0 @@
exports.up = knex => {
return knex.schema
.table('assets', table => {
table.dropColumn('basename')
table.string('hash').notNullable()
})
}
exports.down = knex => {
return knex.schema
.table('assets', table => {
table.dropColumn('hash')
table.string('basename').notNullable()
})
}

View File

@@ -1,23 +0,0 @@
/* global WIKI */
exports.up = knex => {
const dbCompat = {
blobLength: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`)
}
return knex.schema
.table('assetData', table => {
if (dbCompat.blobLength) {
table.dropColumn('data')
}
})
.table('assetData', table => {
if (dbCompat.blobLength) {
table.specificType('data', 'LONGBLOB').notNullable()
}
})
}
exports.down = knex => {
return knex.schema
.table('assetData', table => {})
}

View File

@@ -1,19 +0,0 @@
/* global WIKI */
exports.up = knex => {
const dbCompat = {
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`)
}
return knex.schema
.createTable('analytics', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.string('key').notNullable().primary()
table.boolean('isEnabled').notNullable().defaultTo(false)
table.json('config').notNullable()
})
}
exports.down = knex => {
return knex.schema
.dropTableIfExists('analytics')
}

View File

@@ -1,13 +0,0 @@
exports.up = knex => {
return knex.schema
.table('locales', table => {
table.integer('availability').notNullable().defaultTo(0)
})
}
exports.down = knex => {
return knex.schema
.table('locales', table => {
table.dropColumn('availability')
})
}

View File

@@ -1,13 +0,0 @@
exports.up = knex => {
return knex.schema
.table('users', table => {
table.boolean('mustChangePwd').notNullable().defaultTo(false)
})
}
exports.down = knex => {
return knex.schema
.table('users', table => {
table.dropColumn('mustChangePwd')
})
}

View File

@@ -1,23 +0,0 @@
/* global WIKI */
exports.up = knex => {
const dbCompat = {
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`)
}
return knex.schema
.createTable('pageLinks', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.increments('id').primary()
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
table.string('path').notNullable()
table.string('localeCode', 5).notNullable()
})
.table('pageLinks', table => {
table.index(['path', 'localeCode'])
})
}
exports.down = knex => {
return knex.schema
.dropTableIfExists('pageLinks')
}

View File

@@ -1,15 +0,0 @@
exports.up = knex => {
return knex.schema
.table('storage', table => {
table.string('syncInterval')
table.json('state')
})
}
exports.down = knex => {
return knex.schema
.table('storage', table => {
table.dropColumn('syncInterval')
table.dropColumn('state')
})
}

View File

@@ -1,18 +0,0 @@
/* global WIKI */
exports.up = knex => {
const dbCompat = {
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`)
}
return knex.schema
.createTable('assetData', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.integer('id').primary()
table.binary('data').notNullable()
})
}
exports.down = knex => {
return knex.schema
.dropTableIfExists('assetData')
}

View File

@@ -1,53 +0,0 @@
/* global WIKI */
exports.up = knex => {
const dbCompat = {
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`),
selfCascadeDelete: WIKI.config.db.type !== 'mssql'
}
return knex.schema
.dropTable('pageTree')
.createTable('pageTree', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.integer('id').unsigned().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')
})
.table('pageTree', table => {
if (dbCompat.selfCascadeDelete) {
table.integer('parent').unsigned().references('id').inTable('pageTree').onDelete('CASCADE')
} else {
table.integer('parent').unsigned()
}
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
table.string('localeCode', 5).references('code').inTable('locales')
})
}
exports.down = knex => {
const dbCompat = {
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`),
selfCascadeDelete: WIKI.config.db.type !== 'mssql'
}
return knex.schema
.dropTable('pageTree')
.createTable('pageTree', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.integer('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')
})
.table('pageTree', table => {
table.integer('parent').unsigned().references('id').inTable('pageTree')
table.integer('pageId').unsigned().references('id').inTable('pages')
table.string('localeCode', 5).references('code').inTable('locales')
})
}

View File

@@ -2,18 +2,27 @@
exports.up = knex => {
const dbCompat = {
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`)
blobLength: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`),
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`),
selfCascadeDelete: WIKI.config.db.type !== 'mssql'
}
return knex.schema
// =====================================
// MODEL TABLES
// =====================================
// ANALYTICS ---------------------------
.createTable('analytics', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.string('key').notNullable().primary()
table.boolean('isEnabled').notNullable().defaultTo(false)
table.json('config').notNullable()
})
// ASSETS ------------------------------
.createTable('assets', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.increments('id').primary()
table.string('filename').notNullable()
table.string('basename').notNullable()
table.string('hash').notNullable()
table.string('ext').notNullable()
table.enum('kind', ['binary', 'image']).notNullable().defaultTo('binary')
table.string('mime').notNullable().defaultTo('application/octet-stream')
@@ -22,6 +31,16 @@ exports.up = knex => {
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
// ASSET DATA --------------------------
.createTable('assetData', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.integer('id').primary()
if (dbCompat.blobLength) {
table.specificType('data', 'LONGBLOB').notNullable()
} else {
table.binary('data').notNullable()
}
})
// ASSET FOLDERS -----------------------
.createTable('assetFolders', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
@@ -74,6 +93,7 @@ exports.up = knex => {
table.boolean('isRTL').notNullable().defaultTo(false)
table.string('name').notNullable()
table.string('nativeName').notNullable()
table.integer('availability').notNullable().defaultTo(0)
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
@@ -103,10 +123,19 @@ exports.up = knex => {
table.boolean('isPublished').notNullable().defaultTo(false)
table.string('publishStartDate')
table.string('publishEndDate')
table.string('action').defaultTo('updated')
table.integer('pageId').unsigned()
table.text('content')
table.string('contentType').notNullable()
table.string('createdAt').notNullable()
})
// PAGE LINKS --------------------------
.createTable('pageLinks', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.increments('id').primary()
table.string('path').notNullable()
table.string('localeCode', 5).notNullable()
})
// PAGES -------------------------------
.createTable('pages', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
@@ -120,8 +149,22 @@ exports.up = knex => {
table.string('privateNS')
table.string('publishStartDate')
table.string('publishEndDate')
table.text('content')
table.text('render')
switch (WIKI.config.db.type) {
case 'postgres':
case 'sqlite':
table.text('content')
table.text('render')
break
case 'mariadb':
case 'mysql':
table.specificType('content', 'LONGTEXT')
table.specificType('render', 'LONGTEXT')
break
case 'mssql':
table.specificType('content', 'VARCHAR(max)')
table.specificType('render', 'VARCHAR(max)')
break
}
table.json('toc')
table.string('contentType').notNullable()
table.string('createdAt').notNullable()
@@ -130,7 +173,7 @@ exports.up = knex => {
// PAGE TREE ---------------------------
.createTable('pageTree', table => {
if (dbCompat.charset) { table.charset('utf8mb4') }
table.increments('id').primary()
table.integer('id').unsigned().primary()
table.string('path').notNullable()
table.integer('depth').unsigned().notNullable()
table.string('title').notNullable()
@@ -166,6 +209,8 @@ exports.up = knex => {
table.boolean('isEnabled').notNullable().defaultTo(false)
table.string('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
table.json('config')
table.string('syncInterval')
table.json('state')
})
// TAGS --------------------------------
.createTable('tags', table => {
@@ -202,6 +247,7 @@ exports.up = knex => {
table.boolean('isSystem').notNullable().defaultTo(false)
table.boolean('isActive').notNullable().defaultTo(false)
table.boolean('isVerified').notNullable().defaultTo(false)
table.boolean('mustChangePwd').notNullable().defaultTo(false)
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
@@ -241,11 +287,14 @@ exports.up = knex => {
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', 5).references('code').inTable('locales')
table.integer('authorId').unsigned().references('id').inTable('users')
})
.table('pageLinks', table => {
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
table.index(['path', 'localeCode'])
})
.table('pages', table => {
table.string('editorKey').references('key').inTable('editors')
table.string('localeCode', 5).references('code').inTable('locales')
@@ -253,8 +302,12 @@ exports.up = knex => {
table.integer('creatorId').unsigned().references('id').inTable('users')
})
.table('pageTree', table => {
table.integer('parent').unsigned().references('id').inTable('pageTree')
table.integer('pageId').unsigned().references('id').inTable('pages')
if (dbCompat.selfCascadeDelete) {
table.integer('parent').unsigned().references('id').inTable('pageTree').onDelete('CASCADE')
} else {
table.integer('parent').unsigned()
}
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
table.string('localeCode', 5).references('code').inTable('locales')
})
.table('userKeys', table => {
@@ -269,24 +322,4 @@ exports.up = knex => {
})
}
exports.down = knex => {
return knex.schema
.dropTableIfExists('userGroups')
.dropTableIfExists('pageHistoryTags')
.dropTableIfExists('pageHistory')
.dropTableIfExists('pageTags')
.dropTableIfExists('assets')
.dropTableIfExists('assetFolders')
.dropTableIfExists('comments')
.dropTableIfExists('editors')
.dropTableIfExists('groups')
.dropTableIfExists('locales')
.dropTableIfExists('navigation')
.dropTableIfExists('pages')
.dropTableIfExists('renderers')
.dropTableIfExists('settings')
.dropTableIfExists('storage')
.dropTableIfExists('tags')
.dropTableIfExists('userKeys')
.dropTableIfExists('users')
}
exports.down = knex => { }