From 1b68e1dc0aa8a3ba59bb28e93e399d400f3489ab Mon Sep 17 00:00:00 2001 From: Wendell Jones Date: Thu, 9 Jul 2026 15:54:00 -0400 Subject: [PATCH] Update database schema and indices for improved performance and compatibility --- .../schema_init/create_database_schema.sql | 136 ++++++++++++++++-- 1 file changed, 128 insertions(+), 8 deletions(-) diff --git a/scripts/sql/schema_init/create_database_schema.sql b/scripts/sql/schema_init/create_database_schema.sql index bfb21b28..bcbce416 100644 --- a/scripts/sql/schema_init/create_database_schema.sql +++ b/scripts/sql/schema_init/create_database_schema.sql @@ -2,10 +2,10 @@ -- PostgreSQL database dump -- -\restrict ioCi9akCEb4OTJqqafagnN0ujRzEOChWnb2NQKO5G1mPGHoPiOIWcce58T7EixH +\restrict gtmnhnnhvGPbISEXatQ92tRbfGW4Ltf9Lo0RLFqx6gbMlpR4nJHxMxY5ogWUEfv --- 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) +-- Dumped from database version 18.4 (Ubuntu 18.4-1.pgdg25.10+1) +-- Dumped by pg_dump version 18.4 (Ubuntu 18.4-1.pgdg25.10+1) SET statement_timeout = 0; SET lock_timeout = 0; @@ -1079,7 +1079,8 @@ CREATE TABLE library.user_data ( audio_stream_index integer, subtitle_stream_index integer, likes boolean, - retention_date timestamp with time zone + retention_date timestamp with time zone, + row_version bigint DEFAULT 0 NOT NULL ); @@ -1629,11 +1630,11 @@ ALTER TABLE ONLY public."__EFMigrationsHistory" -- --- Name: __efmigrationshistory pk___efmigrationshistory; Type: CONSTRAINT; Schema: public; Owner: postgres +-- Name: __ef_migrations_history pk___efmigrationshistory; Type: CONSTRAINT; Schema: public; Owner: jellyfin -- -ALTER TABLE ONLY public.__efmigrationshistory - ADD CONSTRAINT pk___efmigrationshistory PRIMARY KEY (migrationid); +ALTER TABLE ONLY public.__ef_migrations_history + ADD CONSTRAINT pk___efmigrationshistory PRIMARY KEY (migration_id); -- @@ -1983,6 +1984,13 @@ CREATE INDEX baseitems_datecreated_idx ON library.base_items USING btree (date_c CREATE INDEX baseitems_datemodified_idx ON library.base_items USING btree (date_modified DESC); +-- +-- Name: baseitems_parentid_idx; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX baseitems_parentid_idx ON library.base_items USING btree (parent_id, type); + + -- -- Name: baseitems_premieredate_idx; Type: INDEX; Schema: library; Owner: jellyfin -- @@ -2011,6 +2019,55 @@ CREATE INDEX baseitems_sortname_idx ON library.base_items USING btree (sort_name CREATE INDEX baseitems_topparentid_idx ON library.base_items USING btree (top_parent_id, type); +-- +-- Name: idx_base_item_audio_extras_item_id; Type: INDEX; Schema: library; Owner: postgres +-- + +CREATE INDEX idx_base_item_audio_extras_item_id ON library.base_item_audio_extras USING btree (item_id); + + +-- +-- Name: idx_base_item_image_infos_item_id; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX idx_base_item_image_infos_item_id ON library.base_item_image_infos USING btree (item_id); + + +-- +-- Name: idx_base_item_live_tv_extras_item_id; Type: INDEX; Schema: library; Owner: postgres +-- + +CREATE INDEX idx_base_item_live_tv_extras_item_id ON library.base_item_live_tv_extras USING btree (item_id); + + +-- +-- Name: idx_base_item_metadata_fields_item_id; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX idx_base_item_metadata_fields_item_id ON library.base_item_metadata_fields USING btree (item_id); + + +-- +-- Name: idx_base_item_providers_item_id; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX idx_base_item_providers_item_id ON library.base_item_providers USING btree (item_id); + + +-- +-- Name: idx_base_item_trailer_types_item_id; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX idx_base_item_trailer_types_item_id ON library.base_item_trailer_types USING btree (item_id); + + +-- +-- Name: idx_base_item_tv_extras_item_id; Type: INDEX; Schema: library; Owner: postgres +-- + +CREATE INDEX idx_base_item_tv_extras_item_id ON library.base_item_tv_extras USING btree (item_id); + + -- -- Name: idx_baseitems_datecreated_filtered; Type: INDEX; Schema: library; Owner: jellyfin -- @@ -2039,6 +2096,13 @@ CREATE INDEX idx_baseitems_topparentid_isfolder ON library.base_items USING btre 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_image_infos_user_id; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX idx_image_infos_user_id ON library.image_infos USING btree (user_id); + + -- -- Name: idx_itemvalues_cleanvalue; Type: INDEX; Schema: library; Owner: jellyfin -- @@ -2074,6 +2138,13 @@ CREATE INDEX idx_itemvalues_value ON library.item_values USING btree (value) WHE CREATE INDEX idx_itemvaluesmap_itemvalueid_itemid ON library.item_values_map USING btree (item_value_id, item_id); +-- +-- Name: idx_user_data_item_id; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX idx_user_data_item_id ON library.user_data USING btree (item_id); + + -- -- Name: ix_ancestorids_parentitemid; Type: INDEX; Schema: library; Owner: jellyfin -- @@ -2081,6 +2152,34 @@ CREATE INDEX idx_itemvaluesmap_itemvalueid_itemid ON library.item_values_map USI CREATE INDEX ix_ancestorids_parentitemid ON library.ancestor_ids USING btree (parent_item_id); +-- +-- Name: ix_base_item_audio_extras_item_id; Type: INDEX; Schema: library; Owner: postgres +-- + +CREATE INDEX ix_base_item_audio_extras_item_id ON library.base_item_audio_extras USING btree (item_id); + + +-- +-- Name: ix_base_item_image_infos_item_id; Type: INDEX; Schema: library; Owner: jellyfin +-- + +CREATE INDEX ix_base_item_image_infos_item_id ON library.base_item_image_infos USING btree (item_id); + + +-- +-- Name: ix_base_item_live_tv_extras_item_id; Type: INDEX; Schema: library; Owner: postgres +-- + +CREATE INDEX ix_base_item_live_tv_extras_item_id ON library.base_item_live_tv_extras USING btree (item_id); + + +-- +-- Name: ix_base_item_tv_extras_item_id; Type: INDEX; Schema: library; Owner: postgres +-- + +CREATE INDEX ix_base_item_tv_extras_item_id ON library.base_item_tv_extras USING btree (item_id); + + -- -- Name: ix_baseitemimageinfos_itemid; Type: INDEX; Schema: library; Owner: jellyfin -- @@ -2347,6 +2446,20 @@ CREATE UNIQUE INDEX "IX_Preferences_UserId_Kind" ON users.preferences USING btre CREATE UNIQUE INDEX "IX_Users_Username" ON users.users USING btree (username); +-- +-- Name: idx_access_schedules_user_id; Type: INDEX; Schema: users; Owner: jellyfin +-- + +CREATE INDEX idx_access_schedules_user_id ON users.access_schedules USING btree (user_id); + + +-- +-- Name: idx_permissions_user_id; Type: INDEX; Schema: users; Owner: jellyfin +-- + +CREATE INDEX idx_permissions_user_id ON users.permissions USING btree (user_id); + + -- -- Name: ix_accessschedules_userid; Type: INDEX; Schema: users; Owner: jellyfin -- @@ -2807,9 +2920,16 @@ ALTER TABLE ONLY users.preferences ADD CONSTRAINT fk_preferences_users_userid FOREIGN KEY (user_id) REFERENCES users.users(id) ON DELETE CASCADE; +-- +-- Name: TABLE pg_stat_statements; Type: ACL; Schema: public; Owner: wjones +-- + +GRANT SELECT ON TABLE public.pg_stat_statements TO jellyfin; + + -- -- PostgreSQL database dump complete -- -\unrestrict ioCi9akCEb4OTJqqafagnN0ujRzEOChWnb2NQKO5G1mPGHoPiOIWcce58T7EixH +\unrestrict gtmnhnnhvGPbISEXatQ92tRbfGW4Ltf9Lo0RLFqx6gbMlpR4nJHxMxY5ogWUEfv