Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store migrations statestore in datadir #289

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading