Repositories gitConnections/brewGitLinks (Mongo/PG), Krypto, SSRF-Policy mit net.BlockList, git-Client ohne Arbeitskopie, Sync/Konflikte, /api/git/*, Client (Verbindungen, Git-Status, Konfliktdialog), Autosave 60 s für Git-Brews (F6), Tests und Doku. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Dev (Paperclip) <dev-bot@noreply.git.morlana.online>
52 lines
2.1 KiB
JavaScript
52 lines
2.1 KiB
JavaScript
import { createDb, checkServerVersion, migrateToLatest } from './db.js';
|
|
import { createBrewRepository } from './brews.js';
|
|
import { createNotificationRepository } from './notifications.js';
|
|
import { createUserRepository } from './users.js';
|
|
import { createGitConnectionRepository, createBrewGitLinkRepository } from './gitRepos.js';
|
|
|
|
// PostgreSQL-Implementierung der Storage-Schicht (ADR 0002). Kysely + pg, versionierte Migrationen
|
|
// laufen beim Start (migrateToLatest). Konfiguration: HB_POSTGRES_URL, HB_POSTGRES_POOL_MAX.
|
|
export const createPostgresStorage = (config, overrides = {})=>{
|
|
let handle;
|
|
let ready = false;
|
|
const repos = {};
|
|
|
|
const build = (db)=>{
|
|
repos.brews = createBrewRepository(db);
|
|
repos.notifications = createNotificationRepository(db);
|
|
repos.users = createUserRepository(db);
|
|
repos.gitConnections = createGitConnectionRepository(db);
|
|
repos.brewGitLinks = createBrewGitLinkRepository(db);
|
|
};
|
|
|
|
return {
|
|
driver : 'postgres',
|
|
get brews() { return repos.brews; },
|
|
get notifications() { return repos.notifications; },
|
|
get users() { return repos.users; },
|
|
get gitConnections() { return repos.gitConnections; },
|
|
get brewGitLinks() { return repos.brewGitLinks; },
|
|
get pool() { return handle?.pool; }, // nur für Tests
|
|
async connect() {
|
|
const url = overrides.url ?? config?.get('hb_postgres_url');
|
|
if(!url) throw new Error('HB_DB_DRIVER=postgres, aber HB_POSTGRES_URL ist nicht gesetzt (z. B. postgres://hb:…@postgres:5432/homebrewery)');
|
|
const poolMax = parseInt(overrides.poolMax ?? config?.get('hb_postgres_pool_max'), 10) || 10;
|
|
handle = createDb({ url, poolMax, searchPath: overrides.searchPath });
|
|
// Fehler idle Clients nur loggen: pg verwirft den Client, der Pool stellt neue Verbindungen selbst her.
|
|
handle.pool.on('error', (err)=>{ console.error('PostgreSQL-Pool-Fehler:', err.message); });
|
|
await checkServerVersion(handle.pool);
|
|
await migrateToLatest(handle.db);
|
|
build(handle.db);
|
|
ready = true;
|
|
},
|
|
async disconnect() {
|
|
ready = false;
|
|
await handle?.db.destroy();
|
|
handle = undefined;
|
|
},
|
|
isReady() {
|
|
return ready;
|
|
}
|
|
};
|
|
};
|