Skip to content

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

fix: clean up broken migration history (#2329)

Max Deichmann46b19279c4dc
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml
index b1da98e394..85a335950a 100644
--- a/.github/workflows/pipeline.yml
+++ b/.github/workflows/pipeline.yml
@@ -67,6 +67,7 @@ jobs:
strategy:
matrix:
node-version: [20]
+ postgres-version: [12, 15]
steps:
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
@@ -97,6 +98,9 @@ jobs:
run: |
docker compose -f docker-compose.dev.yml up -d
sleep 5 # Wait for PostgreSQL to accept connections
+ docker compose ps
+ env:
+ POSTGRES_VERSION: ${{ matrix.postgres-version }}
- name: Seed DB
run: |
@@ -117,6 +121,7 @@ jobs:
strategy:
matrix:
node-version: [20]
+ postgres-version: [12, 15]
steps:
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
@@ -147,6 +152,7 @@ jobs:
run: |
docker compose -f docker-compose.dev.yml up -d
sleep 5 # Wait for PostgreSQL to accept connections
+ docker compose ps
- name: Seed DB
run: |
@@ -184,6 +190,7 @@ jobs:
- name: Run + migrate
run: |
docker compose -f docker-compose.dev.yml up -d
+ docker compose ps
sleep 5 # Wait for PostgreSQL to accept connections
- name: Seed DB
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 9ef53de53f..c2e2942049 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -1,5 +1,3 @@
-version: "3.5"
-
services:
redis:
image: redis:7.2.4
@@ -10,7 +8,7 @@ services:
- 6379:6379
db:
- image: postgres
+ image: postgres:${POSTGRES_VERSION:-latest}
restart: always
command: ["postgres", "-c", "log_statement=all"]
environment:
diff --git a/packages/shared/prisma/migrations/20240530212419_model_price_anthropic_via_google_vertex/migration.sql b/packages/shared/prisma/migrations/20240530212419_model_price_anthropic_via_google_vertex/migration.sql
deleted file mode 100644
index f4e36d0d8d..0000000000
--- a/packages/shared/prisma/migrations/20240530212419_model_price_anthropic_via_google_vertex/migration.sql
+++ /dev/null
@@ -1,7 +0,0 @@
--- Google Vertex uses @ to separate model name and version
-
-UPDATE "public"."models" SET "match_pattern" = '(?i)^(claude-3-haiku(-|@)?20240307)$' WHERE "id" = 'cltr0w45b000008k1407o9qv1';
-
-UPDATE "public"."models" SET "match_pattern" = '(?i)^(claude-3-opus(-|@)?20240229)$' WHERE "id" = 'cltgy0iuw000008le3vod1hhy';
-
-UPDATE "public"."models" SET "match_pattern" = '(?i)^(claude-3-sonnet(-|@)?20240229)$' WHERE "id" = 'cltgy0pp6000108le56se7bl3';
\ No newline at end of file
diff --git a/packages/shared/prisma/migrations/20240606090858_pricings_add_latest_gemini_models/migration.sql b/packages/shared/prisma/migrations/20240606090858_pricings_add_latest_gemini_models/migration.sql
deleted file mode 100644
index eaebbbe05e..0000000000
--- a/packages/shared/prisma/migrations/20240606090858_pricings_add_latest_gemini_models/migration.sql
+++ /dev/null
@@ -1,5 +0,0 @@
--- does not include pricing yet, will be added as soon as it is calculated at ingestion time
-
-INSERT INTO "public"."models" ("id", "model_name", "match_pattern", "unit") VALUES ('clx30djsn0000w9mzebiv41we', 'gemini-1.5-flash', '(?i)^(gemini-1.5-flash)(@[a-zA-Z0-9]+)?$', 'CHARACTERS');
-
-INSERT INTO "public"."models" ("id", "model_name", "match_pattern", "unit") VALUES ('clx30hkrx0000w9mz7lqi0ial', 'gemini-1.5-pro', '(?i)^(gemini-1.5-pro)(@[a-zA-Z0-9]+)?$', 'CHARACTERS');
\ No newline at end of file
diff --git a/packages/shared/prisma/migrations/20240607090858_pricings_add_latest_gemini_models/migration.sql b/packages/shared/prisma/migrations/20240607090858_pricings_add_latest_gemini_models/migration.sql
new file mode 100644
index 0000000000..261b909b02
--- /dev/null
+++ b/packages/shared/prisma/migrations/20240607090858_pricings_add_latest_gemini_models/migration.sql
@@ -0,0 +1,8 @@
+-- does not include pricing yet, will be added as soon as it is calculated at ingestion time
+
+-- remove model if added by faulty migration, context: https://github.com/langfuse/langfuse/issues/2266
+DELETE FROM models WHERE id in ('clx30djsn0000w9mzebiv41we', 'clx30hkrx0000w9mz7lqi0ial');
+
+INSERT INTO "models" ("id", "model_name", "match_pattern", "unit") VALUES ('clx30djsn0000w9mzebiv41we', 'gemini-1.5-flash', '(?i)^(gemini-1.5-flash)(@[a-zA-Z0-9]+)?$', 'CHARACTERS');
+
+INSERT INTO "models" ("id", "model_name", "match_pattern", "unit") VALUES ('clx30hkrx0000w9mz7lqi0ial', 'gemini-1.5-pro', '(?i)^(gemini-1.5-pro)(@[a-zA-Z0-9]+)?$', 'CHARACTERS');
\ No newline at end of file
diff --git a/packages/shared/prisma/migrations/20240607212419_model_price_anthropic_via_google_vertex/migration.sql b/packages/shared/prisma/migrations/20240607212419_model_price_anthropic_via_google_vertex/migration.sql
new file mode 100644
index 0000000000..addb980658
--- /dev/null
+++ b/packages/shared/prisma/migrations/20240607212419_model_price_anthropic_via_google_vertex/migration.sql
@@ -0,0 +1,7 @@
+-- Google Vertex uses @ to separate model name and version
+
+UPDATE "models" SET "match_pattern" = '(?i)^(claude-3-haiku(-|@)?20240307)$' WHERE "id" = 'cltr0w45b000008k1407o9qv1';
+
+UPDATE "models" SET "match_pattern" = '(?i)^(claude-3-opus(-|@)?20240229)$' WHERE "id" = 'cltgy0iuw000008le3vod1hhy';
+
+UPDATE "models" SET "match_pattern" = '(?i)^(claude-3-sonnet(-|@)?20240229)$' WHERE "id" = 'cltgy0pp6000108le56se7bl3';
\ No newline at end of file
diff --git a/packages/shared/prisma/migrations/20240604133340_backfill_manual_scores/migration.sql b/packages/shared/prisma/migrations/20240611113517_backfill_manual_score_configs/migration.sql
similarity index 87%
rename from packages/shared/prisma/migrations/20240604133340_backfill_manual_scores/migration.sql
rename to packages/shared/prisma/migrations/20240611113517_backfill_manual_score_configs/migration.sql
index 748b160947..d69cefee06 100644
--- a/packages/shared/prisma/migrations/20240604133340_backfill_manual_scores/migration.sql
+++ b/packages/shared/prisma/migrations/20240611113517_backfill_manual_score_configs/migration.sql
@@ -10,7 +10,7 @@ INSERT INTO score_configs (id,
max_value,
description)
SELECT
- gen_random_uuid () AS id,
+ md5(random()::text || clock_timestamp()::text || s.project_id::text)::uuid AS id,
s.project_id,
'manual-score',
'NUMERIC',
@@ -24,6 +24,7 @@ FROM ( SELECT DISTINCT
scores
WHERE
name = 'manual-score'
+ AND config_id IS NULL
AND source = 'ANNOTATION') s
WHERE
NOT EXISTS (
@@ -47,4 +48,4 @@ FROM
WHERE
scores.project_id = pc.project_id
AND scores.name = 'manual-score';
-COMMIT;
+COMMIT;
\ No newline at end of file
diff --git a/packages/shared/scripts/cleanup.sql b/packages/shared/scripts/cleanup.sql
new file mode 100644
index 0000000000..d1293fadf0
--- /dev/null
+++ b/packages/shared/scripts/cleanup.sql
@@ -0,0 +1,7 @@
+DO $$
+BEGIN
+ IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '_prisma_migrations') THEN
+ DELETE FROM _prisma_migrations
+ WHERE migration_name IN ('20240606090858_pricings_add_latest_gemini_models', '20240530212419_model_price_anthropic_via_google_vertex', '20240604133340_backfill_manual_scores');
+ END IF;
+END $$;
\ No newline at end of file
diff --git a/turbo.json b/turbo.json
index 45c45d3b33..c102d9b5e7 100644
--- a/turbo.json
+++ b/turbo.json
@@ -9,7 +9,9 @@
"start": {
"dependsOn": ["^start"]
},
- "db:migrate": {},
+ "db:migrate": {
+ "cache": false
+ },
"db:deploy": {},
"db:reset": {},
"db:push": {},
diff --git a/web/Dockerfile b/web/Dockerfile
index 578976dc19..a246399b0a 100644
--- a/web/Dockerfile
+++ b/web/Dockerfile
@@ -78,6 +78,7 @@ COPY --from=builder --chown=nextjs:nodejs /app/web/public ./web/public
COPY --from=builder --chown=nextjs:nodejs /app/packages/shared/prisma ./packages/shared/prisma
COPY --chown=nextjs:nodejs ./web/entrypoint.sh ./web/entrypoint.sh
+COPY --chown=nextjs:nodejs ./packages/shared/scripts/cleanup.sql ./packages/shared/scripts/cleanup.sql
RUN chmod +x ./web/entrypoint.sh
USER nextjs
diff --git a/web/entrypoint.sh b/web/entrypoint.sh
index 51d49af930..ae58f4c305 100644
--- a/web/entrypoint.sh
+++ b/web/entrypoint.sh
@@ -1,5 +1,6 @@
#!/bin/sh
+# Run cleanup script before running migrations
# Check if DATABASE_URL is not set
if [ -z "$DATABASE_URL" ]; then
# Check if all required variables are provided
@@ -18,6 +19,8 @@ if [ -z "$DIRECT_URL" ]; then
export DIRECT_URL=$DATABASE_URL
fi
+prisma db execute --url "$DIRECT_URL" --file "./packages/shared/scripts/cleanup.sql"
+
# Apply migrations
prisma migrate deploy --schema=./packages/shared/prisma/schema.prisma
status=$?