File size: 955 Bytes
a4836dc
 
ad2afbf
b01d539
 
 
 
a4836dc
 
ad2afbf
b01d539
a4836dc
b01d539
 
 
 
 
 
 
ad2afbf
 
b01d539
 
 
 
a4836dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { SystemDatabase } from "./database.js";
import { SqliteSystemDatabase } from "./sqlite-system-database.js";
import type { AppEnvironment } from "../config/environment.js";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import type { OperationalMetrics } from "../observability/operational-metrics.js";
import { prepareLocalDatabasePath } from "../startup/database-path.js";

export async function createDatabase(
  environment: AppEnvironment,
  metrics?: OperationalMetrics,
): Promise<SystemDatabase> {
  await prepareLocalDatabasePath({
    databasePath: environment.databasePath,
    objectStorageRoot: environment.objectStorageRoot,
  });
  return SqliteSystemDatabase.connect(
    pathToFileURL(environment.databasePath).href,
    {
      appBuildSha: environment.gitCommitSha,
      appKey: environment.appKey,
      backupRoot: join(environment.objectStorageRoot, "backups"),
      metrics,
    },
  );
}