fix(authorization): migration should drop both constraint and index

The original migration only used DROP CONSTRAINT which failed silently
because Prisma created an INDEX instead. Added DROP INDEX as well to
handle both cases in future deployments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-04 03:14:00 -08:00
parent 0991d5d484
commit 52afe72f17
1 changed files with 3 additions and 1 deletions

View File

@ -10,9 +10,11 @@ UPDATE authorization_roles
SET deleted_at = revoked_at
WHERE status = 'REVOKED' AND deleted_at IS NULL;
-- 3. 删除原有的唯一约束(如果存在)
-- 3. 删除原有的唯一约束或索引(如果存在)
-- 注意: Prisma 生成的可能是 CONSTRAINT 或 INDEX需要两种都尝试删除
ALTER TABLE authorization_roles
DROP CONSTRAINT IF EXISTS authorization_roles_account_sequence_role_type_region_code_key;
DROP INDEX IF EXISTS authorization_roles_account_sequence_role_type_region_code_key;
-- 4. 创建部分唯一索引(只对未删除的记录生效)
-- 这是大厂的标准做法,支持软删除后重新创建相同记录