mirror of
https://github.com/zadam/trilium.git
synced 2025-03-12 15:56:26 +08:00
fix resource path bug
This commit is contained in:
parent
695f0e5879
commit
f6d481a9e2
4 changed files with 35 additions and 16 deletions
|
@ -4,8 +4,9 @@ const ini = require('ini');
|
|||
const fs = require('fs');
|
||||
const dataDir = require('./data_dir');
|
||||
const path = require('path');
|
||||
const resource_dir = require('./resource_dir');
|
||||
|
||||
const configSampleFilePath = path.resolve(__dirname, "..", "config-sample.ini");
|
||||
const configSampleFilePath = path.resolve(resource_dir.RESOURCE_DIR, "config-sample.ini");
|
||||
|
||||
const configFilePath = dataDir.TRILIUM_DATA_DIR + '/config.ini';
|
||||
|
||||
|
|
|
@ -3,14 +3,7 @@ const sql = require('./sql');
|
|||
const options = require('./options');
|
||||
const fs = require('fs-extra');
|
||||
const log = require('./log');
|
||||
const path = require('path');
|
||||
|
||||
const MIGRATIONS_DIR = path.resolve(__dirname, "..", "migrations");
|
||||
|
||||
if (!fs.existsSync(MIGRATIONS_DIR)) {
|
||||
log.error("Could not find migration directory: " + MIGRATIONS_DIR);
|
||||
process.exit(1);
|
||||
}
|
||||
const resource_dir = require('./resource_dir');
|
||||
|
||||
async function migrate() {
|
||||
const migrations = [];
|
||||
|
@ -20,7 +13,7 @@ async function migrate() {
|
|||
|
||||
const currentDbVersion = parseInt(await options.getOption('db_version'));
|
||||
|
||||
fs.readdirSync(MIGRATIONS_DIR).forEach(file => {
|
||||
fs.readdirSync(resource_dir.MIGRATIONS_DIR).forEach(file => {
|
||||
const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)/);
|
||||
|
||||
if (match) {
|
||||
|
@ -53,7 +46,7 @@ async function migrate() {
|
|||
|
||||
await sql.doInTransaction(async () => {
|
||||
if (mig.type === 'sql') {
|
||||
const migrationSql = fs.readFileSync(MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
|
||||
const migrationSql = fs.readFileSync(resource_dir.MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
|
||||
|
||||
console.log("Migration with SQL script: " + migrationSql);
|
||||
|
||||
|
@ -62,7 +55,7 @@ async function migrate() {
|
|||
else if (mig.type === 'js') {
|
||||
console.log("Migration with JS module");
|
||||
|
||||
const migrationModule = require("../" + MIGRATIONS_DIR + "/" + mig.file);
|
||||
const migrationModule = require("../" + resource_dir.MIGRATIONS_DIR + "/" + mig.file);
|
||||
await migrationModule(db);
|
||||
}
|
||||
else {
|
||||
|
|
25
services/resource_dir.js
Normal file
25
services/resource_dir.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const log = require('./log');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const RESOURCE_DIR = path.resolve(__dirname, "..");
|
||||
|
||||
const MIGRATIONS_DIR = path.resolve(RESOURCE_DIR, "migrations");
|
||||
|
||||
if (!fs.existsSync(MIGRATIONS_DIR)) {
|
||||
log.error("Could not find migration directory: " + MIGRATIONS_DIR);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const DB_INIT_DIR = path.resolve(RESOURCE_DIR, "db");
|
||||
|
||||
if (!fs.existsSync(DB_INIT_DIR)) {
|
||||
log.error("Could not find DB initialization directory: " + DB_INIT_DIR);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RESOURCE_DIR,
|
||||
MIGRATIONS_DIR,
|
||||
DB_INIT_DIR
|
||||
};
|
|
@ -4,8 +4,8 @@ const log = require('./log');
|
|||
const dataDir = require('./data_dir');
|
||||
const fs = require('fs');
|
||||
const sqlite = require('sqlite');
|
||||
const utils = require('./utils');
|
||||
const app_info = require('./app_info');
|
||||
const resource_dir = require('./resource_dir');
|
||||
|
||||
async function createConnection() {
|
||||
return await sqlite.open(dataDir.DOCUMENT_PATH, {Promise});
|
||||
|
@ -28,9 +28,9 @@ const dbReady = new Promise((resolve, reject) => {
|
|||
if (tableResults.length !== 1) {
|
||||
log.info("Connected to db, but schema doesn't exist. Initializing schema ...");
|
||||
|
||||
const schema = fs.readFileSync('db/schema.sql', 'UTF-8');
|
||||
const notesSql = fs.readFileSync('db/main_notes.sql', 'UTF-8');
|
||||
const notesTreeSql = fs.readFileSync('db/main_notes_tree.sql', 'UTF-8');
|
||||
const schema = fs.readFileSync(resource_dir.DB_INIT_DIR + '/schema.sql', 'UTF-8');
|
||||
const notesSql = fs.readFileSync(resource_dir.DB_INIT_DIR + '/main_notes.sql', 'UTF-8');
|
||||
const notesTreeSql = fs.readFileSync(resource_dir.DB_INIT_DIR + '/main_notes_tree.sql', 'UTF-8');
|
||||
|
||||
await doInTransaction(async () => {
|
||||
await executeScript(schema);
|
||||
|
|
Loading…
Reference in a new issue