2023-05-08 09:49:53 +00:00
|
|
|
import path from "path";
|
|
|
|
import * as testUtils from "test/server/testUtils";
|
|
|
|
import {execFileSync} from "child_process";
|
|
|
|
|
2024-09-05 20:30:04 +00:00
|
|
|
export async function prepareDatabase(tempDirectory: string, filename: string = 'landing.db') {
|
2023-05-08 09:49:53 +00:00
|
|
|
// Let's create a sqlite db that we can share with servers that run in other processes, hence
|
|
|
|
// not an in-memory db. Running seed.ts directly might not take in account the most recent value
|
|
|
|
// for TYPEORM_DATABASE, because ormconfig.js may already have been loaded with a different
|
|
|
|
// configuration (in-memory for instance). Spawning a process is one way to make sure that the
|
|
|
|
// latest value prevail.
|
2024-09-05 20:30:04 +00:00
|
|
|
process.env.TYPEORM_DATABASE = path.join(tempDirectory, filename);
|
2023-05-08 09:49:53 +00:00
|
|
|
const seed = await testUtils.getBuildFile('test/gen-server/seed.js');
|
|
|
|
execFileSync('node', [seed, 'init'], {
|
|
|
|
env: process.env,
|
|
|
|
stdio: 'inherit'
|
|
|
|
});
|
|
|
|
}
|