|
| 1 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 | +import { Kysely } from 'kysely' |
| 3 | +import { defaultSurgeryTemplate, defaultFollowupTemplate } from '../default-templates' |
| 4 | + |
| 5 | +/** |
| 6 | + * Add subtitle support to print templates. |
| 7 | + * |
| 8 | + * This migration: |
| 9 | + * 1. Updates default_print_templates with the new template structure (includes showSubtitle prop) |
| 10 | + * 2. Syncs print_templates with the updated defaults |
| 11 | + */ |
| 12 | +export async function up(db: Kysely<any>): Promise<void> { |
| 13 | + const now = Date.now() |
| 14 | + |
| 15 | + // Update default_print_templates with new template structures |
| 16 | + await db |
| 17 | + .updateTable('default_print_templates') |
| 18 | + .set({ |
| 19 | + structure: JSON.stringify(defaultSurgeryTemplate) |
| 20 | + }) |
| 21 | + .where('key', '=', 'surgery-standard') |
| 22 | + .execute() |
| 23 | + |
| 24 | + await db |
| 25 | + .updateTable('default_print_templates') |
| 26 | + .set({ |
| 27 | + structure: JSON.stringify(defaultFollowupTemplate) |
| 28 | + }) |
| 29 | + .where('key', '=', 'followup-standard') |
| 30 | + .execute() |
| 31 | + |
| 32 | + // Sync print_templates with updated defaults |
| 33 | + const defaults = await db |
| 34 | + .selectFrom('default_print_templates') |
| 35 | + .select(['key', 'type', 'structure']) |
| 36 | + .execute() |
| 37 | + |
| 38 | + for (const defaultTemplate of defaults) { |
| 39 | + await db |
| 40 | + .updateTable('print_templates') |
| 41 | + .set({ |
| 42 | + structure: defaultTemplate.structure, |
| 43 | + updated_at: now |
| 44 | + }) |
| 45 | + .where('type', '=', defaultTemplate.type) |
| 46 | + .where('is_default', '=', 1) |
| 47 | + .execute() |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +export async function down(_db: Kysely<any>): Promise<void> { |
| 52 | + // No-op: This is a data sync migration, not reversible without storing old data |
| 53 | +} |
0 commit comments