Skip to content

Commit

Permalink
Put migrations statestore in datadir
Browse files Browse the repository at this point in the history
  • Loading branch information
bjw-s committed Dec 4, 2023
1 parent 42699ac commit 93d16f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ServerOptions } from 'https';

export interface Config {
mode: 'test' | 'development';
dataDir: string;
port: number;
hostname: string;
serverFiles: string;
Expand Down
4 changes: 3 additions & 1 deletion src/load-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (process.env.ACTUAL_CONFIG_PATH) {
userConfig = parseJSON(configFile, true);
}

/** @type {Omit<import('./config-types.js').Config, 'mode' | 'serverFiles' | 'userFiles'>} */
/** @type {Omit<import('./config-types.js').Config, 'mode' | 'dataDir' | 'serverFiles' | 'userFiles'>} */
let defaultConfig = {
port: 5006,
hostname: '::',
Expand All @@ -67,6 +67,7 @@ let config;
if (process.env.NODE_ENV === 'test') {
config = {
mode: 'test',
dataDir: projectRoot,
serverFiles: path.join(projectRoot, 'test-server-files'),
userFiles: path.join(projectRoot, 'test-user-files'),
...defaultConfig,
Expand All @@ -75,6 +76,7 @@ if (process.env.NODE_ENV === 'test') {
config = {
mode: 'development',
...defaultConfig,
dataDir: defaultDataDir,
serverFiles: path.join(defaultDataDir, 'server-files'),
userFiles: path.join(defaultDataDir, 'user-files'),
...(userConfig || {}),
Expand Down
5 changes: 4 additions & 1 deletion src/migrations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import migrate from 'migrate';
import path from 'node:path';
import config from './load-config.js';

export default function run(direction = 'up') {
Expand All @@ -9,7 +10,9 @@ export default function run(direction = 'up') {
return new Promise((resolve) =>
migrate.load(
{
stateStore: `.migrate${config.mode === 'test' ? '-test' : ''}`,
stateStore: `${path.join(config.dataDir, '.migrate')}${
config.mode === 'test' ? '-test' : ''
}`,
},
(err, set) => {
if (err) {
Expand Down

0 comments on commit 93d16f0

Please sign in to comment.