mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
feat(plugins): store plugin data on the engine TREK runs on
PLUGIN_DATA binds the plugin data backend to the engine (the same
{ sqlite, postgres }[engine.id] binding the backup port uses): the SQLite
file per plugin, unchanged, or the Postgres schema per plugin. The host
opens a plugin's store through it and an uninstall that deletes data erases
through it, which drops the schema on Postgres. Nothing outside db/engine
asks which engine runs.
A plugin's SQL is passed through as written, so a plugin needs to know the
dialect: db.engine (db:own) answers 'sqlite' or 'postgres', and the SDK
exposes it as ctx.db.engine(), in the mock host (dbEngine option) and in
dev. The plugin facts are regenerated and the SDK goes to 1.10.0.
The Postgres lane's PGPLUG suite installs, uses and erases plugin data on
Postgres and shows that a plugin reaches neither TREK's users table nor
another plugin's schema.
This commit is contained in:
@@ -53,7 +53,6 @@ import path from 'node:path';
|
||||
import { PluginRpcHostFactory } from './host/plugin-rpc-host.factory';
|
||||
import { closePluginDataDb } from './host/plugin-host-state';
|
||||
import { ForbiddenResource } from './host/rpc-host';
|
||||
import { removePluginData } from './host/plugin-data.service';
|
||||
import { isKnownPermission } from './protocol/envelope';
|
||||
import { discoverPlugins, type DiscoveryRepos } from './install/discovery';
|
||||
import { enqueueHookUserDataErasures } from './user-erasure-enqueue';
|
||||
@@ -1091,7 +1090,11 @@ export class PluginRuntimeService implements OnApplicationBootstrap, OnModuleDes
|
||||
// leave a plugin without its row but with its settings, grants or tasks, which a
|
||||
// later plugin reusing the id would inherit. The data dir goes after the commit.
|
||||
await this.uow.transactional(() => this.dropPluginRows(id, deleteData));
|
||||
if (deleteData) removePluginData(id);
|
||||
// The plugin's own database (a SQLite file, or its schema on Postgres) and its data dir.
|
||||
if (deleteData) {
|
||||
if (!this.hostFactory) throw new Error('PluginRpcHostFactory not provided: it is what erases the plugin data');
|
||||
await this.hostFactory.erasePluginData(id);
|
||||
}
|
||||
}
|
||||
|
||||
private async dropPluginRows(id: string, deleteData: boolean): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user