diff --git a/server/src/schema/migrations/1784836013770-MinFacePreferenceMigration.ts b/server/src/schema/migrations/1784836013770-MinFacePreferenceMigration.ts new file mode 100644 index 0000000000..74d28768e1 --- /dev/null +++ b/server/src/schema/migrations/1784836013770-MinFacePreferenceMigration.ts @@ -0,0 +1,25 @@ +import { Kysely, sql } from 'kysely'; + +export async function up(db: Kysely): Promise { + await sql` + INSERT INTO "user_metadata" ("userId", "key", "value") + SELECT "user"."id", 'preferences', jsonb_build_object('people', jsonb_build_object('minimumFaces', "config"."minFaces")) + FROM "user" + CROSS JOIN ( + SELECT "value"->'machineLearning'->'facialRecognition'->'minFaces' AS "minFaces" + FROM "system_metadata" + WHERE "key" = 'system-config' + AND "value"->'machineLearning'->'facialRecognition'->'minFaces' IS NOT NULL + ) AS "config" + ON CONFLICT ("userId", "key") DO UPDATE + SET "value" = "user_metadata"."value" || jsonb_build_object( + 'people', + COALESCE("user_metadata"."value"->'people', '{}'::jsonb) || (EXCLUDED."value"->'people') + ) + WHERE "user_metadata"."value"->'people'->'minimumFaces' IS NULL + `.execute(db); +} + +export async function down(): Promise { + // not supported +}