diff --git a/server/src/db/migrations/Migration20200101046140_tours_are_on_for_every_install.ts b/server/src/db/migrations/Migration20200101046140_tours_are_on_for_every_install.ts new file mode 100644 index 000000000..a42eae0f2 --- /dev/null +++ b/server/src/db/migrations/Migration20200101046140_tours_are_on_for_every_install.ts @@ -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 { + this.addSql("UPDATE addons SET enabled = 1 WHERE id = 'tours'"); + } +} diff --git a/server/src/db/seeders/AddonSeeder.ts b/server/src/db/seeders/AddonSeeder.ts index 681854429..e0acb7b66 100644 --- a/server/src/db/seeders/AddonSeeder.ts +++ b/server/src/db/seeders/AddonSeeder.ts @@ -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, }, { diff --git a/server/tests/unit/db/legacy-baseline.test.ts b/server/tests/unit/db/legacy-baseline.test.ts index 2f8c8d467..b6fec4c75 100644 --- a/server/tests/unit/db/legacy-baseline.test.ts +++ b/server/tests/unit/db/legacy-baseline.test.ts @@ -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. diff --git a/server/tests/unit/db/tours-on-by-default-migration.test.ts b/server/tests/unit/db/tours-on-by-default-migration.test.ts new file mode 100644 index 000000000..adf92e515 --- /dev/null +++ b/server/tests/unit/db/tours-on-by-default-migration.test.ts @@ -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); + }); +});