feat(demo): a fixed addon set on every boot and after every hourly reset

A demo instance now runs with one explicit addon policy (demo-addon-policy.ts)
instead of whatever its admin last switched: every trip, global and
integration addon on, and off only what reaches a server of the visitor's
own, the five document sync providers, wanderer under Tours, the Immich and
Synology Photos providers, AirTrail and Dawarich. The switches under the
addons (Tours maps, piste routing, bag tracking, the collab features) are on.

The demo seed applies it, together with the demo account's English
language, on every boot and after every reopen, and the hourly reset applies
it once more after the baseline swap, in one transaction each. A test pins
that every seeded addon and provider is named in exactly one list, so a new
addon has to be classified before it ships.
This commit is contained in:
Maurice
2026-10-24 23:33:57 +02:00
parent eae74c5605
commit 03493d4f79
5 changed files with 313 additions and 1 deletions
@@ -1,5 +1,9 @@
import { currentTimestampKysely } from '../dialect/kysely-functions';
import { Addons } from '../entities/Addons.entity';
import { AppSettings } from '../entities/AppSettings.entity';
import { DocumentProviders } from '../entities/DocumentProviders.entity';
import { PhotoProviders } from '../entities/PhotoProviders.entity';
import { Settings } from '../entities/Settings.entity';
import { Trips } from '../entities/Trips.entity';
import { Users } from '../entities/Users.entity';
import type { DB } from '../kysely/db';
@@ -36,6 +40,20 @@ export interface DemoInstanceKeyRow {
value: string | null;
}
/** One shelf of the demo addon policy (`demo/demo-addon-policy.ts`): the rows it switches on and off. */
export interface DemoShelfStates {
readonly on: readonly string[];
readonly off: readonly string[];
}
/** The states `applyAddonStates` writes: three shelves and the switches under them in `app_settings`. */
export interface DemoAddonStates {
readonly addons: DemoShelfStates;
readonly photoProviders: DemoShelfStates;
readonly documentProviders: DemoShelfStates;
readonly appSettings: Readonly<Record<string, string>>;
}
/**
* DMS9's 13-column `places` insert tuple — kept as a tuple, not an object,
* so `demo-seed.ts`'s three ~30-row example-trip data arrays (Tokyo/Kyoto,
@@ -400,4 +418,36 @@ export class DemoRepository {
await repo.upsert({ key: row.key, value: row.value }, { onConflictFields: ['key'], onConflictAction: 'merge' });
}
}
// ---------------------------------------------------------------------
// The fixed demo set (demo-addon-policy.ts), applied by the seed and the reset
// ---------------------------------------------------------------------
/**
* Writes the demo's addon states in one transaction, so a reset that fails
* halfway does not leave half the shelf switched. A named row the database
* does not hold is an update that matches nothing, never an insert: the
* seeders own which rows exist.
*/
async applyAddonStates(states: DemoAddonStates): Promise<void> {
this.validateRequestContext();
await this.em.transactional(async () => {
const addons = this.em.getRepository(Addons);
for (const id of states.addons.on) await addons.setEnabled(id, true);
for (const id of states.addons.off) await addons.setEnabled(id, false);
const photos = this.em.getRepository(PhotoProviders);
for (const id of states.photoProviders.on) await photos.setEnabled(id, 1);
for (const id of states.photoProviders.off) await photos.setEnabled(id, 0);
const documents = this.em.getRepository(DocumentProviders);
for (const id of states.documentProviders.on) await documents.setEnabled(id, 1);
for (const id of states.documentProviders.off) await documents.setEnabled(id, 0);
const settings = this.em.getRepository(AppSettings);
for (const [key, value] of Object.entries(states.appSettings)) await settings.setValue(key, value);
});
}
/** A user's own settings row, written as given (the demo account's fixed language). Composes `SettingsRepository#upsertForUser`. */
async setUserSetting(userId: number, key: string, value: string): Promise<void> {
await this.em.getRepository(Settings).upsertForUser(userId, key, value);
}
}