@@ -17,7 +17,7 @@ import crypto from "crypto";
1717 * If content appears stale or "reverts", check views FIRST.
1818 */
1919
20- export const LAB_NOTES_SCHEMA_VERSION = 9 ;
20+ export const LAB_NOTES_SCHEMA_VERSION = 10 ;
2121
2222function setLabNotesSchemaVersion ( db : Database . Database , version : number ) {
2323 const cur = db
@@ -563,6 +563,37 @@ export function migrateLabNotesSchema(
563563 ` ) ;
564564 }
565565
566+ // ---- v10: remove legacy UNIQUE(slug) constraints (keep UNIQUE(slug, locale)) ----
567+ if ( prevVersion < 10 ) {
568+ // Find any UNIQUE indexes that cover slug only (legacy) and drop them.
569+ // We keep uq_lab_notes_slug_locale (or recreate it if missing).
570+ const indexes = db
571+ . prepare ( `PRAGMA index_list('lab_notes')` )
572+ . all ( ) as Array < { name : string ; unique : number } > ;
573+
574+ for ( const idx of indexes ) {
575+ if ( ! idx . unique ) continue ;
576+
577+ const cols = db
578+ . prepare ( `PRAGMA index_info('${ idx . name . replace ( / ' / g, "''" ) } ')` )
579+ . all ( ) as Array < { name : string } > ;
580+
581+ const colNames = cols . map ( ( c ) => c . name ) ;
582+ const isSlugOnly = colNames . length === 1 && colNames [ 0 ] === "slug" ;
583+
584+ // Drop legacy slug-only uniqueness (this is what is causing your error)
585+ if ( isSlugOnly ) {
586+ db . exec ( `DROP INDEX IF EXISTS ${ idx . name } ;` ) ;
587+ log ?.( `[db] dropped legacy unique index on slug: ${ idx . name } ` ) ;
588+ }
589+ }
590+
591+ // Ensure the correct uniqueness exists
592+ db . exec ( `
593+ CREATE UNIQUE INDEX IF NOT EXISTS uq_lab_notes_slug_locale
594+ ON lab_notes(slug, locale);
595+ ` ) ;
596+ }
566597
567598
568599 // ⚠️ WARNING ⚠️
0 commit comments