Improved index to respect nulls

This commit is contained in:
Kieran Eglin 2024-04-01 18:22:58 -07:00
parent 4e26253b33
commit 3daf72a161
3 changed files with 16 additions and 4 deletions

View file

@ -1,7 +1,19 @@
defmodule Pinchflat.Repo.Migrations.ReReAddSourceUniquenessIndex do
use Ecto.Migration
def change do
create unique_index(:sources, [:collection_id, :media_profile_id, :title_filter_regex])
def up do
execute """
CREATE UNIQUE INDEX sources_collection_id_media_profile_id_title_filter_regex_index ON sources (
collection_id,
media_profile_id,
IFNULL(title_filter_regex, '')
);
"""
end
def down do
execute """
DROP INDEX sources_collection_id_media_profile_id_title_filter_regex_index;
"""
end
end