Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(scores): backfill manual scores with config_id (#2233)

marliessophie34da790d5e42
diff --git a/packages/shared/prisma/migrations/20240604133340_backfill_manual_scores/migration.sql b/packages/shared/prisma/migrations/20240604133340_backfill_manual_scores/migration.sql
new file mode 100644
index 0000000000..748b160947
--- /dev/null
+++ b/packages/shared/prisma/migrations/20240604133340_backfill_manual_scores/migration.sql
@@ -0,0 +1,50 @@
+-- Create manual-score config for any project with manual scores and link config_id to scores
+BEGIN;
+WITH project_configs AS (
+INSERT INTO score_configs (id,
+ project_id,
+ name,
+ data_type,
+ is_archived,
+ min_value,
+ max_value,
+ description)
+SELECT
+ gen_random_uuid () AS id,
+ s.project_id,
+ 'manual-score',
+ 'NUMERIC',
+ FALSE,
+ - 1,
+ 1,
+ 'Langfuse legacy annotation score.'
+FROM ( SELECT DISTINCT
+ project_id
+ FROM
+ scores
+ WHERE
+ name = 'manual-score'
+ AND source = 'ANNOTATION') s
+WHERE
+ NOT EXISTS (
+ SELECT
+ 1
+ FROM
+ score_configs sc
+ WHERE
+ sc.name = 'manual-score'
+ AND sc.project_id = s.project_id)
+ RETURNING
+ id,
+ project_id
+)
+UPDATE
+ scores
+SET
+ config_id = pc.id
+FROM
+ project_configs pc
+WHERE
+ scores.project_id = pc.project_id
+ AND scores.name = 'manual-score';
+COMMIT;