Commit 3743777b authored by Nick's avatar Nick

fix: sqlite migrations

parent fefd60a3
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## [2.0.0-beta.XX] - 2018-XX-XX ## [2.0.0-beta.42] - 2018-02-17
### Added ### Added
- Added Patreon link in Contribute admin page - Added Patreon link in Contribute admin page
- Added Theme Code Injection functionality - Added Theme Code Injection functionality
...@@ -27,5 +27,5 @@ This project adheres to [Semantic Versioning](http://semver.org/). ...@@ -27,5 +27,5 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [2.0.0-beta.11] - 2018-01-20 ## [2.0.0-beta.11] - 2018-01-20
- First beta release - First beta release
[2.0.0-beta.12]: https://github.com/Requarks/wiki/releases/tag/2.0.0-beta.12 [2.0.0-beta.42]: https://github.com/Requarks/wiki/releases/tag/2.0.0-beta.42
[2.0.0-beta.11]: https://github.com/Requarks/wiki/releases/tag/2.0.0-beta.11 [2.0.0-beta.11]: https://github.com/Requarks/wiki/releases/tag/2.0.0-beta.11
...@@ -11,7 +11,6 @@ RUN apk update && \ ...@@ -11,7 +11,6 @@ RUN apk update && \
WORKDIR /wiki WORKDIR /wiki
COPY package.json . COPY package.json .
RUN yarn --silent RUN yarn --silent
COPY ./dev/docker-sqlite/init.sh ./init.sh
ENV dockerdev 1 ENV dockerdev 1
ENV DEVDB sqlite ENV DEVDB sqlite
......
...@@ -11,8 +11,16 @@ module.exports = { ...@@ -11,8 +11,16 @@ module.exports = {
WIKI.models = require('./db').init() WIKI.models = require('./db').init()
try {
await WIKI.models.onReady await WIKI.models.onReady
await WIKI.configSvc.loadFromDb() await WIKI.configSvc.loadFromDb()
} catch (err) {
WIKI.logger.error('Database Initialization Error: ' + err.message)
if (WIKI.IS_DEBUG) {
console.error(err)
}
process.exit(1)
}
this.bootMaster() this.bootMaster()
}, },
......
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.string('editorKey').references('key').inTable('editors')
table.string('localeCode', 2).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,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', 2).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')
}
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')
})
}
...@@ -2,6 +2,8 @@ const path = require('path') ...@@ -2,6 +2,8 @@ const path = require('path')
const fs = require('fs-extra') const fs = require('fs-extra')
const semver = require('semver') const semver = require('semver')
const baseMigrationPath = path.join(WIKI.SERVERPATH, (WIKI.config.db.type !== 'sqlite') ? 'db/migrations' : 'db/migrations-sqlite')
/* global WIKI */ /* global WIKI */
module.exports = { module.exports = {
...@@ -10,11 +12,10 @@ module.exports = { ...@@ -10,11 +12,10 @@ module.exports = {
* @returns Promise<string[]> * @returns Promise<string[]>
*/ */
async getMigrations() { async getMigrations() {
const absoluteDir = path.join(WIKI.SERVERPATH, 'db/migrations') const migrationFiles = await fs.readdir(baseMigrationPath)
const migrationFiles = await fs.readdir(absoluteDir)
return migrationFiles.sort(semver.compare).map(m => ({ return migrationFiles.sort(semver.compare).map(m => ({
file: m, file: m,
directory: absoluteDir directory: baseMigrationPath
})) }))
}, },
...@@ -23,6 +24,6 @@ module.exports = { ...@@ -23,6 +24,6 @@ module.exports = {
}, },
getMigration(migration) { getMigration(migration) {
return require(path.join(WIKI.SERVERPATH, 'db/migrations', migration.file)); return require(path.join(baseMigrationPath, migration.file));
} }
} }
...@@ -174,6 +174,7 @@ module.exports = class Page extends Model { ...@@ -174,6 +174,7 @@ module.exports = class Page extends Model {
} }
await WIKI.models.pageHistory.addVersion({ await WIKI.models.pageHistory.addVersion({
...ogPage, ...ogPage,
isPublished: ogPage.isPublished === true || ogPage.isPublished === 1,
action: 'updated' action: 'updated'
}) })
await WIKI.models.pages.query().patch({ await WIKI.models.pages.query().patch({
......
...@@ -12,13 +12,14 @@ module.exports = { ...@@ -12,13 +12,14 @@ module.exports = {
new LocalStrategy({ new LocalStrategy({
usernameField: 'email', usernameField: 'email',
passwordField: 'password' passwordField: 'password'
}, (uEmail, uPassword, done) => { }, async (uEmail, uPassword, done) => {
WIKI.models.users.query().findOne({ try {
const user = await WIKI.models.users.query().findOne({
email: uEmail, email: uEmail,
providerKey: 'local' providerKey: 'local'
}).then((user) => { })
if (user) { if (user) {
return user.verifyPassword(uPassword).then(() => { await user.verifyPassword(uPassword)
if (!user.isActive) { if (!user.isActive) {
done(new WIKI.Error.AuthAccountBanned(), null) done(new WIKI.Error.AuthAccountBanned(), null)
} else if (!user.isVerified) { } else if (!user.isVerified) {
...@@ -26,16 +27,13 @@ module.exports = { ...@@ -26,16 +27,13 @@ module.exports = {
} else { } else {
done(null, user) done(null, user)
} }
}).catch((err) => {
done(err, null)
})
} else { } else {
done(new WIKI.Error.AuthLoginFailed(), null) done(new WIKI.Error.AuthLoginFailed(), null)
} }
}).catch((err) => { } catch (err) {
done(err, null) done(err, null)
})
} }
)) })
)
} }
} }
...@@ -124,7 +124,9 @@ const init = { ...@@ -124,7 +124,9 @@ const init = {
console.warn(chalk.yellow('--- Closing DB connections...')) console.warn(chalk.yellow('--- Closing DB connections...'))
await global.WIKI.models.knex.destroy() await global.WIKI.models.knex.destroy()
console.warn(chalk.yellow('--- Closing Server connections...')) console.warn(chalk.yellow('--- Closing Server connections...'))
global.WIKI.server.destroy(() => { if (global.WIKI.server) {
await new Promise((resolve, reject) => global.WIKI.server.destroy(resolve))
}
console.warn(chalk.yellow('--- Purging node modules cache...')) console.warn(chalk.yellow('--- Purging node modules cache...'))
global.WIKI = {} global.WIKI = {}
...@@ -145,7 +147,6 @@ const init = { ...@@ -145,7 +147,6 @@ const init = {
process.removeAllListeners('uncaughtException') process.removeAllListeners('uncaughtException')
require('./server') require('./server')
})
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment