feat(db): run TREK on PostgreSQL

TREK runs on PostgreSQL when TREK_DB_URL is set, and on SQLite as before
otherwise: an engine port under src/db/engine, the dialect helpers under
src/db/dialect, a Postgres baseline for the migrations up to the cut,
pg_dump/pg_restore backups, a probe of every repository method against a
real server and a Postgres test lane in CI.
This commit is contained in:
Isaias Tavares
2026-11-05 01:15:21 -03:00
committed by Maurice
parent 17b47b38b9
commit 2e3762afe1
176 changed files with 6728 additions and 777 deletions
+2 -1
View File
@@ -8,6 +8,7 @@
import { getMcpSafeUrl } from '../../src/app-config';
import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { SqliteEngine } from '../../src/db/engine/sqlite/sqlite-engine';
import { AuditLog } from '../../src/db/entities/AuditLog.entity';
import { McpTokens } from '../../src/db/entities/McpTokens.entity';
import { OauthClients } from '../../src/db/entities/OauthClients.entity';
@@ -85,7 +86,7 @@ beforeAll(async () => {
t.repo(OauthConsents),
await createTestAddonsService(testDb),
new AuditService(t.repo(AuditLog), t.repo(Users)),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
nestApp.get(CimdClientResolver),
);
});
@@ -10,6 +10,7 @@
*/
import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { SqliteEngine } from '../../src/db/engine/sqlite/sqlite-engine';
import { Addons } from '../../src/db/entities/Addons.entity';
import { AuditLog } from '../../src/db/entities/AuditLog.entity';
import { OauthClients } from '../../src/db/entities/OauthClients.entity';
@@ -96,7 +97,7 @@ beforeAll(async () => {
t.repo(OauthConsents),
await createTestAddonsService(testDb),
new AuditService(t.repo(AuditLog), t.repo(Users)),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
nestApp.get(CimdClientResolver),
);
});
+2 -1
View File
@@ -5,6 +5,7 @@
*/
import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { SqliteEngine } from '../../src/db/engine/sqlite/sqlite-engine';
import { Addons } from '../../src/db/entities/Addons.entity';
import { AuditLog } from '../../src/db/entities/AuditLog.entity';
import { OauthClients } from '../../src/db/entities/OauthClients.entity';
@@ -97,7 +98,7 @@ beforeAll(async () => {
t.repo(OauthConsents),
await createTestAddonsService(testDb),
new AuditService(t.repo(AuditLog), t.repo(Users)),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
nestApp.get(CimdClientResolver),
);
});
+17
View File
@@ -468,6 +468,23 @@ describe('Search places', () => {
expect(res.body.places).toHaveLength(1);
expect(res.body.places[0].name).toBe('Scenic Place');
});
it('PLACE-017c — GET ?category= or ?tag= with an id that is not a number matches nothing', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
createPlace(testDb, trip.id, { name: 'Somewhere' });
const queries = ['category=abc', 'tag=abc', 'category=1.5', 'tag=-1', 'category=0', 'tag=0'];
const responses = await Promise.all(
queries.map((query) =>
request(app).get(`/api/trips/${trip.id}/places?${query}`).set('Cookie', authCookie(user.id)),
),
);
for (const [i, res] of responses.entries()) {
expect(res.status, queries[i]).toBe(200);
expect(res.body.places, queries[i]).toEqual([]);
}
});
});
// ─────────────────────────────────────────────────────────────────────────────
@@ -17,6 +17,7 @@
* asserts the plugin still comes up clean.
*/
import { db as testDb } from '../../../src/db/database';
import { SqliteEngine } from '../../../src/db/engine/sqlite/sqlite-engine';
import { Addons } from '../../../src/db/entities/Addons.entity';
import { AppSettings } from '../../../src/db/entities/AppSettings.entity';
import { AuditLog } from '../../../src/db/entities/AuditLog.entity';
@@ -173,7 +174,7 @@ describe('plugin boot vs registry scan ordering', () => {
(t as TestOrm).repo(NotificationChannelPreferences),
// Plan 4 Task 4: `uow` is no longer `@Optional()` — ordered ahead
// of `registry?`/`hostFactory?`, matching the real constructor.
new UnitOfWork((t as TestOrm).em),
new UnitOfWork((t as TestOrm).em, new SqliteEngine()),
undefined,
hostFactory,
t?.orm,
@@ -264,7 +265,7 @@ describe('plugin boot vs registry scan ordering', () => {
t2.repo(PhotoProviderFields),
t2.repo(AppSettings),
t2.repo(Users),
new UnitOfWork(t2.em),
new UnitOfWork(t2.em, new SqliteEngine()),
);
const auditLogRepo2 = t2.repo(AuditLog);
const usersRepo2 = t2.repo(Users);
@@ -293,7 +294,7 @@ describe('plugin boot vs registry scan ordering', () => {
t2.repo(PluginCapabilityAudit),
t2.repo(Settings),
t2.repo(NotificationChannelPreferences),
new UnitOfWork(t2.em),
new UnitOfWork(t2.em, new SqliteEngine()),
undefined,
hostFactory2,
t2.orm,
@@ -13,6 +13,7 @@
* so every one of the 14 repositories this task injects reads/writes real columns,
* not a hand-slimmed fixture table.
*/
import { SqliteEngine } from '../../../src/db/engine/sqlite/sqlite-engine';
import { AuditLog } from '../../../src/db/entities/AuditLog.entity';
import { NotificationChannelPreferences } from '../../../src/db/entities/NotificationChannelPreferences.entity';
import { PluginActions } from '../../../src/db/entities/PluginActions.entity';
@@ -76,7 +77,7 @@ async function buildRuntime(registrar?: CronRegistrarService): Promise<PluginRun
const audit = new AuditService(t.repo(AuditLog), t.repo(Users));
const addons = await createTestAddonsService(testDb);
const userSettings = new PluginUserSettingsService(t.repo(PluginSettingsFields), t.repo(PluginUserConfig));
const uow = new UnitOfWork(t.em);
const uow = new UnitOfWork(t.em, new SqliteEngine());
return new PluginRuntimeService(
audit,
addons,
@@ -218,7 +219,7 @@ describe('Plan 3j Task 2 — R-install-gates named accept+refuse pairs (PR17/PR2
t.repo(PluginCapabilityAudit),
t.repo(Settings),
t.repo(NotificationChannelPreferences),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
fakeRegistry(['db:own']),
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -254,7 +255,7 @@ describe('Plan 3j Task 2 — R-install-gates named accept+refuse pairs (PR17/PR2
t.repo(PluginCapabilityAudit),
t.repo(Settings),
t.repo(NotificationChannelPreferences),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
fakeRegistry(['db:own', 'db:read:trips']),
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -303,7 +304,7 @@ describe('Plan 3j Task 2 — R-install-gates named accept+refuse pairs (PR17/PR2
t.repo(PluginCapabilityAudit),
t.repo(Settings),
t.repo(NotificationChannelPreferences),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
registry,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -342,7 +343,7 @@ describe('Plan 3j Task 2 — R-install-gates named accept+refuse pairs (PR17/PR2
t.repo(PluginCapabilityAudit),
t.repo(Settings),
t.repo(NotificationChannelPreferences),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
registry,
);
await expect(rtR.retrust('pr28-refuse', '2.0.0', 'NEWKEY', { userId: 1 })).rejects.toThrow(/nothing to re-trust/);
@@ -59,6 +59,7 @@
* plugin-runtime.service.ts's own comment at the wrap site) already ran inside a
* request context by the time this file's shared `runtime` finished booting.
*/
import { SqliteEngine } from '../../../src/db/engine/sqlite/sqlite-engine';
import { AuditLog } from '../../../src/db/entities/AuditLog.entity';
import { NotificationChannelPreferences } from '../../../src/db/entities/NotificationChannelPreferences.entity';
import { PluginActions } from '../../../src/db/entities/PluginActions.entity';
@@ -158,7 +159,7 @@ async function buildRuntime(registrar?: CronRegistrarService, orm?: TestOrm['orm
t.repo(Settings),
t.repo(NotificationChannelPreferences),
// Plan 4 Task 4: `uow` is no longer `@Optional()`.
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
undefined,
undefined,
orm,
@@ -3,6 +3,7 @@
* install a pinned version through the full verify -> extract -> validate ->
* move -> register pipeline (with the network download mocked).
*/
import { SqliteEngine } from '../../../src/db/engine/sqlite/sqlite-engine';
import { PluginActions } from '../../../src/db/entities/PluginActions.entity';
import { PluginErrorLog } from '../../../src/db/entities/PluginErrorLog.entity';
import { PluginSettingsFields } from '../../../src/db/entities/PluginSettingsFields.entity';
@@ -148,7 +149,7 @@ beforeEach(() => {
t.repo(PluginActions),
t.repo(PluginSettingsFields),
t.repo(PluginErrorLog),
new UnitOfWork(t.em),
new UnitOfWork(t.em, new SqliteEngine()),
);
});
afterEach(() => {