mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-06 11:36:44 +03:00
**Problem:** - Users upgrading to v3.7.2 encountered database migration failures - Migration 0005 tried to add unique index without handling existing duplicates - Hybrid initialization (manual SQL + Drizzle) caused schema inconsistencies - Error: "UNIQUE constraint failed: repositories.user_id, repositories.full_name" **Solution:** 1. **Fixed Migration 0005:** - Added deduplication step before creating unique index - Removes duplicate (user_id, full_name) entries, keeping most recent - Safely creates unique constraint after cleanup 2. **Removed Hybrid Database Initialization:** - Eliminated 154 lines of manual SQL from docker-entrypoint.sh - Now uses Drizzle exclusively for schema management - Single source of truth prevents schema drift - Migrations run automatically via src/lib/db/index.ts **Testing:** - ✅ Fresh database initialization works - ✅ Duplicate deduplication verified - ✅ Unique constraint properly enforced - ✅ All 6 migrations apply cleanly **Changes:** - docker-entrypoint.sh: Removed manual table creation SQL - drizzle/0005_polite_preak.sql: Added deduplication before index creation Fixes #97
11 lines
451 B
SQL
11 lines
451 B
SQL
-- Step 1: Remove duplicate repositories, keeping the most recently updated one
|
|
-- This handles cases where users have duplicate entries from before the unique constraint
|
|
DELETE FROM repositories
|
|
WHERE rowid NOT IN (
|
|
SELECT MAX(rowid)
|
|
FROM repositories
|
|
GROUP BY user_id, full_name
|
|
);
|
|
--> statement-breakpoint
|
|
-- Step 2: Now create the unique index safely
|
|
CREATE UNIQUE INDEX uniq_repositories_user_full_name ON repositories (user_id, full_name); |