const Knex = require('knex')
const config = require('./config')
const knex = Knex(config.knex)
async function createSchema () {
const hasTable = await knex.schema.hasTable('videoRequests')
if (!hasTable) {
return knex.migrate.latest()
.then(() => {
__logger.info(`Server was successfully creates initial table in '${config.knex.connection.database}' database`)
}).catch(error => {
throw Error(`Initial schema creation was fail ${error}`)
})
} else {
__logger.info(`'${config.knex.connection.database}' database already has required schema`)
}
}
module.exports = createSchema
Created
March 22, 2019 10:33
-
-
Save zmts/c288d0fd0a6fe2995a07cd242cf41951 to your computer and use it in GitHub Desktop.
Knex: create table if not exists
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great, tahnks!