2014-02-12 17:27:43 +00:00
|
|
|
Sequelize = require("sequelize")
|
|
|
|
Settings = require("settings-sharelatex")
|
2015-05-05 08:47:17 +00:00
|
|
|
_ = require("underscore")
|
2018-03-05 16:02:16 +00:00
|
|
|
logger = require "logger-sharelatex"
|
2015-05-05 08:47:17 +00:00
|
|
|
|
|
|
|
options = _.extend {logging:false}, Settings.mysql.clsi
|
2014-02-12 17:27:43 +00:00
|
|
|
|
2018-03-16 15:29:35 +00:00
|
|
|
logger.log dbPath:Settings.mysql.clsi.storage, "connecting to db"
|
|
|
|
|
2014-02-12 17:27:43 +00:00
|
|
|
sequelize = new Sequelize(
|
|
|
|
Settings.mysql.clsi.database,
|
|
|
|
Settings.mysql.clsi.username,
|
|
|
|
Settings.mysql.clsi.password,
|
2015-05-05 08:47:17 +00:00
|
|
|
options
|
2014-02-12 17:27:43 +00:00
|
|
|
)
|
|
|
|
|
2018-07-17 11:53:07 +00:00
|
|
|
if Settings.mysql.clsi.dialect == "sqlite"
|
2018-07-26 15:12:26 +00:00
|
|
|
logger.log "running PRAGMA journal_mode=WAL;"
|
2018-07-17 11:53:07 +00:00
|
|
|
sequelize.query("PRAGMA journal_mode=WAL;")
|
2018-07-30 14:16:06 +00:00
|
|
|
sequelize.query("PRAGMA synchronous=OFF;")
|
|
|
|
sequelize.query("PRAGMA read_uncommitted = true;")
|
2018-07-17 11:50:33 +00:00
|
|
|
|
2014-02-12 17:27:43 +00:00
|
|
|
module.exports =
|
|
|
|
UrlCache: sequelize.define("UrlCache", {
|
|
|
|
url: Sequelize.STRING
|
|
|
|
project_id: Sequelize.STRING
|
|
|
|
lastModified: Sequelize.DATE
|
2015-05-15 13:05:17 +00:00
|
|
|
}, {
|
|
|
|
indexes: [
|
|
|
|
{fields: ['url', 'project_id']},
|
|
|
|
{fields: ['project_id']}
|
|
|
|
]
|
2014-02-12 17:27:43 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Project: sequelize.define("Project", {
|
2015-05-15 13:05:17 +00:00
|
|
|
project_id: {type: Sequelize.STRING, primaryKey: true}
|
2014-02-12 17:27:43 +00:00
|
|
|
lastAccessed: Sequelize.DATE
|
2015-05-15 13:05:17 +00:00
|
|
|
}, {
|
|
|
|
indexes: [
|
|
|
|
{fields: ['lastAccessed']}
|
|
|
|
]
|
2014-02-12 17:27:43 +00:00
|
|
|
})
|
|
|
|
|
2018-07-30 16:37:30 +00:00
|
|
|
op: Sequelize.Op
|
|
|
|
|
2018-03-05 16:02:16 +00:00
|
|
|
sync: () ->
|
|
|
|
logger.log dbPath:Settings.mysql.clsi.storage, "syncing db schema"
|
|
|
|
sequelize.sync()
|
2018-07-30 13:04:33 +00:00
|
|
|
.then(->
|
|
|
|
logger.log "db sync complete"
|
|
|
|
).catch((err)->
|
|
|
|
console.log err, "error syncing"
|
|
|
|
)
|
|
|
|
|
2014-02-12 17:27:43 +00:00
|
|
|
|