Skip to content

Commit

Permalink
Store migrations statestore in datadir (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjw-s authored Dec 5, 2023
1 parent 42699ac commit f93893e
Show file tree
Hide file tree
Showing 4 changed files with 14 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
6 changes: 6 additions & 0 deletions upcoming-release-notes/289.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [bjw-s]
---

Store the migrations statestore in the datadir instead of the application root.

0 comments on commit f93893e

Please sign in to comment.