--
-- PostgreSQL database dump
--

\restrict ioCi9akCEb4OTJqqafagnN0ujRzEOChWnb2NQKO5G1mPGHoPiOIWcce58T7EixH

-- Dumped from database version 18.3 (Ubuntu 18.3-1.pgdg25.10+1)
-- Dumped by pg_dump version 18.3 (Ubuntu 18.3-1.pgdg25.10+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: activitylog; Type: SCHEMA; Schema: -; Owner: jellyfin
--

CREATE SCHEMA activitylog;


ALTER SCHEMA activitylog OWNER TO jellyfin;

--
-- Name: authentication; Type: SCHEMA; Schema: -; Owner: jellyfin
--

CREATE SCHEMA authentication;


ALTER SCHEMA authentication OWNER TO jellyfin;

--
-- Name: displaypreferences; Type: SCHEMA; Schema: -; Owner: jellyfin
--

CREATE SCHEMA displaypreferences;


ALTER SCHEMA displaypreferences OWNER TO jellyfin;

--
-- Name: library; Type: SCHEMA; Schema: -; Owner: jellyfin
--

CREATE SCHEMA library;


ALTER SCHEMA library OWNER TO jellyfin;

--
-- Name: pg_repack; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pg_repack WITH SCHEMA public;


--
-- Name: EXTENSION pg_repack; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION pg_repack IS 'Reorganize tables in PostgreSQL databases with minimal locks';


--
-- Name: users; Type: SCHEMA; Schema: -; Owner: jellyfin
--

CREATE SCHEMA users;


ALTER SCHEMA users OWNER TO jellyfin;

--
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;


--
-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION pg_stat_statements IS 'track planning and execution statistics of all SQL statements executed';


SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: activity_logs; Type: TABLE; Schema: activitylog; Owner: jellyfin
--

CREATE TABLE activitylog.activity_logs (
    id integer CONSTRAINT "ActivityLogs_Id_not_null" NOT NULL,
    name character varying(512) CONSTRAINT "ActivityLogs_Name_not_null" NOT NULL,
    overview character varying(512),
    short_overview character varying(512),
    type character varying(256) CONSTRAINT "ActivityLogs_Type_not_null" NOT NULL,
    user_id uuid CONSTRAINT "ActivityLogs_UserId_not_null" NOT NULL,
    item_id character varying(256),
    date_created timestamp with time zone CONSTRAINT "ActivityLogs_DateCreated_not_null" NOT NULL,
    log_severity integer CONSTRAINT "ActivityLogs_LogSeverity_not_null" NOT NULL,
    row_version bigint CONSTRAINT "ActivityLogs_RowVersion_not_null" NOT NULL
);


ALTER TABLE activitylog.activity_logs OWNER TO jellyfin;

--
-- Name: ActivityLogs_Id_seq; Type: SEQUENCE; Schema: activitylog; Owner: jellyfin
--

ALTER TABLE activitylog.activity_logs ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME activitylog."ActivityLogs_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: api_keys; Type: TABLE; Schema: authentication; Owner: jellyfin
--

CREATE TABLE authentication.api_keys (
    id integer CONSTRAINT "ApiKeys_Id_not_null" NOT NULL,
    date_created timestamp with time zone CONSTRAINT "ApiKeys_DateCreated_not_null" NOT NULL,
    date_last_activity timestamp with time zone CONSTRAINT "ApiKeys_DateLastActivity_not_null" NOT NULL,
    name character varying(64) CONSTRAINT "ApiKeys_Name_not_null" NOT NULL,
    access_token text CONSTRAINT "ApiKeys_AccessToken_not_null" NOT NULL
);


ALTER TABLE authentication.api_keys OWNER TO jellyfin;

--
-- Name: ApiKeys_Id_seq; Type: SEQUENCE; Schema: authentication; Owner: jellyfin
--

ALTER TABLE authentication.api_keys ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME authentication."ApiKeys_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: device_options; Type: TABLE; Schema: authentication; Owner: jellyfin
--

CREATE TABLE authentication.device_options (
    id integer CONSTRAINT "DeviceOptions_Id_not_null" NOT NULL,
    device_id text CONSTRAINT "DeviceOptions_DeviceId_not_null" NOT NULL,
    custom_name text
);


ALTER TABLE authentication.device_options OWNER TO jellyfin;

--
-- Name: DeviceOptions_Id_seq; Type: SEQUENCE; Schema: authentication; Owner: jellyfin
--

ALTER TABLE authentication.device_options ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME authentication."DeviceOptions_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: devices; Type: TABLE; Schema: authentication; Owner: jellyfin
--

CREATE TABLE authentication.devices (
    id integer CONSTRAINT "Devices_Id_not_null" NOT NULL,
    user_id uuid CONSTRAINT "Devices_UserId_not_null" NOT NULL,
    access_token text CONSTRAINT "Devices_AccessToken_not_null" NOT NULL,
    app_name character varying(64) CONSTRAINT "Devices_AppName_not_null" NOT NULL,
    app_version character varying(32) CONSTRAINT "Devices_AppVersion_not_null" NOT NULL,
    device_name character varying(64) CONSTRAINT "Devices_DeviceName_not_null" NOT NULL,
    device_id character varying(256) CONSTRAINT "Devices_DeviceId_not_null" NOT NULL,
    is_active boolean CONSTRAINT "Devices_IsActive_not_null" NOT NULL,
    date_created timestamp with time zone CONSTRAINT "Devices_DateCreated_not_null" NOT NULL,
    date_modified timestamp with time zone CONSTRAINT "Devices_DateModified_not_null" NOT NULL,
    date_last_activity timestamp with time zone CONSTRAINT "Devices_DateLastActivity_not_null" NOT NULL
);


ALTER TABLE authentication.devices OWNER TO jellyfin;

--
-- Name: Devices_Id_seq; Type: SEQUENCE; Schema: authentication; Owner: jellyfin
--

ALTER TABLE authentication.devices ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME authentication."Devices_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: custom_item_display_preferences; Type: TABLE; Schema: displaypreferences; Owner: jellyfin
--

CREATE TABLE displaypreferences.custom_item_display_preferences (
    id integer CONSTRAINT "CustomItemDisplayPreferences_Id_not_null" NOT NULL,
    user_id uuid CONSTRAINT "CustomItemDisplayPreferences_UserId_not_null" NOT NULL,
    item_id uuid CONSTRAINT "CustomItemDisplayPreferences_ItemId_not_null" NOT NULL,
    client character varying(32) CONSTRAINT "CustomItemDisplayPreferences_Client_not_null" NOT NULL,
    key text CONSTRAINT "CustomItemDisplayPreferences_Key_not_null" NOT NULL,
    value text
);


ALTER TABLE displaypreferences.custom_item_display_preferences OWNER TO jellyfin;

--
-- Name: CustomItemDisplayPreferences_Id_seq; Type: SEQUENCE; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE displaypreferences.custom_item_display_preferences ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME displaypreferences."CustomItemDisplayPreferences_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: display_preferences; Type: TABLE; Schema: displaypreferences; Owner: jellyfin
--

CREATE TABLE displaypreferences.display_preferences (
    id integer CONSTRAINT "DisplayPreferences_Id_not_null" NOT NULL,
    user_id uuid CONSTRAINT "DisplayPreferences_UserId_not_null" NOT NULL,
    item_id uuid CONSTRAINT "DisplayPreferences_ItemId_not_null" NOT NULL,
    client character varying(32) CONSTRAINT "DisplayPreferences_Client_not_null" NOT NULL,
    show_sidebar boolean CONSTRAINT "DisplayPreferences_ShowSidebar_not_null" NOT NULL,
    show_backdrop boolean CONSTRAINT "DisplayPreferences_ShowBackdrop_not_null" NOT NULL,
    scroll_direction integer CONSTRAINT "DisplayPreferences_ScrollDirection_not_null" NOT NULL,
    index_by integer,
    skip_forward_length integer CONSTRAINT "DisplayPreferences_SkipForwardLength_not_null" NOT NULL,
    skip_backward_length integer CONSTRAINT "DisplayPreferences_SkipBackwardLength_not_null" NOT NULL,
    chromecast_version integer CONSTRAINT "DisplayPreferences_ChromecastVersion_not_null" NOT NULL,
    enable_next_video_info_overlay boolean CONSTRAINT "DisplayPreferences_EnableNextVideoInfoOverlay_not_null" NOT NULL,
    dashboard_theme character varying(32),
    tv_home character varying(32)
);


ALTER TABLE displaypreferences.display_preferences OWNER TO jellyfin;

--
-- Name: DisplayPreferences_Id_seq; Type: SEQUENCE; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE displaypreferences.display_preferences ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME displaypreferences."DisplayPreferences_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: home_sections; Type: TABLE; Schema: displaypreferences; Owner: jellyfin
--

CREATE TABLE displaypreferences.home_sections (
    id integer CONSTRAINT "HomeSection_Id_not_null" NOT NULL,
    display_preferences_id integer CONSTRAINT "HomeSection_DisplayPreferencesId_not_null" NOT NULL,
    "order" integer CONSTRAINT "HomeSection_Order_not_null" NOT NULL,
    type integer CONSTRAINT "HomeSection_Type_not_null" NOT NULL
);


ALTER TABLE displaypreferences.home_sections OWNER TO jellyfin;

--
-- Name: HomeSection_Id_seq; Type: SEQUENCE; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE displaypreferences.home_sections ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME displaypreferences."HomeSection_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: item_display_preferences; Type: TABLE; Schema: displaypreferences; Owner: jellyfin
--

CREATE TABLE displaypreferences.item_display_preferences (
    id integer CONSTRAINT "ItemDisplayPreferences_Id_not_null" NOT NULL,
    user_id uuid CONSTRAINT "ItemDisplayPreferences_UserId_not_null" NOT NULL,
    item_id uuid CONSTRAINT "ItemDisplayPreferences_ItemId_not_null" NOT NULL,
    client character varying(32) CONSTRAINT "ItemDisplayPreferences_Client_not_null" NOT NULL,
    view_type integer CONSTRAINT "ItemDisplayPreferences_ViewType_not_null" NOT NULL,
    remember_indexing boolean CONSTRAINT "ItemDisplayPreferences_RememberIndexing_not_null" NOT NULL,
    index_by integer,
    remember_sorting boolean CONSTRAINT "ItemDisplayPreferences_RememberSorting_not_null" NOT NULL,
    sort_by character varying(64) CONSTRAINT "ItemDisplayPreferences_SortBy_not_null" NOT NULL,
    sort_order integer CONSTRAINT "ItemDisplayPreferences_SortOrder_not_null" NOT NULL
);


ALTER TABLE displaypreferences.item_display_preferences OWNER TO jellyfin;

--
-- Name: ItemDisplayPreferences_Id_seq; Type: SEQUENCE; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE displaypreferences.item_display_preferences ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME displaypreferences."ItemDisplayPreferences_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: image_infos; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.image_infos (
    id integer CONSTRAINT "ImageInfos_Id_not_null" NOT NULL,
    user_id uuid,
    path character varying(512) CONSTRAINT "ImageInfos_Path_not_null" NOT NULL,
    last_modified timestamp with time zone CONSTRAINT "ImageInfos_LastModified_not_null" NOT NULL
);


ALTER TABLE library.image_infos OWNER TO jellyfin;

--
-- Name: ImageInfos_Id_seq; Type: SEQUENCE; Schema: library; Owner: jellyfin
--

ALTER TABLE library.image_infos ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME library."ImageInfos_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: ancestor_ids; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.ancestor_ids (
    parent_item_id uuid CONSTRAINT "AncestorIds_ParentItemId_not_null" NOT NULL,
    item_id uuid CONSTRAINT "AncestorIds_ItemId_not_null" NOT NULL
);


ALTER TABLE library.ancestor_ids OWNER TO jellyfin;

--
-- Name: attachment_stream_infos; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.attachment_stream_infos (
    item_id uuid CONSTRAINT "AttachmentStreamInfos_ItemId_not_null" NOT NULL,
    index integer CONSTRAINT "AttachmentStreamInfos_Index_not_null" NOT NULL,
    codec text,
    codec_tag text,
    comment text,
    filename text,
    mime_type text
);


ALTER TABLE library.attachment_stream_infos OWNER TO jellyfin;

--
-- Name: audio_stream_details; Type: TABLE; Schema: library; Owner: postgres
--

CREATE TABLE library.audio_stream_details (
    item_id uuid CONSTRAINT "AudioStreamDetails_ItemId_not_null" NOT NULL,
    stream_index integer CONSTRAINT "AudioStreamDetails_StreamIndex_not_null" NOT NULL,
    channel_layout text,
    channels integer,
    sample_rate integer,
    is_hearing_impaired boolean
);


ALTER TABLE library.audio_stream_details OWNER TO postgres;

--
-- Name: base_item_audio_extras; Type: TABLE; Schema: library; Owner: postgres
--

CREATE TABLE library.base_item_audio_extras (
    item_id uuid CONSTRAINT "BaseItemAudioExtras_ItemId_not_null" NOT NULL,
    album text,
    artists text,
    album_artists text,
    lufs real,
    normalization_gain real
);


ALTER TABLE library.base_item_audio_extras OWNER TO postgres;

--
-- Name: base_item_image_infos; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.base_item_image_infos (
    id uuid CONSTRAINT "BaseItemImageInfos_Id_not_null" NOT NULL,
    path text CONSTRAINT "BaseItemImageInfos_Path_not_null" NOT NULL,
    date_modified timestamp with time zone,
    image_type integer CONSTRAINT "BaseItemImageInfos_ImageType_not_null" NOT NULL,
    width integer CONSTRAINT "BaseItemImageInfos_Width_not_null" NOT NULL,
    height integer CONSTRAINT "BaseItemImageInfos_Height_not_null" NOT NULL,
    blurhash bytea,
    item_id uuid CONSTRAINT "BaseItemImageInfos_ItemId_not_null" NOT NULL
);


ALTER TABLE library.base_item_image_infos OWNER TO jellyfin;

--
-- Name: base_item_live_tv_extras; Type: TABLE; Schema: library; Owner: postgres
--

CREATE TABLE library.base_item_live_tv_extras (
    item_id uuid CONSTRAINT "BaseItemLiveTvExtras_ItemId_not_null" NOT NULL,
    start_date timestamp with time zone,
    end_date timestamp with time zone,
    episode_title text,
    show_id text,
    external_series_id text,
    external_service_id text,
    audio integer
);


ALTER TABLE library.base_item_live_tv_extras OWNER TO postgres;

--
-- Name: base_item_metadata_fields; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.base_item_metadata_fields (
    id integer CONSTRAINT "BaseItemMetadataFields_Id_not_null" NOT NULL,
    item_id uuid CONSTRAINT "BaseItemMetadataFields_ItemId_not_null" NOT NULL
);


ALTER TABLE library.base_item_metadata_fields OWNER TO jellyfin;

--
-- Name: base_item_providers; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.base_item_providers (
    item_id uuid CONSTRAINT "BaseItemProviders_ItemId_not_null" NOT NULL,
    provider_id text CONSTRAINT "BaseItemProviders_ProviderId_not_null" NOT NULL,
    provider_value text CONSTRAINT "BaseItemProviders_ProviderValue_not_null" NOT NULL
);


ALTER TABLE library.base_item_providers OWNER TO jellyfin;

--
-- Name: base_item_trailer_types; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.base_item_trailer_types (
    id integer CONSTRAINT "BaseItemTrailerTypes_Id_not_null" NOT NULL,
    item_id uuid CONSTRAINT "BaseItemTrailerTypes_ItemId_not_null" NOT NULL
);


ALTER TABLE library.base_item_trailer_types OWNER TO jellyfin;

--
-- Name: base_item_tv_extras; Type: TABLE; Schema: library; Owner: postgres
--

CREATE TABLE library.base_item_tv_extras (
    item_id uuid CONSTRAINT "BaseItemTvExtras_ItemId_not_null" NOT NULL,
    series_id uuid,
    season_id uuid,
    series_name text,
    season_name text,
    series_presentation_unique_key text
);


ALTER TABLE library.base_item_tv_extras OWNER TO postgres;

--
-- Name: base_items; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.base_items (
    id uuid CONSTRAINT "BaseItems_Id_not_null" NOT NULL,
    type text CONSTRAINT "BaseItems_Type_not_null" NOT NULL,
    data text,
    path text,
    channel_id uuid,
    is_movie boolean CONSTRAINT "BaseItems_IsMovie_not_null" NOT NULL,
    community_rating real,
    custom_rating text,
    index_number integer,
    is_locked boolean CONSTRAINT "BaseItems_IsLocked_not_null" NOT NULL,
    name text,
    official_rating text,
    media_type text,
    overview text,
    parent_index_number integer,
    premiere_date timestamp with time zone,
    production_year integer,
    genres text,
    sort_name text,
    forced_sort_name text,
    run_time_ticks bigint,
    date_created timestamp with time zone,
    date_modified timestamp with time zone,
    is_series boolean CONSTRAINT "BaseItems_IsSeries_not_null" NOT NULL,
    is_repeat boolean CONSTRAINT "BaseItems_IsRepeat_not_null" NOT NULL,
    preferred_metadata_language text,
    preferred_metadata_country_code text,
    date_last_refreshed timestamp with time zone,
    date_last_saved timestamp with time zone,
    is_in_mixed_folder boolean CONSTRAINT "BaseItems_IsInMixedFolder_not_null" NOT NULL,
    studios text,
    tags text,
    is_folder boolean CONSTRAINT "BaseItems_IsFolder_not_null" NOT NULL,
    inherited_parental_rating_value integer,
    inherited_parental_rating_sub_value integer,
    unrated_type text,
    critic_rating real,
    clean_name text,
    presentation_unique_key text,
    original_title text,
    primary_version_id text,
    date_last_media_added timestamp with time zone,
    is_virtual_item boolean CONSTRAINT "BaseItems_IsVirtualItem_not_null" NOT NULL,
    tagline text,
    production_locations text,
    extra_ids text,
    total_bitrate integer,
    extra_type integer,
    external_id text,
    owner_id text,
    width integer,
    height integer,
    size bigint,
    parent_id uuid,
    top_parent_id uuid
);


ALTER TABLE library.base_items OWNER TO jellyfin;

--
-- Name: base_items_v; Type: VIEW; Schema: library; Owner: postgres
--

CREATE VIEW library.base_items_v AS
 SELECT b.id,
    b.type,
    b.data,
    b.path,
    b.channel_id,
    b.is_movie,
    b.community_rating,
    b.custom_rating,
    b.index_number,
    b.is_locked,
    b.name,
    b.official_rating,
    b.media_type,
    b.overview,
    b.parent_index_number,
    b.premiere_date,
    b.production_year,
    b.genres,
    b.sort_name,
    b.forced_sort_name,
    b.run_time_ticks,
    b.date_created,
    b.date_modified,
    b.is_series,
    b.is_repeat,
    b.preferred_metadata_language,
    b.preferred_metadata_country_code,
    b.date_last_refreshed,
    b.date_last_saved,
    b.is_in_mixed_folder,
    b.studios,
    b.tags,
    b.is_folder,
    b.inherited_parental_rating_value,
    b.inherited_parental_rating_sub_value,
    b.unrated_type,
    b.critic_rating,
    b.clean_name,
    b.presentation_unique_key,
    b.original_title,
    b.primary_version_id,
    b.date_last_media_added,
    b.is_virtual_item,
    b.tagline,
    b.production_locations,
    b.extra_ids,
    b.total_bitrate,
    b.extra_type,
    b.external_id,
    b.owner_id,
    b.width,
    b.height,
    b.size,
    b.parent_id,
    b.top_parent_id,
    tv.series_id,
    tv.season_id,
    tv.series_name,
    tv.season_name,
    tv.series_presentation_unique_key,
    ltv.start_date,
    ltv.end_date,
    ltv.episode_title,
    ltv.show_id,
    ltv.external_series_id,
    ltv.external_service_id,
    ltv.audio,
    au.album,
    au.artists,
    au.album_artists,
    au.lufs,
    au.normalization_gain
   FROM (((library.base_items b
     LEFT JOIN library.base_item_tv_extras tv ON ((tv.item_id = b.id)))
     LEFT JOIN library.base_item_live_tv_extras ltv ON ((ltv.item_id = b.id)))
     LEFT JOIN library.base_item_audio_extras au ON ((au.item_id = b.id)));


ALTER VIEW library.base_items_v OWNER TO postgres;

--
-- Name: chapters; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.chapters (
    item_id uuid CONSTRAINT "Chapters_ItemId_not_null" NOT NULL,
    chapter_index integer CONSTRAINT "Chapters_ChapterIndex_not_null" NOT NULL,
    start_position_ticks bigint CONSTRAINT "Chapters_StartPositionTicks_not_null" NOT NULL,
    name text,
    image_path text,
    image_date_modified timestamp with time zone
);


ALTER TABLE library.chapters OWNER TO jellyfin;

--
-- Name: people_base_item_map; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.people_base_item_map (
    role text CONSTRAINT "PeopleBaseItemMap_Role_not_null" NOT NULL,
    item_id uuid CONSTRAINT "PeopleBaseItemMap_ItemId_not_null" NOT NULL,
    people_id uuid CONSTRAINT "PeopleBaseItemMap_PeopleId_not_null" NOT NULL,
    sort_order integer,
    list_order integer
);


ALTER TABLE library.people_base_item_map OWNER TO jellyfin;

--
-- Name: peoples; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.peoples (
    id uuid CONSTRAINT "Peoples_Id_not_null" NOT NULL,
    name text CONSTRAINT "Peoples_Name_not_null" NOT NULL,
    person_type text
);


ALTER TABLE library.peoples OWNER TO jellyfin;

--
-- Name: item_people_v; Type: VIEW; Schema: library; Owner: postgres
--

CREATE VIEW library.item_people_v AS
 SELECT b.id AS item_id,
    b.type AS item_type,
    b.name AS item_name,
    tv.series_name,
    b.production_year,
    pe.id AS person_id,
    pe.name AS person_name,
    pe.person_type,
    pm.role,
    pm.sort_order,
    pm.list_order
   FROM (((library.people_base_item_map pm
     JOIN library.base_items b ON ((pm.item_id = b.id)))
     JOIN library.peoples pe ON ((pm.people_id = pe.id)))
     LEFT JOIN library.base_item_tv_extras tv ON ((tv.item_id = b.id)))
  WHERE (b.is_virtual_item = false);


ALTER VIEW library.item_people_v OWNER TO postgres;

--
-- Name: item_providers_v; Type: VIEW; Schema: library; Owner: postgres
--

CREATE VIEW library.item_providers_v AS
 SELECT b.id AS item_id,
    b.type,
    b.name,
    b.original_title,
    b.production_year,
    tv.series_name,
    b.index_number AS episode_number,
    b.parent_index_number AS season_number,
    max(
        CASE
            WHEN (p.provider_id = 'Imdb'::text) THEN p.provider_value
            ELSE NULL::text
        END) AS imdb_id,
    max(
        CASE
            WHEN (p.provider_id = 'Tmdb'::text) THEN p.provider_value
            ELSE NULL::text
        END) AS tmdb_id,
    max(
        CASE
            WHEN (p.provider_id = 'Tvdb'::text) THEN p.provider_value
            ELSE NULL::text
        END) AS tvdb_id,
    max(
        CASE
            WHEN (p.provider_id = 'TvRage'::text) THEN p.provider_value
            ELSE NULL::text
        END) AS tv_rage_id,
    max(
        CASE
            WHEN (p.provider_id = 'MusicBrainzAlbum'::text) THEN p.provider_value
            ELSE NULL::text
        END) AS music_brainz_album_id,
    max(
        CASE
            WHEN (p.provider_id = 'MusicBrainzArtist'::text) THEN p.provider_value
            ELSE NULL::text
        END) AS music_brainz_artist_id,
        CASE
            WHEN (count(
            CASE
                WHEN (p.provider_id <> ALL (ARRAY['Imdb'::text, 'Tmdb'::text, 'Tvdb'::text, 'TvRage'::text, 'MusicBrainzAlbum'::text, 'MusicBrainzArtist'::text])) THEN 1
                ELSE NULL::integer
            END) > 0) THEN (jsonb_object_agg(p.provider_id, p.provider_value) FILTER (WHERE (p.provider_id <> ALL (ARRAY['Imdb'::text, 'Tmdb'::text, 'Tvdb'::text, 'TvRage'::text, 'MusicBrainzAlbum'::text, 'MusicBrainzArtist'::text]))))::text
            ELSE NULL::text
        END AS other_providers
   FROM ((library.base_items b
     LEFT JOIN library.base_item_providers p ON ((b.id = p.item_id)))
     LEFT JOIN library.base_item_tv_extras tv ON ((b.id = tv.item_id)))
  WHERE (b.is_virtual_item = false)
  GROUP BY b.id, b.type, b.name, b.original_title, b.production_year, tv.series_name, b.index_number, b.parent_index_number;


ALTER VIEW library.item_providers_v OWNER TO postgres;

--
-- Name: item_values; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.item_values (
    item_value_id uuid CONSTRAINT "ItemValues_ItemValueId_not_null" NOT NULL,
    type integer CONSTRAINT "ItemValues_Type_not_null" NOT NULL,
    value text CONSTRAINT "ItemValues_Value_not_null" NOT NULL,
    clean_value text CONSTRAINT "ItemValues_CleanValue_not_null" NOT NULL
);


ALTER TABLE library.item_values OWNER TO jellyfin;

--
-- Name: item_values_map; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.item_values_map (
    item_id uuid CONSTRAINT "ItemValuesMap_ItemId_not_null" NOT NULL,
    item_value_id uuid CONSTRAINT "ItemValuesMap_ItemValueId_not_null" NOT NULL
);


ALTER TABLE library.item_values_map OWNER TO jellyfin;

--
-- Name: keyframe_data; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.keyframe_data (
    item_id uuid CONSTRAINT "KeyframeData_ItemId_not_null" NOT NULL,
    total_duration bigint CONSTRAINT "KeyframeData_TotalDuration_not_null" NOT NULL,
    keyframe_ticks bigint[]
);


ALTER TABLE library.keyframe_data OWNER TO jellyfin;

--
-- Name: library_options; Type: TABLE; Schema: library; Owner: postgres
--

CREATE TABLE library.library_options (
    library_path text CONSTRAINT "LibraryOptions_LibraryPath_not_null" NOT NULL,
    options_json jsonb CONSTRAINT "LibraryOptions_OptionsJson_not_null" NOT NULL,
    version integer DEFAULT 1 CONSTRAINT "LibraryOptions_Version_not_null" NOT NULL,
    date_created timestamp with time zone DEFAULT now() CONSTRAINT "LibraryOptions_DateCreated_not_null" NOT NULL,
    date_modified timestamp with time zone DEFAULT now() CONSTRAINT "LibraryOptions_DateModified_not_null" NOT NULL
);


ALTER TABLE library.library_options OWNER TO postgres;

--
-- Name: media_stream_infos; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.media_stream_infos (
    item_id uuid CONSTRAINT "MediaStreamInfos_ItemId_not_null" NOT NULL,
    stream_index integer CONSTRAINT "MediaStreamInfos_StreamIndex_not_null" NOT NULL,
    stream_type integer CONSTRAINT "MediaStreamInfos_StreamType_not_null" NOT NULL,
    codec text,
    language text,
    profile text,
    path text,
    bit_rate integer,
    is_default boolean CONSTRAINT "MediaStreamInfos_IsDefault_not_null" NOT NULL,
    is_forced boolean CONSTRAINT "MediaStreamInfos_IsForced_not_null" NOT NULL,
    is_external boolean CONSTRAINT "MediaStreamInfos_IsExternal_not_null" NOT NULL,
    level real,
    codec_tag text,
    comment text,
    is_avc boolean,
    title text,
    time_base text,
    codec_time_base text
);


ALTER TABLE library.media_stream_infos OWNER TO jellyfin;

--
-- Name: video_stream_details; Type: TABLE; Schema: library; Owner: postgres
--

CREATE TABLE library.video_stream_details (
    item_id uuid CONSTRAINT "VideoStreamDetails_ItemId_not_null" NOT NULL,
    stream_index integer CONSTRAINT "VideoStreamDetails_StreamIndex_not_null" NOT NULL,
    aspect_ratio text,
    is_interlaced boolean,
    height integer,
    width integer,
    average_frame_rate real,
    real_frame_rate real,
    pixel_format text,
    bit_depth integer,
    is_anamorphic boolean,
    ref_frames integer,
    nal_length_size text,
    color_primaries text,
    color_space text,
    color_transfer text,
    dv_version_major integer,
    dv_version_minor integer,
    dv_profile integer,
    dv_level integer,
    rpu_present_flag integer,
    el_present_flag integer,
    bl_present_flag integer,
    dv_bl_signal_compatibility_id integer,
    rotation integer,
    key_frames text,
    hdr10_plus_present_flag boolean
);


ALTER TABLE library.video_stream_details OWNER TO postgres;

--
-- Name: library_summary_v; Type: VIEW; Schema: library; Owner: postgres
--

CREATE VIEW library.library_summary_v AS
 WITH primary_video AS (
         SELECT DISTINCT ON (m.item_id) m.item_id,
            vd.height,
            vd.dv_profile,
            vd.hdr10_plus_present_flag,
            vd.color_transfer
           FROM (library.media_stream_infos m
             JOIN library.video_stream_details vd ON (((vd.item_id = m.item_id) AND (vd.stream_index = m.stream_index))))
          WHERE (m.stream_type = 1)
          ORDER BY m.item_id, m.stream_index
        )
 SELECT b.type,
    count(*) AS item_count,
    count(*) FILTER (WHERE (b.production_year IS NOT NULL)) AS with_year,
    min(b.production_year) AS oldest_year,
    max(b.production_year) AS newest_year,
    round((avg(b.community_rating))::numeric, 2) AS avg_community_rating,
    sum(b.run_time_ticks) AS total_run_time_ticks,
    round((COALESCE(sum(b.run_time_ticks), (0)::numeric) / 600000000.0), 1) AS total_runtime_hours,
    sum(b.size) AS total_size_bytes,
    round((COALESCE(sum(b.size), (0)::numeric) / (1024.0 ^ (3)::numeric)), 2) AS total_size_gb,
    count(*) FILTER (WHERE (pv.height >= 2160)) AS count4_k,
    count(*) FILTER (WHERE ((pv.height >= 1080) AND (pv.height <= 2159))) AS count1080p,
    count(*) FILTER (WHERE ((pv.height >= 720) AND (pv.height <= 1079))) AS count720p,
    count(*) FILTER (WHERE ((pv.height < 720) AND (pv.height IS NOT NULL))) AS count_sd,
    count(*) FILTER (WHERE (pv.dv_profile IS NOT NULL)) AS count_dolby_vision,
    count(*) FILTER (WHERE (pv.hdr10_plus_present_flag = true)) AS count_hdr10_plus,
    count(*) FILTER (WHERE ((pv.color_transfer = 'smpte2084'::text) AND (pv.dv_profile IS NULL) AND (pv.hdr10_plus_present_flag IS NOT TRUE))) AS count_hdr10
   FROM (library.base_items b
     LEFT JOIN primary_video pv ON ((pv.item_id = b.id)))
  WHERE ((b.is_virtual_item = false) AND (b.is_folder = false))
  GROUP BY b.type
  ORDER BY (count(*)) DESC;


ALTER VIEW library.library_summary_v OWNER TO postgres;

--
-- Name: media_segments; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.media_segments (
    id uuid CONSTRAINT "MediaSegments_Id_not_null" NOT NULL,
    item_id uuid CONSTRAINT "MediaSegments_ItemId_not_null" NOT NULL,
    type integer CONSTRAINT "MediaSegments_Type_not_null" NOT NULL,
    end_ticks bigint CONSTRAINT "MediaSegments_EndTicks_not_null" NOT NULL,
    start_ticks bigint CONSTRAINT "MediaSegments_StartTicks_not_null" NOT NULL,
    segment_provider_id text CONSTRAINT "MediaSegments_SegmentProviderId_not_null" NOT NULL
);


ALTER TABLE library.media_segments OWNER TO jellyfin;

--
-- Name: media_stream_infos_v; Type: VIEW; Schema: library; Owner: postgres
--

CREATE VIEW library.media_stream_infos_v AS
 SELECT m.item_id,
    m.stream_index,
    m.stream_type,
    m.codec,
    m.language,
    m.profile,
    m.path,
    m.bit_rate,
    m.is_default,
    m.is_forced,
    m.is_external,
    m.level,
    m.codec_tag,
    m.comment,
    m.is_avc,
    m.title,
    m.time_base,
    m.codec_time_base,
    a.channel_layout,
    a.channels,
    a.sample_rate,
    a.is_hearing_impaired,
    v.aspect_ratio,
    v.is_interlaced,
    v.height,
    v.width,
    v.average_frame_rate,
    v.real_frame_rate,
    v.pixel_format,
    v.bit_depth,
    v.is_anamorphic,
    v.ref_frames,
    v.nal_length_size,
    v.color_primaries,
    v.color_space,
    v.color_transfer,
    v.dv_version_major,
    v.dv_version_minor,
    v.dv_profile,
    v.dv_level,
    v.rpu_present_flag,
    v.el_present_flag,
    v.bl_present_flag,
    v.dv_bl_signal_compatibility_id,
    v.rotation,
    v.key_frames,
    v.hdr10_plus_present_flag
   FROM ((library.media_stream_infos m
     LEFT JOIN library.audio_stream_details a ON (((m.item_id = a.item_id) AND (m.stream_index = a.stream_index))))
     LEFT JOIN library.video_stream_details v ON (((m.item_id = v.item_id) AND (m.stream_index = v.stream_index))));


ALTER VIEW library.media_stream_infos_v OWNER TO postgres;

--
-- Name: trickplay_infos; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.trickplay_infos (
    item_id uuid CONSTRAINT "TrickplayInfos_ItemId_not_null" NOT NULL,
    width integer CONSTRAINT "TrickplayInfos_Width_not_null" NOT NULL,
    height integer CONSTRAINT "TrickplayInfos_Height_not_null" NOT NULL,
    tile_width integer CONSTRAINT "TrickplayInfos_TileWidth_not_null" NOT NULL,
    tile_height integer CONSTRAINT "TrickplayInfos_TileHeight_not_null" NOT NULL,
    thumbnail_count integer CONSTRAINT "TrickplayInfos_ThumbnailCount_not_null" NOT NULL,
    "interval" integer CONSTRAINT "TrickplayInfos_Interval_not_null" NOT NULL,
    bandwidth integer CONSTRAINT "TrickplayInfos_Bandwidth_not_null" NOT NULL
);


ALTER TABLE library.trickplay_infos OWNER TO jellyfin;

--
-- Name: user_data; Type: TABLE; Schema: library; Owner: jellyfin
--

CREATE TABLE library.user_data (
    custom_data_key text CONSTRAINT "UserData_CustomDataKey_not_null" NOT NULL,
    item_id uuid CONSTRAINT "UserData_ItemId_not_null" NOT NULL,
    user_id uuid CONSTRAINT "UserData_UserId_not_null" NOT NULL,
    rating double precision,
    playback_position_ticks bigint CONSTRAINT "UserData_PlaybackPositionTicks_not_null" NOT NULL,
    play_count integer CONSTRAINT "UserData_PlayCount_not_null" NOT NULL,
    is_favorite boolean CONSTRAINT "UserData_IsFavorite_not_null" NOT NULL,
    last_played_date timestamp with time zone,
    played boolean CONSTRAINT "UserData_Played_not_null" NOT NULL,
    audio_stream_index integer,
    subtitle_stream_index integer,
    likes boolean,
    retention_date timestamp with time zone
);


ALTER TABLE library.user_data OWNER TO jellyfin;

--
-- Name: users; Type: TABLE; Schema: users; Owner: jellyfin
--

CREATE TABLE users.users (
    id uuid CONSTRAINT "Users_Id_not_null" NOT NULL,
    username character varying(255) CONSTRAINT "Users_Username_not_null" NOT NULL,
    password character varying(65535),
    must_update_password boolean CONSTRAINT "Users_MustUpdatePassword_not_null" NOT NULL,
    audio_language_preference character varying(255),
    authentication_provider_id character varying(255) CONSTRAINT "Users_AuthenticationProviderId_not_null" NOT NULL,
    password_reset_provider_id character varying(255) CONSTRAINT "Users_PasswordResetProviderId_not_null" NOT NULL,
    invalid_login_attempt_count integer CONSTRAINT "Users_InvalidLoginAttemptCount_not_null" NOT NULL,
    last_activity_date timestamp with time zone,
    last_login_date timestamp with time zone,
    login_attempts_before_lockout integer,
    max_active_sessions integer CONSTRAINT "Users_MaxActiveSessions_not_null" NOT NULL,
    subtitle_mode integer CONSTRAINT "Users_SubtitleMode_not_null" NOT NULL,
    play_default_audio_track boolean CONSTRAINT "Users_PlayDefaultAudioTrack_not_null" NOT NULL,
    subtitle_language_preference character varying(255),
    display_missing_episodes boolean CONSTRAINT "Users_DisplayMissingEpisodes_not_null" NOT NULL,
    display_collections_view boolean CONSTRAINT "Users_DisplayCollectionsView_not_null" NOT NULL,
    enable_local_password boolean CONSTRAINT "Users_EnableLocalPassword_not_null" NOT NULL,
    hide_played_in_latest boolean CONSTRAINT "Users_HidePlayedInLatest_not_null" NOT NULL,
    remember_audio_selections boolean CONSTRAINT "Users_RememberAudioSelections_not_null" NOT NULL,
    remember_subtitle_selections boolean CONSTRAINT "Users_RememberSubtitleSelections_not_null" NOT NULL,
    enable_next_episode_auto_play boolean CONSTRAINT "Users_EnableNextEpisodeAutoPlay_not_null" NOT NULL,
    enable_auto_login boolean CONSTRAINT "Users_EnableAutoLogin_not_null" NOT NULL,
    enable_user_preference_access boolean CONSTRAINT "Users_EnableUserPreferenceAccess_not_null" NOT NULL,
    max_parental_rating_score integer,
    max_parental_rating_sub_score integer,
    remote_client_bitrate_limit integer,
    internal_id bigint CONSTRAINT "Users_InternalId_not_null" NOT NULL,
    sync_play_access integer CONSTRAINT "Users_SyncPlayAccess_not_null" NOT NULL,
    cast_receiver_id character varying(32),
    row_version bigint CONSTRAINT "Users_RowVersion_not_null" NOT NULL
);


ALTER TABLE users.users OWNER TO jellyfin;

--
-- Name: user_playback_history_v; Type: VIEW; Schema: library; Owner: postgres
--

CREATE VIEW library.user_playback_history_v AS
 SELECT u.username,
    u.id AS user_id,
    b.name AS item_name,
    b.type AS item_type,
    tv.series_name,
    tv.season_name,
    b.index_number AS episode_number,
    b.parent_index_number AS season_number,
    b.production_year,
    b.run_time_ticks,
    ud.item_id,
    ud.played,
    ud.play_count,
    ud.last_played_date,
    ud.playback_position_ticks,
        CASE
            WHEN (b.run_time_ticks > 0) THEN round((((ud.playback_position_ticks)::numeric * (100)::numeric) / (b.run_time_ticks)::numeric), 1)
            ELSE NULL::numeric
        END AS progress_pct,
    ud.is_favorite,
    ud.rating,
    ud.audio_stream_index,
    ud.subtitle_stream_index
   FROM (((library.user_data ud
     JOIN library.base_items b ON ((ud.item_id = b.id)))
     JOIN users.users u ON ((ud.user_id = u.id)))
     LEFT JOIN library.base_item_tv_extras tv ON ((tv.item_id = b.id)))
  WHERE (ud.custom_data_key = ''::text);


ALTER VIEW library.user_playback_history_v OWNER TO postgres;

--
-- Name: video_items_v; Type: VIEW; Schema: library; Owner: postgres
--

CREATE VIEW library.video_items_v AS
 SELECT b.id AS item_id,
    b.type,
    b.name,
    b.original_title,
    b.production_year,
    b.official_rating,
    b.community_rating,
    b.run_time_ticks,
    b.path,
    b.date_created,
    b.date_modified,
    tv.series_name,
    tv.season_name,
    b.index_number AS episode_number,
    b.parent_index_number AS season_number,
    b.total_bitrate,
    b.size,
    m.codec AS video_codec,
    m.profile AS video_profile,
    vd.width,
    vd.height,
    vd.average_frame_rate,
    vd.bit_depth,
    vd.pixel_format,
    vd.color_space,
    vd.color_transfer,
    vd.color_primaries,
    vd.is_interlaced,
    vd.is_anamorphic,
    vd.aspect_ratio,
    (vd.dv_profile IS NOT NULL) AS is_dolby_vision,
    vd.hdr10_plus_present_flag AS is_hdr10_plus,
        CASE
            WHEN (vd.dv_profile IS NOT NULL) THEN 'Dolby Vision'::text
            WHEN (vd.hdr10_plus_present_flag = true) THEN 'HDR10+'::text
            WHEN (vd.color_transfer = 'smpte2084'::text) THEN 'HDR10'::text
            WHEN (vd.color_transfer = 'arib-std-b67'::text) THEN 'HLG'::text
            ELSE 'SDR'::text
        END AS hdr_format,
    ( SELECT count(*) AS count
           FROM library.media_stream_infos ms
          WHERE ((ms.item_id = b.id) AND (ms.stream_type = 0))) AS audio_track_count,
    ( SELECT count(*) AS count
           FROM library.media_stream_infos ms
          WHERE ((ms.item_id = b.id) AND (ms.stream_type = 2))) AS subtitle_track_count
   FROM (((library.base_items b
     JOIN LATERAL ( SELECT ms.stream_index,
            ms.codec,
            ms.profile
           FROM library.media_stream_infos ms
          WHERE ((ms.item_id = b.id) AND (ms.stream_type = 1))
          ORDER BY ms.stream_index
         LIMIT 1) m ON (true))
     JOIN library.video_stream_details vd ON (((vd.item_id = b.id) AND (vd.stream_index = m.stream_index))))
     LEFT JOIN library.base_item_tv_extras tv ON ((tv.item_id = b.id)))
  WHERE ((b.is_virtual_item = false) AND (b.is_folder = false));


ALTER VIEW library.video_items_v OWNER TO postgres;

--
-- Name: __EFMigrationsHistory; Type: TABLE; Schema: public; Owner: jellyfin
--

CREATE TABLE public."__EFMigrationsHistory" (
    migration_id character varying(150) CONSTRAINT "__EFMigrationsHistory_MigrationId_not_null" NOT NULL,
    product_version character varying(32) CONSTRAINT "__EFMigrationsHistory_ProductVersion_not_null" NOT NULL
);


ALTER TABLE public."__EFMigrationsHistory" OWNER TO jellyfin;

--
-- Name: __ef_migrations_history; Type: TABLE; Schema: public; Owner: jellyfin
--

CREATE TABLE public.__ef_migrations_history (
    migration_id character varying(150) NOT NULL,
    product_version character varying(32) NOT NULL
);


ALTER TABLE public.__ef_migrations_history OWNER TO jellyfin;

--
-- Name: __efmigrationshistory; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.__efmigrationshistory (
    migrationid character varying(150) NOT NULL,
    productversion character varying(32) NOT NULL
);


ALTER TABLE public.__efmigrationshistory OWNER TO postgres;

--
-- Name: bloat_tables; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.bloat_tables (
    count bigint
);


ALTER TABLE public.bloat_tables OWNER TO postgres;

--
-- Name: access_schedules; Type: TABLE; Schema: users; Owner: jellyfin
--

CREATE TABLE users.access_schedules (
    id integer CONSTRAINT "AccessSchedules_Id_not_null" NOT NULL,
    user_id uuid CONSTRAINT "AccessSchedules_UserId_not_null" NOT NULL,
    day_of_week integer CONSTRAINT "AccessSchedules_DayOfWeek_not_null" NOT NULL,
    start_hour double precision CONSTRAINT "AccessSchedules_StartHour_not_null" NOT NULL,
    end_hour double precision CONSTRAINT "AccessSchedules_EndHour_not_null" NOT NULL
);


ALTER TABLE users.access_schedules OWNER TO jellyfin;

--
-- Name: AccessSchedules_Id_seq; Type: SEQUENCE; Schema: users; Owner: jellyfin
--

ALTER TABLE users.access_schedules ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME users."AccessSchedules_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: permissions; Type: TABLE; Schema: users; Owner: jellyfin
--

CREATE TABLE users.permissions (
    id integer CONSTRAINT "Permissions_Id_not_null" NOT NULL,
    user_id uuid,
    kind integer CONSTRAINT "Permissions_Kind_not_null" NOT NULL,
    value boolean CONSTRAINT "Permissions_Value_not_null" NOT NULL,
    row_version bigint CONSTRAINT "Permissions_RowVersion_not_null" NOT NULL,
    permission_permissions_guid uuid
);


ALTER TABLE users.permissions OWNER TO jellyfin;

--
-- Name: Permissions_Id_seq; Type: SEQUENCE; Schema: users; Owner: jellyfin
--

ALTER TABLE users.permissions ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME users."Permissions_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: preferences; Type: TABLE; Schema: users; Owner: jellyfin
--

CREATE TABLE users.preferences (
    id integer CONSTRAINT "Preferences_Id_not_null" NOT NULL,
    user_id uuid,
    kind integer CONSTRAINT "Preferences_Kind_not_null" NOT NULL,
    value character varying(65535) CONSTRAINT "Preferences_Value_not_null" NOT NULL,
    row_version bigint CONSTRAINT "Preferences_RowVersion_not_null" NOT NULL,
    preference_preferences_guid uuid
);


ALTER TABLE users.preferences OWNER TO jellyfin;

--
-- Name: Preferences_Id_seq; Type: SEQUENCE; Schema: users; Owner: jellyfin
--

ALTER TABLE users.preferences ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME users."Preferences_Id_seq"
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: activity_logs PK_ActivityLogs; Type: CONSTRAINT; Schema: activitylog; Owner: jellyfin
--

ALTER TABLE ONLY activitylog.activity_logs
    ADD CONSTRAINT "PK_ActivityLogs" PRIMARY KEY (id);


--
-- Name: api_keys PK_ApiKeys; Type: CONSTRAINT; Schema: authentication; Owner: jellyfin
--

ALTER TABLE ONLY authentication.api_keys
    ADD CONSTRAINT "PK_ApiKeys" PRIMARY KEY (id);


--
-- Name: device_options PK_DeviceOptions; Type: CONSTRAINT; Schema: authentication; Owner: jellyfin
--

ALTER TABLE ONLY authentication.device_options
    ADD CONSTRAINT "PK_DeviceOptions" PRIMARY KEY (id);


--
-- Name: devices PK_Devices; Type: CONSTRAINT; Schema: authentication; Owner: jellyfin
--

ALTER TABLE ONLY authentication.devices
    ADD CONSTRAINT "PK_Devices" PRIMARY KEY (id);


--
-- Name: custom_item_display_preferences PK_CustomItemDisplayPreferences; Type: CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.custom_item_display_preferences
    ADD CONSTRAINT "PK_CustomItemDisplayPreferences" PRIMARY KEY (id);


--
-- Name: display_preferences PK_DisplayPreferences; Type: CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.display_preferences
    ADD CONSTRAINT "PK_DisplayPreferences" PRIMARY KEY (id);


--
-- Name: home_sections PK_HomeSection; Type: CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.home_sections
    ADD CONSTRAINT "PK_HomeSection" PRIMARY KEY (id);


--
-- Name: item_display_preferences PK_ItemDisplayPreferences; Type: CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.item_display_preferences
    ADD CONSTRAINT "PK_ItemDisplayPreferences" PRIMARY KEY (id);


--
-- Name: base_item_image_infos BaseItemImageInfos_pkey; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_image_infos
    ADD CONSTRAINT "BaseItemImageInfos_pkey" PRIMARY KEY (id);


--
-- Name: ancestor_ids PK_AncestorIds; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.ancestor_ids
    ADD CONSTRAINT "PK_AncestorIds" PRIMARY KEY (item_id, parent_item_id);


--
-- Name: attachment_stream_infos PK_AttachmentStreamInfos; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.attachment_stream_infos
    ADD CONSTRAINT "PK_AttachmentStreamInfos" PRIMARY KEY (item_id, index);


--
-- Name: audio_stream_details PK_AudioStreamDetails; Type: CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.audio_stream_details
    ADD CONSTRAINT "PK_AudioStreamDetails" PRIMARY KEY (item_id, stream_index);


--
-- Name: base_item_audio_extras PK_BaseItemAudioExtras; Type: CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.base_item_audio_extras
    ADD CONSTRAINT "PK_BaseItemAudioExtras" PRIMARY KEY (item_id);


--
-- Name: base_item_live_tv_extras PK_BaseItemLiveTvExtras; Type: CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.base_item_live_tv_extras
    ADD CONSTRAINT "PK_BaseItemLiveTvExtras" PRIMARY KEY (item_id);


--
-- Name: base_item_metadata_fields PK_BaseItemMetadataFields; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_metadata_fields
    ADD CONSTRAINT "PK_BaseItemMetadataFields" PRIMARY KEY (id, item_id);


--
-- Name: base_item_providers PK_BaseItemProviders; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_providers
    ADD CONSTRAINT "PK_BaseItemProviders" PRIMARY KEY (item_id, provider_id);


--
-- Name: base_item_trailer_types PK_BaseItemTrailerTypes; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_trailer_types
    ADD CONSTRAINT "PK_BaseItemTrailerTypes" PRIMARY KEY (id, item_id);


--
-- Name: base_item_tv_extras PK_BaseItemTvExtras; Type: CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.base_item_tv_extras
    ADD CONSTRAINT "PK_BaseItemTvExtras" PRIMARY KEY (item_id);


--
-- Name: base_items PK_BaseItems; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_items
    ADD CONSTRAINT "PK_BaseItems" PRIMARY KEY (id);


--
-- Name: chapters PK_Chapters; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.chapters
    ADD CONSTRAINT "PK_Chapters" PRIMARY KEY (item_id, chapter_index);


--
-- Name: image_infos PK_ImageInfos; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.image_infos
    ADD CONSTRAINT "PK_ImageInfos" PRIMARY KEY (id);


--
-- Name: item_values PK_ItemValues; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.item_values
    ADD CONSTRAINT "PK_ItemValues" PRIMARY KEY (item_value_id);


--
-- Name: keyframe_data PK_KeyframeData; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.keyframe_data
    ADD CONSTRAINT "PK_KeyframeData" PRIMARY KEY (item_id);


--
-- Name: library_options PK_LibraryOptions; Type: CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.library_options
    ADD CONSTRAINT "PK_LibraryOptions" PRIMARY KEY (library_path);


--
-- Name: media_segments PK_MediaSegments; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.media_segments
    ADD CONSTRAINT "PK_MediaSegments" PRIMARY KEY (id);


--
-- Name: media_stream_infos PK_MediaStreamInfos; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.media_stream_infos
    ADD CONSTRAINT "PK_MediaStreamInfos" PRIMARY KEY (item_id, stream_index);


--
-- Name: peoples PK_Peoples; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.peoples
    ADD CONSTRAINT "PK_Peoples" PRIMARY KEY (id);


--
-- Name: trickplay_infos PK_TrickplayInfos; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.trickplay_infos
    ADD CONSTRAINT "PK_TrickplayInfos" PRIMARY KEY (item_id, width);


--
-- Name: user_data PK_UserData; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.user_data
    ADD CONSTRAINT "PK_UserData" PRIMARY KEY (item_id, user_id, custom_data_key);


--
-- Name: video_stream_details PK_VideoStreamDetails; Type: CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.video_stream_details
    ADD CONSTRAINT "PK_VideoStreamDetails" PRIMARY KEY (item_id, stream_index);


--
-- Name: item_values_map pk_itemvaluesmap; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.item_values_map
    ADD CONSTRAINT pk_itemvaluesmap PRIMARY KEY (item_value_id, item_id);


--
-- Name: people_base_item_map pk_peoplebaseitemmap; Type: CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.people_base_item_map
    ADD CONSTRAINT pk_peoplebaseitemmap PRIMARY KEY (item_id, people_id, role);


--
-- Name: __EFMigrationsHistory PK___EFMigrationsHistory; Type: CONSTRAINT; Schema: public; Owner: jellyfin
--

ALTER TABLE ONLY public."__EFMigrationsHistory"
    ADD CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY (migration_id);


--
-- Name: __efmigrationshistory pk___efmigrationshistory; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.__efmigrationshistory
    ADD CONSTRAINT pk___efmigrationshistory PRIMARY KEY (migrationid);


--
-- Name: access_schedules PK_AccessSchedules; Type: CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.access_schedules
    ADD CONSTRAINT "PK_AccessSchedules" PRIMARY KEY (id);


--
-- Name: permissions PK_Permissions; Type: CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.permissions
    ADD CONSTRAINT "PK_Permissions" PRIMARY KEY (id);


--
-- Name: preferences PK_Preferences; Type: CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.preferences
    ADD CONSTRAINT "PK_Preferences" PRIMARY KEY (id);


--
-- Name: users PK_Users; Type: CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.users
    ADD CONSTRAINT "PK_Users" PRIMARY KEY (id);


--
-- Name: IX_ActivityLogs_DateCreated; Type: INDEX; Schema: activitylog; Owner: jellyfin
--

CREATE INDEX "IX_ActivityLogs_DateCreated" ON activitylog.activity_logs USING btree (date_created);


--
-- Name: idx_activitylogs_userid_datecreated; Type: INDEX; Schema: activitylog; Owner: jellyfin
--

CREATE INDEX idx_activitylogs_userid_datecreated ON activitylog.activity_logs USING btree (user_id, date_created DESC) WHERE (user_id IS NOT NULL);


--
-- Name: ix_activitylogs_datecreated; Type: INDEX; Schema: activitylog; Owner: jellyfin
--

CREATE INDEX ix_activitylogs_datecreated ON activitylog.activity_logs USING btree (date_created);


--
-- Name: IX_ApiKeys_AccessToken; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_ApiKeys_AccessToken" ON authentication.api_keys USING btree (access_token);


--
-- Name: IX_DeviceOptions_DeviceId; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_DeviceOptions_DeviceId" ON authentication.device_options USING btree (device_id);


--
-- Name: IX_Devices_AccessToken_DateLastActivity; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX "IX_Devices_AccessToken_DateLastActivity" ON authentication.devices USING btree (access_token, date_last_activity);


--
-- Name: IX_Devices_DeviceId; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX "IX_Devices_DeviceId" ON authentication.devices USING btree (device_id);


--
-- Name: IX_Devices_DeviceId_DateLastActivity; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX "IX_Devices_DeviceId_DateLastActivity" ON authentication.devices USING btree (device_id, date_last_activity);


--
-- Name: IX_Devices_UserId_DeviceId; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX "IX_Devices_UserId_DeviceId" ON authentication.devices USING btree (user_id, device_id);


--
-- Name: ix_apikeys_accesstoken; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_apikeys_accesstoken ON authentication.api_keys USING btree (access_token);


--
-- Name: ix_deviceoptions_deviceid; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_deviceoptions_deviceid ON authentication.device_options USING btree (device_id);


--
-- Name: ix_devices_accesstoken_datelastactivity; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX ix_devices_accesstoken_datelastactivity ON authentication.devices USING btree (access_token, date_last_activity);


--
-- Name: ix_devices_deviceid; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX ix_devices_deviceid ON authentication.devices USING btree (device_id);


--
-- Name: ix_devices_deviceid_datelastactivity; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX ix_devices_deviceid_datelastactivity ON authentication.devices USING btree (device_id, date_last_activity);


--
-- Name: ix_devices_userid_deviceid; Type: INDEX; Schema: authentication; Owner: jellyfin
--

CREATE INDEX ix_devices_userid_deviceid ON authentication.devices USING btree (user_id, device_id);


--
-- Name: IX_CustomItemDisplayPreferences_UserId_ItemId_Client_Key; Type: INDEX; Schema: displaypreferences; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_CustomItemDisplayPreferences_UserId_ItemId_Client_Key" ON displaypreferences.custom_item_display_preferences USING btree (user_id, item_id, client, key);


--
-- Name: IX_DisplayPreferences_UserId_ItemId_Client; Type: INDEX; Schema: displaypreferences; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_DisplayPreferences_UserId_ItemId_Client" ON displaypreferences.display_preferences USING btree (user_id, item_id, client);


--
-- Name: IX_HomeSection_DisplayPreferencesId; Type: INDEX; Schema: displaypreferences; Owner: jellyfin
--

CREATE INDEX "IX_HomeSection_DisplayPreferencesId" ON displaypreferences.home_sections USING btree (display_preferences_id);


--
-- Name: IX_ItemDisplayPreferences_UserId; Type: INDEX; Schema: displaypreferences; Owner: jellyfin
--

CREATE INDEX "IX_ItemDisplayPreferences_UserId" ON displaypreferences.item_display_preferences USING btree (user_id);


--
-- Name: ix_displaypreferences_userid_itemid_client; Type: INDEX; Schema: displaypreferences; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_displaypreferences_userid_itemid_client ON displaypreferences.display_preferences USING btree (user_id, item_id, client);


--
-- Name: ix_homesection_displaypreferencesid; Type: INDEX; Schema: displaypreferences; Owner: jellyfin
--

CREATE INDEX ix_homesection_displaypreferencesid ON displaypreferences.home_sections USING btree (display_preferences_id);


--
-- Name: ix_itemdisplaypreferences_userid; Type: INDEX; Schema: displaypreferences; Owner: jellyfin
--

CREATE INDEX ix_itemdisplaypreferences_userid ON displaypreferences.item_display_preferences USING btree (user_id);


--
-- Name: IX_BaseItemImageInfos_ItemId; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_BaseItemImageInfos_ItemId" ON library.base_item_image_infos USING btree (item_id);


--
-- Name: IX_BaseItemLiveTvExtras_EndDate; Type: INDEX; Schema: library; Owner: postgres
--

CREATE INDEX "IX_BaseItemLiveTvExtras_EndDate" ON library.base_item_live_tv_extras USING btree (end_date);


--
-- Name: IX_BaseItemLiveTvExtras_StartDate; Type: INDEX; Schema: library; Owner: postgres
--

CREATE INDEX "IX_BaseItemLiveTvExtras_StartDate" ON library.base_item_live_tv_extras USING btree (start_date);


--
-- Name: IX_BaseItemMetadataFields_ItemId; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_BaseItemMetadataFields_ItemId" ON library.base_item_metadata_fields USING btree (item_id);


--
-- Name: IX_BaseItemTrailerTypes_ItemId; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_BaseItemTrailerTypes_ItemId" ON library.base_item_trailer_types USING btree (item_id);


--
-- Name: IX_BaseItemTvExtras_SeriesId; Type: INDEX; Schema: library; Owner: postgres
--

CREATE INDEX "IX_BaseItemTvExtras_SeriesId" ON library.base_item_tv_extras USING btree (series_id);


--
-- Name: IX_BaseItemTvExtras_SeriesPresentationUniqueKey; Type: INDEX; Schema: library; Owner: postgres
--

CREATE INDEX "IX_BaseItemTvExtras_SeriesPresentationUniqueKey" ON library.base_item_tv_extras USING btree (series_presentation_unique_key);


--
-- Name: IX_BaseItems_Id_Type_IsFolder_IsVirtualItem; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_BaseItems_Id_Type_IsFolder_IsVirtualItem" ON library.base_items USING btree (id, type, is_folder, is_virtual_item);


--
-- Name: IX_BaseItems_ParentId; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_BaseItems_ParentId" ON library.base_items USING btree (parent_id);


--
-- Name: IX_BaseItems_Type_TopParentId_Id; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_BaseItems_Type_TopParentId_Id" ON library.base_items USING btree (type, top_parent_id, id);


--
-- Name: IX_ImageInfos_UserId; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_ImageInfos_UserId" ON library.image_infos USING btree (user_id);


--
-- Name: IX_ItemValues_Type_CleanValue; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_ItemValues_Type_CleanValue" ON library.item_values USING btree (type, clean_value);


--
-- Name: IX_ItemValues_Type_Value; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_ItemValues_Type_Value" ON library.item_values USING btree (type, value);


--
-- Name: IX_LibraryOptions_DateModified; Type: INDEX; Schema: library; Owner: postgres
--

CREATE INDEX "IX_LibraryOptions_DateModified" ON library.library_options USING btree (date_modified DESC);


--
-- Name: IX_UserData_ItemId_UserId_IsFavorite; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_UserData_ItemId_UserId_IsFavorite" ON library.user_data USING btree (item_id, user_id, is_favorite);


--
-- Name: IX_UserData_ItemId_UserId_LastPlayedDate; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_UserData_ItemId_UserId_LastPlayedDate" ON library.user_data USING btree (item_id, user_id, last_played_date);


--
-- Name: IX_UserData_ItemId_UserId_PlaybackPositionTicks; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_UserData_ItemId_UserId_PlaybackPositionTicks" ON library.user_data USING btree (item_id, user_id, playback_position_ticks);


--
-- Name: IX_UserData_ItemId_UserId_Played; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX "IX_UserData_ItemId_UserId_Played" ON library.user_data USING btree (item_id, user_id, played);


--
-- Name: baseitemproviders_providerid_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitemproviders_providerid_idx ON library.base_item_providers USING btree (provider_id, item_id);


--
-- Name: baseitemproviders_providervalue_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitemproviders_providervalue_idx ON library.base_item_providers USING btree (provider_value, provider_id);


--
-- Name: baseitems_communityrating_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitems_communityrating_idx ON library.base_items USING btree (community_rating DESC);


--
-- Name: baseitems_datecreated_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitems_datecreated_idx ON library.base_items USING btree (date_created DESC);


--
-- Name: baseitems_datemodified_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitems_datemodified_idx ON library.base_items USING btree (date_modified DESC);


--
-- Name: baseitems_premieredate_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitems_premieredate_idx ON library.base_items USING btree (premiere_date DESC);


--
-- Name: baseitems_productionyear_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitems_productionyear_idx ON library.base_items USING btree (production_year DESC);


--
-- Name: baseitems_sortname_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitems_sortname_idx ON library.base_items USING btree (sort_name);


--
-- Name: baseitems_topparentid_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX baseitems_topparentid_idx ON library.base_items USING btree (top_parent_id, type);


--
-- Name: idx_baseitems_datecreated_filtered; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_baseitems_datecreated_filtered ON library.base_items USING btree (date_created DESC, type, is_virtual_item) WHERE ((date_created IS NOT NULL) AND (is_virtual_item = false));


--
-- Name: idx_baseitems_presentationuniquekey_episodes; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_baseitems_presentationuniquekey_episodes ON library.base_items USING btree (presentation_unique_key, top_parent_id, is_virtual_item) WHERE ((type = 'MediaBrowser.Controller.Entities.TV.Episode'::text) AND (presentation_unique_key IS NOT NULL));


--
-- Name: idx_baseitems_topparentid_isfolder; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_baseitems_topparentid_isfolder ON library.base_items USING btree (top_parent_id, is_folder, is_virtual_item) WHERE (top_parent_id IS NOT NULL);


--
-- Name: idx_baseitems_type_isvirtualitem_topparentid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_baseitems_type_isvirtualitem_topparentid ON library.base_items USING btree (type, is_virtual_item, top_parent_id) WHERE (is_virtual_item = false);


--
-- Name: idx_itemvalues_cleanvalue; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_itemvalues_cleanvalue ON library.item_values USING btree (clean_value) WHERE (clean_value IS NOT NULL);


--
-- Name: idx_itemvalues_id_cleanvalue; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_itemvalues_id_cleanvalue ON library.item_values USING btree (item_value_id, clean_value);


--
-- Name: idx_itemvalues_type_value_expr; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_itemvalues_type_value_expr ON library.item_values USING btree ((((type)::text || value)));


--
-- Name: idx_itemvalues_value; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_itemvalues_value ON library.item_values USING btree (value) WHERE (value IS NOT NULL);


--
-- Name: idx_itemvaluesmap_itemvalueid_itemid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX idx_itemvaluesmap_itemvalueid_itemid ON library.item_values_map USING btree (item_value_id, item_id);


--
-- Name: ix_ancestorids_parentitemid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_ancestorids_parentitemid ON library.ancestor_ids USING btree (parent_item_id);


--
-- Name: ix_baseitemimageinfos_itemid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitemimageinfos_itemid ON library.base_item_image_infos USING btree (item_id);


--
-- Name: ix_baseitemmetadatafields_itemid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitemmetadatafields_itemid ON library.base_item_metadata_fields USING btree (item_id);


--
-- Name: ix_baseitemproviders_providerid_providervalue_itemid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitemproviders_providerid_providervalue_itemid ON library.base_item_providers USING btree (provider_id, provider_value, item_id);


--
-- Name: ix_baseitems_id_type_isfolder_isvirtualitem; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitems_id_type_isfolder_isvirtualitem ON library.base_items USING btree (id, type, is_folder, is_virtual_item);


--
-- Name: ix_baseitems_path; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitems_path ON library.base_items USING btree (path);


--
-- Name: ix_baseitems_presentationuniquekey; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitems_presentationuniquekey ON library.base_items USING btree (presentation_unique_key);


--
-- Name: ix_baseitems_topparentid_id; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitems_topparentid_id ON library.base_items USING btree (top_parent_id, id);


--
-- Name: ix_baseitems_type_topparentid_id; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitems_type_topparentid_id ON library.base_items USING btree (type, top_parent_id, id);


--
-- Name: ix_baseitems_type_topparentid_presentationuniquekey; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitems_type_topparentid_presentationuniquekey ON library.base_items USING btree (type, top_parent_id, presentation_unique_key);


--
-- Name: ix_baseitemtrailertypes_itemid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_baseitemtrailertypes_itemid ON library.base_item_trailer_types USING btree (item_id);


--
-- Name: ix_imageinfos_userid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_imageinfos_userid ON library.image_infos USING btree (user_id);


--
-- Name: ix_itemvalues_type_cleanvalue; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_itemvalues_type_cleanvalue ON library.item_values USING btree (type, clean_value);


--
-- Name: ix_itemvalues_type_value; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_itemvalues_type_value ON library.item_values USING btree (type, value);


--
-- Name: ix_itemvaluesmap_itemid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_itemvaluesmap_itemid ON library.item_values_map USING btree (item_id);


--
-- Name: ix_mediastreaminfos_streamindex; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_mediastreaminfos_streamindex ON library.media_stream_infos USING btree (stream_index);


--
-- Name: ix_mediastreaminfos_streamindex_streamtype; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_mediastreaminfos_streamindex_streamtype ON library.media_stream_infos USING btree (stream_index, stream_type);


--
-- Name: ix_mediastreaminfos_streamindex_streamtype_language; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_mediastreaminfos_streamindex_streamtype_language ON library.media_stream_infos USING btree (stream_index, stream_type, language);


--
-- Name: ix_mediastreaminfos_streamtype; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_mediastreaminfos_streamtype ON library.media_stream_infos USING btree (stream_type);


--
-- Name: ix_peoplebaseitemmap_itemid_listorder; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_peoplebaseitemmap_itemid_listorder ON library.people_base_item_map USING btree (item_id, list_order);


--
-- Name: ix_peoplebaseitemmap_itemid_sortorder; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_peoplebaseitemmap_itemid_sortorder ON library.people_base_item_map USING btree (item_id, sort_order);


--
-- Name: ix_peoplebaseitemmap_peopleid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_peoplebaseitemmap_peopleid ON library.people_base_item_map USING btree (people_id);


--
-- Name: ix_peoples_name; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_peoples_name ON library.peoples USING btree (name);


--
-- Name: ix_userdata_itemid_userid_isfavorite; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_userdata_itemid_userid_isfavorite ON library.user_data USING btree (item_id, user_id, is_favorite);


--
-- Name: ix_userdata_itemid_userid_lastplayeddate; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_userdata_itemid_userid_lastplayeddate ON library.user_data USING btree (item_id, user_id, last_played_date);


--
-- Name: ix_userdata_itemid_userid_playbackpositionticks; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_userdata_itemid_userid_playbackpositionticks ON library.user_data USING btree (item_id, user_id, playback_position_ticks);


--
-- Name: ix_userdata_itemid_userid_played; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_userdata_itemid_userid_played ON library.user_data USING btree (item_id, user_id, played);


--
-- Name: ix_userdata_userid; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX ix_userdata_userid ON library.user_data USING btree (user_id);


--
-- Name: mediastreaminfos_codec_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX mediastreaminfos_codec_idx ON library.media_stream_infos USING btree (codec);


--
-- Name: mediastreaminfos_itemid_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX mediastreaminfos_itemid_idx ON library.media_stream_infos USING btree (item_id, stream_type);


--
-- Name: peoplebaseitemmap_itemid_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX peoplebaseitemmap_itemid_idx ON library.people_base_item_map USING btree (item_id, people_id);


--
-- Name: peoplebaseitemmap_peopleid_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX peoplebaseitemmap_peopleid_idx ON library.people_base_item_map USING btree (people_id, item_id);


--
-- Name: userdata_lastplayeddate_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX userdata_lastplayeddate_idx ON library.user_data USING btree (last_played_date DESC);


--
-- Name: userdata_userid_isfavorite_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX userdata_userid_isfavorite_idx ON library.user_data USING btree (user_id, is_favorite);


--
-- Name: userdata_userid_played_idx; Type: INDEX; Schema: library; Owner: jellyfin
--

CREATE INDEX userdata_userid_played_idx ON library.user_data USING btree (user_id, played);


--
-- Name: IX_AccessSchedules_UserId; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE INDEX "IX_AccessSchedules_UserId" ON users.access_schedules USING btree (user_id);


--
-- Name: IX_Permissions_UserId_Kind; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_Permissions_UserId_Kind" ON users.permissions USING btree (user_id, kind) WHERE (user_id IS NOT NULL);


--
-- Name: IX_Preferences_UserId_Kind; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_Preferences_UserId_Kind" ON users.preferences USING btree (user_id, kind) WHERE (user_id IS NOT NULL);


--
-- Name: IX_Users_Username; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE UNIQUE INDEX "IX_Users_Username" ON users.users USING btree (username);


--
-- Name: ix_accessschedules_userid; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE INDEX ix_accessschedules_userid ON users.access_schedules USING btree (user_id);


--
-- Name: ix_permissions_userid_kind; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_permissions_userid_kind ON users.permissions USING btree (user_id, kind) WHERE (user_id IS NOT NULL);


--
-- Name: ix_preferences_userid_kind; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_preferences_userid_kind ON users.preferences USING btree (user_id, kind) WHERE (user_id IS NOT NULL);


--
-- Name: ix_users_username; Type: INDEX; Schema: users; Owner: jellyfin
--

CREATE UNIQUE INDEX ix_users_username ON users.users USING btree (username);


--
-- Name: devices FK_Devices_Users_UserId; Type: FK CONSTRAINT; Schema: authentication; Owner: jellyfin
--

ALTER TABLE ONLY authentication.devices
    ADD CONSTRAINT "FK_Devices_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: devices fk_devices_users_userid; Type: FK CONSTRAINT; Schema: authentication; Owner: jellyfin
--

ALTER TABLE ONLY authentication.devices
    ADD CONSTRAINT fk_devices_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: display_preferences FK_DisplayPreferences_Users_UserId; Type: FK CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.display_preferences
    ADD CONSTRAINT "FK_DisplayPreferences_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: home_sections FK_HomeSection_DisplayPreferences_DisplayPreferencesId; Type: FK CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.home_sections
    ADD CONSTRAINT "FK_HomeSection_DisplayPreferences_DisplayPreferencesId" FOREIGN KEY (display_preferences_id) REFERENCES displaypreferences.display_preferences(id) ON DELETE CASCADE;


--
-- Name: item_display_preferences FK_ItemDisplayPreferences_Users_UserId; Type: FK CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.item_display_preferences
    ADD CONSTRAINT "FK_ItemDisplayPreferences_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: display_preferences fk_displaypreferences_users_userid; Type: FK CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.display_preferences
    ADD CONSTRAINT fk_displaypreferences_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: home_sections fk_homesection_displaypreferences_displaypreferencesid; Type: FK CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.home_sections
    ADD CONSTRAINT fk_homesection_displaypreferences_displaypreferencesid FOREIGN KEY (display_preferences_id) REFERENCES displaypreferences.display_preferences(id) ON DELETE CASCADE;


--
-- Name: item_display_preferences fk_itemdisplaypreferences_users_userid; Type: FK CONSTRAINT; Schema: displaypreferences; Owner: jellyfin
--

ALTER TABLE ONLY displaypreferences.item_display_preferences
    ADD CONSTRAINT fk_itemdisplaypreferences_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: ancestor_ids FK_AncestorIds_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.ancestor_ids
    ADD CONSTRAINT "FK_AncestorIds_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: ancestor_ids FK_AncestorIds_BaseItems_ParentItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.ancestor_ids
    ADD CONSTRAINT "FK_AncestorIds_BaseItems_ParentItemId" FOREIGN KEY (parent_item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: attachment_stream_infos FK_AttachmentStreamInfos_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.attachment_stream_infos
    ADD CONSTRAINT "FK_AttachmentStreamInfos_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: audio_stream_details FK_AudioStreamDetails_MediaStreamInfos_ItemId_StreamIndex; Type: FK CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.audio_stream_details
    ADD CONSTRAINT "FK_AudioStreamDetails_MediaStreamInfos_ItemId_StreamIndex" FOREIGN KEY (item_id, stream_index) REFERENCES library.media_stream_infos(item_id, stream_index) ON DELETE CASCADE;


--
-- Name: base_item_audio_extras FK_BaseItemAudioExtras_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.base_item_audio_extras
    ADD CONSTRAINT "FK_BaseItemAudioExtras_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_image_infos FK_BaseItemImageInfos_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_image_infos
    ADD CONSTRAINT "FK_BaseItemImageInfos_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_live_tv_extras FK_BaseItemLiveTvExtras_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.base_item_live_tv_extras
    ADD CONSTRAINT "FK_BaseItemLiveTvExtras_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_metadata_fields FK_BaseItemMetadataFields_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_metadata_fields
    ADD CONSTRAINT "FK_BaseItemMetadataFields_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_providers FK_BaseItemProviders_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_providers
    ADD CONSTRAINT "FK_BaseItemProviders_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_trailer_types FK_BaseItemTrailerTypes_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_trailer_types
    ADD CONSTRAINT "FK_BaseItemTrailerTypes_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_tv_extras FK_BaseItemTvExtras_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.base_item_tv_extras
    ADD CONSTRAINT "FK_BaseItemTvExtras_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_items FK_BaseItems_BaseItems_ParentId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_items
    ADD CONSTRAINT "FK_BaseItems_BaseItems_ParentId" FOREIGN KEY (parent_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: chapters FK_Chapters_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.chapters
    ADD CONSTRAINT "FK_Chapters_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: image_infos FK_ImageInfos_Users_UserId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.image_infos
    ADD CONSTRAINT "FK_ImageInfos_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: item_values_map FK_ItemValuesMap_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.item_values_map
    ADD CONSTRAINT "FK_ItemValuesMap_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: item_values_map FK_ItemValuesMap_ItemValues_ItemValueId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.item_values_map
    ADD CONSTRAINT "FK_ItemValuesMap_ItemValues_ItemValueId" FOREIGN KEY (item_value_id) REFERENCES library.item_values(item_value_id) ON DELETE CASCADE;


--
-- Name: keyframe_data FK_KeyframeData_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.keyframe_data
    ADD CONSTRAINT "FK_KeyframeData_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: media_stream_infos FK_MediaStreamInfos_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.media_stream_infos
    ADD CONSTRAINT "FK_MediaStreamInfos_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: people_base_item_map FK_PeopleBaseItemMap_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.people_base_item_map
    ADD CONSTRAINT "FK_PeopleBaseItemMap_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: people_base_item_map FK_PeopleBaseItemMap_Peoples_PeopleId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.people_base_item_map
    ADD CONSTRAINT "FK_PeopleBaseItemMap_Peoples_PeopleId" FOREIGN KEY (people_id) REFERENCES library.peoples(id) ON DELETE CASCADE;


--
-- Name: user_data FK_UserData_BaseItems_ItemId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.user_data
    ADD CONSTRAINT "FK_UserData_BaseItems_ItemId" FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: user_data FK_UserData_Users_UserId; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.user_data
    ADD CONSTRAINT "FK_UserData_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: video_stream_details FK_VideoStreamDetails_MediaStreamInfos_ItemId_StreamIndex; Type: FK CONSTRAINT; Schema: library; Owner: postgres
--

ALTER TABLE ONLY library.video_stream_details
    ADD CONSTRAINT "FK_VideoStreamDetails_MediaStreamInfos_ItemId_StreamIndex" FOREIGN KEY (item_id, stream_index) REFERENCES library.media_stream_infos(item_id, stream_index) ON DELETE CASCADE;


--
-- Name: ancestor_ids fk_ancestorids_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.ancestor_ids
    ADD CONSTRAINT fk_ancestorids_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: ancestor_ids fk_ancestorids_baseitems_parentitemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.ancestor_ids
    ADD CONSTRAINT fk_ancestorids_baseitems_parentitemid FOREIGN KEY (parent_item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: attachment_stream_infos fk_attachmentstreaminfos_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.attachment_stream_infos
    ADD CONSTRAINT fk_attachmentstreaminfos_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_image_infos fk_baseitemimageinfos_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_image_infos
    ADD CONSTRAINT fk_baseitemimageinfos_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_metadata_fields fk_baseitemmetadatafields_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_metadata_fields
    ADD CONSTRAINT fk_baseitemmetadatafields_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_providers fk_baseitemproviders_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_providers
    ADD CONSTRAINT fk_baseitemproviders_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: base_item_trailer_types fk_baseitemtrailertypes_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.base_item_trailer_types
    ADD CONSTRAINT fk_baseitemtrailertypes_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: chapters fk_chapters_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.chapters
    ADD CONSTRAINT fk_chapters_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: image_infos fk_imageinfos_users_userid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.image_infos
    ADD CONSTRAINT fk_imageinfos_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: item_values_map fk_itemvaluesmap_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.item_values_map
    ADD CONSTRAINT fk_itemvaluesmap_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: item_values_map fk_itemvaluesmap_itemvalues_itemvalueid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.item_values_map
    ADD CONSTRAINT fk_itemvaluesmap_itemvalues_itemvalueid FOREIGN KEY (item_value_id) REFERENCES library.item_values(item_value_id) ON DELETE CASCADE;


--
-- Name: keyframe_data fk_keyframedata_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.keyframe_data
    ADD CONSTRAINT fk_keyframedata_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: media_stream_infos fk_mediastreaminfos_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.media_stream_infos
    ADD CONSTRAINT fk_mediastreaminfos_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: people_base_item_map fk_peoplebaseitemmap_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.people_base_item_map
    ADD CONSTRAINT fk_peoplebaseitemmap_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: people_base_item_map fk_peoplebaseitemmap_peoples_peopleid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.people_base_item_map
    ADD CONSTRAINT fk_peoplebaseitemmap_peoples_peopleid FOREIGN KEY (people_id) REFERENCES library.peoples(id) ON DELETE CASCADE;


--
-- Name: user_data fk_userdata_baseitems_itemid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.user_data
    ADD CONSTRAINT fk_userdata_baseitems_itemid FOREIGN KEY (item_id) REFERENCES library.base_items(id) ON DELETE CASCADE;


--
-- Name: user_data fk_userdata_users_userid; Type: FK CONSTRAINT; Schema: library; Owner: jellyfin
--

ALTER TABLE ONLY library.user_data
    ADD CONSTRAINT fk_userdata_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: access_schedules FK_AccessSchedules_Users_UserId; Type: FK CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.access_schedules
    ADD CONSTRAINT "FK_AccessSchedules_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: permissions FK_Permissions_Users_UserId; Type: FK CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.permissions
    ADD CONSTRAINT "FK_Permissions_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: preferences FK_Preferences_Users_UserId; Type: FK CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.preferences
    ADD CONSTRAINT "FK_Preferences_Users_UserId" FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: access_schedules fk_accessschedules_users_userid; Type: FK CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.access_schedules
    ADD CONSTRAINT fk_accessschedules_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: permissions fk_permissions_users_userid; Type: FK CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.permissions
    ADD CONSTRAINT fk_permissions_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- Name: preferences fk_preferences_users_userid; Type: FK CONSTRAINT; Schema: users; Owner: jellyfin
--

ALTER TABLE ONLY users.preferences
    ADD CONSTRAINT fk_preferences_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

\unrestrict ioCi9akCEb4OTJqqafagnN0ujRzEOChWnb2NQKO5G1mPGHoPiOIWcce58T7EixH

