SELECT 
*
from metadata_items
WHERE guid like 'plex://episode%'
order by slug;

select * from metadata_items where parent_id=56828;

SELECT 
*
from metadata_items
WHERE guid like 'plex://episode%'
and title='Los terapeutas'
order by slug;


 SELECT 
*
from metadata_items
WHERE title='El coche fantastico'
order by added_at;


select *
from metadata_items
where library_section_id=20;


select library_section_id, guid, slug, title, date_added
from metadata_items
where original_title='Knight Rider';



select *
from metadata_items
order by added_at desc
limit 10;

select *
from metadata_items
where guid='plex://episode/6123babdcd697e002c98e177';


--start
drop trigger fts4_metadata_titles_after_update_icu;

drop trigger fts4_metadata_titles_before_update_icu;

-- update 
UPDATE metadata_items AS DESTINATION
SET refreshed_at = ORIGIN.refreshed_at,
    added_at = ORIGIN.added_at,
    created_at = ORIGIN.created_at,
    updated_at = ORIGIN.updated_at,
    changed_at = ORIGIN.changed_at,
    resources_changed_at = ORIGIN.resources_changed_at
FROM metadata_items AS ORIGIN
WHERE DESTINATION.library_section_id = 4
AND ORIGIN.library_section_id = 33
AND DESTINATION.hash = ORIGIN.hash;


--triggers restore
CREATE TRIGGER fts4_metadata_titles_before_update_icu BEFORE UPDATE ON metadata_items BEGIN DELETE FROM fts4_metadata_titles_icu WHERE docid=old.rowid; END;

CREATE TRIGGER fts4_metadata_titles_after_update_icu AFTER UPDATE ON metadata_items BEGIN INSERT INTO fts4_metadata_titles_icu(docid, title, title_sort, original_title) VALUES(new.rowid, new.title, new.title_sort, new.original_title); END;
