mirror of
https://github.com/kieraneglin/pinchflat.git
synced 2026-01-23 02:24:24 +00:00
Improved index to respect nulls
This commit is contained in:
parent
4e26253b33
commit
3daf72a161
3 changed files with 16 additions and 4 deletions
|
|
@ -107,7 +107,7 @@ defmodule Pinchflat.Sources.Source do
|
|||
|> dynamic_default(:uuid, fn _ -> Ecto.UUID.generate() end)
|
||||
|> validate_required(required_fields)
|
||||
|> cast_assoc(:metadata, with: &SourceMetadata.changeset/2, required: false)
|
||||
|> unique_constraint([:collection_id, :media_profile_id, :title_filter_regex])
|
||||
|> unique_constraint([:collection_id, :media_profile_id, :title_filter_regex], error_key: :original_url)
|
||||
end
|
||||
|
||||
@doc false
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ defmodule Pinchflat.SourcesTest do
|
|||
valid_once_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
original_url: "https://www.youtube.com/channel/abc123",
|
||||
title_filter_regex: "TEST"
|
||||
title_filter_regex: nil
|
||||
}
|
||||
|
||||
assert {:ok, %Source{}} = Sources.create_source(valid_once_attrs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue