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,52 +0,0 @@
exports.up = knex => {
return knex.schema
.renameTable('pageHistory', 'pageHistory_old')
.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()
table.string('action').defaultTo('updated')
table.integer('pageId').unsigned()
table.string('editorKey').references('key').inTable('editors')
table.string('localeCode', 5).references('code').inTable('locales')
table.integer('authorId').unsigned().references('id').inTable('users')
})
.raw(`INSERT INTO pageHistory SELECT id,path,hash,title,description,isPrivate,isPublished,publishStartDate,publishEndDate,content,contentType,createdAt,'updated' AS action,pageId,editorKey,localeCode,authorId FROM pageHistory_old;`)
.dropTable('pageHistory_old')
}
exports.down = knex => {
return knex.schema
.renameTable('pageHistory', 'pageHistory_old')
.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()
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')
})
.raw('INSERT INTO pageHistory SELECT id,path,hash,title,description,isPrivate,isPublished,publishStartDate,publishEndDate,content,contentType,createdAt,NULL as pageId,editorKey,localeCode,authorId FROM pageHistory_old;')
.dropTable('pageHistory_old')
}

View File

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

View File

@@ -1,13 +0,0 @@
exports.up = knex => {
return knex.schema
.createTable('analytics', table => {
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,17 +0,0 @@
exports.up = knex => {
return knex.schema
.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()
})
.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,12 +0,0 @@
exports.up = knex => {
return knex.schema
.createTable('assetData', table => {
table.integer('id').primary()
table.binary('data').notNullable()
})
}
exports.down = knex => {
return knex.schema
.dropTableIfExists('assetData')
}

View File

@@ -1,35 +0,0 @@
exports.up = knex => {
return knex.schema
.dropTable('pageTree')
.createTable('pageTree', table => {
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.integer('parent').unsigned().references('id').inTable('pageTree').onDelete('CASCADE')
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
table.string('localeCode', 5).references('code').inTable('locales')
})
}
exports.down = knex => {
return knex.schema
.dropTable('pageTree')
.createTable('pageTree', table => {
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.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

@@ -3,11 +3,17 @@ exports.up = knex => {
// =====================================
// MODEL TABLES
// =====================================
// ANALYTICS ---------------------------
.createTable('analytics', table => {
table.string('key').notNullable().primary()
table.boolean('isEnabled').notNullable().defaultTo(false)
table.json('config').notNullable()
})
// ASSETS ------------------------------
.createTable('assets', table => {
table.increments('id').primary()
table.string('filename').notNullable()
table.string('basename').notNullable()
table.string('hash').notNullable().defaultTo('')
table.string('ext').notNullable()
table.enum('kind', ['binary', 'image']).notNullable().defaultTo('binary')
table.string('mime').notNullable().defaultTo('application/octet-stream')
@@ -19,6 +25,11 @@ exports.up = knex => {
table.integer('folderId').unsigned().references('id').inTable('assetFolders')
table.integer('authorId').unsigned().references('id').inTable('users')
})
// ASSET DATA --------------------------
.createTable('assetData', table => {
table.integer('id').primary()
table.binary('data').notNullable()
})
// ASSET FOLDERS -----------------------
.createTable('assetFolders', table => {
table.increments('id').primary()
@@ -68,6 +79,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()
})
@@ -97,12 +109,20 @@ exports.up = knex => {
table.text('content')
table.string('contentType').notNullable()
table.string('createdAt').notNullable()
table.string('action').defaultTo('updated')
table.integer('pageId').unsigned().references('id').inTable('pages')
table.integer('pageId').unsigned()
table.string('editorKey').references('key').inTable('editors')
table.string('localeCode', 5).references('code').inTable('locales')
table.integer('authorId').unsigned().references('id').inTable('users')
})
// 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()
})
// PAGES -------------------------------
.createTable('pages', table => {
table.increments('id').primary()
@@ -129,7 +149,7 @@ exports.up = knex => {
})
// PAGE TREE ---------------------------
.createTable('pageTree', table => {
table.increments('id').primary()
table.integer('id').primary()
table.string('path').notNullable()
table.integer('depth').unsigned().notNullable()
table.string('title').notNullable()
@@ -137,8 +157,8 @@ exports.up = knex => {
table.boolean('isFolder').notNullable().defaultTo(false)
table.string('privateNS')
table.integer('parent').unsigned().references('id').inTable('pageTree')
table.integer('pageId').unsigned().references('id').inTable('pages')
table.integer('parent').unsigned().references('id').inTable('pageTree').onDelete('CASCADE')
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
table.string('localeCode', 5).references('code').inTable('locales')
})
// RENDERERS ---------------------------
@@ -165,6 +185,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 => {
@@ -200,6 +222,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()
@@ -234,26 +257,12 @@ exports.up = knex => {
.table('users', table => {
table.unique(['providerKey', 'email'])
})
// =====================================
// INDEXES
// =====================================
.table('pageLinks', table => {
table.index(['path', 'localeCode'])
})
}
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 => { }