-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure duplicate player states can never occur
- Loading branch information
Showing
5 changed files
with
155 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
priv/repo/migrations/20250107194334_fix_duplicate_player_states.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Ambry.Repo.Migrations.FixDuplicatePlayerStates do | ||
use Ecto.Migration | ||
|
||
def up do | ||
# deletes older player_states with duplicate media_id | ||
execute """ | ||
DELETE FROM | ||
player_states ps | ||
WHERE | ||
EXISTS ( | ||
SELECT | ||
* | ||
FROM | ||
player_states x | ||
WHERE | ||
x.media_id = ps.media_id | ||
AND x.ctid > ps.ctid | ||
); | ||
""" | ||
|
||
create unique_index(:player_states, [:user_id, :media_id]) | ||
end | ||
|
||
def down do | ||
drop unique_index(:player_states, [:user_id, :media_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters