feat(addons): Tours is on for every install

A fresh install gets Tours enabled from the addon seeder. An install that
already has the row is switched on by a migration that runs once, so an
admin who turns Tours off afterwards keeps it off.
This commit is contained in:
Maurice
2026-10-20 20:52:00 +02:00
parent e42622d71d
commit 5580ff71a9
4 changed files with 58 additions and 2 deletions
@@ -0,0 +1,15 @@
import { Migration } from '@mikro-orm/migrations';
/**
* Tours is on for every install from v5 on. A fresh install gets it from the
* addon seeder, which now writes it enabled; an install that already has the
* row is switched on here, once. The migration never runs again, so an admin
* who turns Tours off afterwards keeps it off.
*/
export class Migration20200101046140_tours_are_on_for_every_install extends Migration {
override name = 'Migration20200101046140_tours_are_on_for_every_install';
override async up(): Promise<void> {
this.addSql("UPDATE addons SET enabled = 1 WHERE id = 'tours'");
}
}
+2 -2
View File
@@ -13,7 +13,7 @@ interface AddonRow {
sort_order: number;
}
const DEFAULT_ADDONS: AddonRow[] = [
export const DEFAULT_ADDONS: AddonRow[] = [
{
id: 'packing',
name: 'Lists',
@@ -101,7 +101,7 @@ const DEFAULT_ADDONS: AddonRow[] = [
description: 'Hikes and other single-day tours that follow a route',
type: 'trip',
icon: 'Mountain',
enabled: 0,
enabled: 1,
sort_order: 8,
},
{
@@ -80,6 +80,7 @@ const UNNUMBERED = [
'Migration20200101046110_a_tour_points_at_its_packing_list',
'Migration20200101046120_a_wanderer_connection_can_watch_its_sources',
'Migration20200101046130_snowshoeing_and_winter_hiking_are_ski_disciplines',
'Migration20200101046140_tours_are_on_for_every_install',
];
// The last step the positional runner ever had; planLegacyBaseline refuses a
// schema_version past it.
@@ -0,0 +1,40 @@
/**
* Tours is on for every install from v5 on: the migration switches an existing
* install's Tours row on once and touches no other addon, and the seeder writes
* Tours enabled on a fresh install.
*/
import { DEFAULT_ADDONS } from '../../../src/db/seeders/AddonSeeder';
import { createMigrationOrm, migrateTo, pendingNames, rawExec, rawQuery } from '../../helpers/migration-step';
import { describe, expect, it } from 'vitest';
const TARGET = 'Migration20200101046140_tours_are_on_for_every_install';
describe('tours on by default', () => {
it('ADDON-TOURS-001: an existing install has Tours switched on once, the other addons stay as they were', async () => {
const orm = await createMigrationOrm();
try {
const names = await pendingNames(orm);
const idx = names.indexOf(TARGET);
expect(idx).toBeGreaterThan(0);
await migrateTo(orm, names[idx - 1]);
await rawExec(
orm,
"INSERT INTO addons (id, name, type, enabled, sort_order) VALUES ('tours', 'Tours', 'trip', 0, 8), ('roadtrip', 'Road trip', 'trip', 0, 7)",
);
await migrateTo(orm, TARGET);
expect(await rawQuery(orm, 'SELECT id, enabled FROM addons ORDER BY id')).toEqual([
{ id: 'roadtrip', enabled: 0 },
{ id: 'tours', enabled: 1 },
]);
} finally {
await orm.close(true);
}
});
it('ADDON-TOURS-002: the seeder writes Tours enabled for a fresh install', () => {
expect(DEFAULT_ADDONS.find((addon) => addon.id === 'tours')?.enabled).toBe(1);
});
});