2020-02-19 06:14:28 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-console,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-19 06:14:14 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-19 06:14:37 -05:00
|
|
|
const Sequelize = require('sequelize')
|
2021-07-12 12:47:21 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-06-15 04:52:21 -04:00
|
|
|
const _ = require('lodash')
|
2020-02-19 06:14:37 -05:00
|
|
|
const logger = require('logger-sharelatex')
|
2015-05-05 04:47:17 -04:00
|
|
|
|
2020-02-19 06:14:37 -05:00
|
|
|
const options = _.extend({ logging: false }, Settings.mysql.clsi)
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:14:37 -05:00
|
|
|
logger.log({ dbPath: Settings.mysql.clsi.storage }, 'connecting to db')
|
2018-03-16 11:29:35 -04:00
|
|
|
|
2020-02-19 06:14:14 -05:00
|
|
|
const sequelize = new Sequelize(
|
2020-02-19 06:14:37 -05:00
|
|
|
Settings.mysql.clsi.database,
|
|
|
|
Settings.mysql.clsi.username,
|
|
|
|
Settings.mysql.clsi.password,
|
|
|
|
options
|
|
|
|
)
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:14:37 -05:00
|
|
|
if (Settings.mysql.clsi.dialect === 'sqlite') {
|
|
|
|
logger.log('running PRAGMA journal_mode=WAL;')
|
|
|
|
sequelize.query('PRAGMA journal_mode=WAL;')
|
|
|
|
sequelize.query('PRAGMA synchronous=OFF;')
|
|
|
|
sequelize.query('PRAGMA read_uncommitted = true;')
|
2020-02-19 06:14:14 -05:00
|
|
|
}
|
2018-07-17 07:50:33 -04:00
|
|
|
|
2020-02-19 06:14:14 -05:00
|
|
|
module.exports = {
|
2020-02-19 06:14:37 -05:00
|
|
|
UrlCache: sequelize.define(
|
|
|
|
'UrlCache',
|
|
|
|
{
|
|
|
|
url: Sequelize.STRING,
|
|
|
|
project_id: Sequelize.STRING,
|
2021-07-13 07:04:48 -04:00
|
|
|
lastModified: Sequelize.DATE,
|
2020-02-19 06:14:37 -05:00
|
|
|
},
|
|
|
|
{
|
2021-07-13 07:04:48 -04:00
|
|
|
indexes: [{ fields: ['url', 'project_id'] }, { fields: ['project_id'] }],
|
2020-02-19 06:14:37 -05:00
|
|
|
}
|
|
|
|
),
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:14:37 -05:00
|
|
|
Project: sequelize.define(
|
|
|
|
'Project',
|
|
|
|
{
|
|
|
|
project_id: { type: Sequelize.STRING, primaryKey: true },
|
2021-07-13 07:04:48 -04:00
|
|
|
lastAccessed: Sequelize.DATE,
|
2020-02-19 06:14:37 -05:00
|
|
|
},
|
|
|
|
{
|
2021-07-13 07:04:48 -04:00
|
|
|
indexes: [{ fields: ['lastAccessed'] }],
|
2020-02-19 06:14:37 -05:00
|
|
|
}
|
|
|
|
),
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:14:37 -05:00
|
|
|
op: Sequelize.Op,
|
2018-07-30 09:04:33 -04:00
|
|
|
|
2020-02-19 06:14:37 -05:00
|
|
|
sync() {
|
|
|
|
logger.log({ dbPath: Settings.mysql.clsi.storage }, 'syncing db schema')
|
|
|
|
return sequelize
|
|
|
|
.sync()
|
|
|
|
.then(() => logger.log('db sync complete'))
|
2021-07-13 07:04:48 -04:00
|
|
|
.catch(err => console.log(err, 'error syncing'))
|
|
|
|
},
|
2020-02-19 06:14:37 -05:00
|
|
|
}
|