Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
domino14 committed Jan 14, 2025
1 parent 24e8a97 commit ae9a998
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scripts/migrations/migrate_wordvault_lexicon/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,23 @@ func migrate(cfg *config.Config, pool *pgxpool.Pool, fromLex, toLex string) erro
}
defer tx.Rollback(ctx)

changeLexQuery := `UPDATE wordvault_cards SET lexicon_name = $1 WHERE lexicon_name = $2`
changeLexQuery := `
-- 1) DELETE all rows that *would* conflict.
DELETE FROM wordvault_cards c
WHERE c.lexicon_name = $2
AND EXISTS (
SELECT 1
FROM wordvault_cards c2
WHERE c2.user_id = c.user_id
AND c2.lexicon_name = $1
AND c2.alphagram = c.alphagram
);
-- 2) UPDATE the remaining rows
UPDATE wordvault_cards
SET lexicon_name = $1
WHERE lexicon_name = $2;
`

t, err := tx.Exec(ctx, changeLexQuery, toLex, fromLex)
if err != nil {
Expand Down

0 comments on commit ae9a998

Please sign in to comment.