view PostgreSQL/Plugins/SQL/Upgrades/Rev2ToRev3.sql @ 598:8f6e7ae942f3 find-refactoring

DB Housekeeping
author Alain Mazy <am@orthanc.team>
date Wed, 27 Nov 2024 16:05:49 +0100
parents 272eeb046a88
children
line wrap: on
line source

-- This file contains part of the changes required to upgrade from Revision 2 to Revision 3 (DB version 6 and revision 2)
-- It actually contains only the changes that:
   -- can not be executed with an idempotent statement in SQL
   -- or would polute the PrepareIndex.sql
   -- do facilite an up-time upgrade
-- This file is executed only if the current schema is in revision 2 and it is executed 
-- before PrepareIndex.sql that is idempotent.


-- create a new ChildrenIndex2 that is replacing ChildrenIndex.
-- We create it in this partial update so it can be created while the system is up !
DO $$
DECLARE
    pg_version text;
BEGIN
    SELECT version() INTO pg_version;

    IF substring(pg_version from 'PostgreSQL (\d+)\.')::int >= 11 THEN
        -- PostgreSQL 11 or later
        EXECUTE 'CREATE INDEX IF NOT EXISTS ChildrenIndex2 ON Resources USING btree (parentId ASC NULLS LAST) INCLUDE (publicId, internalId)';
    ELSE
        EXECUTE 'CREATE INDEX IF NOT EXISTS ChildrenIndex2 ON Resources USING btree (parentId ASC NULLS LAST, publicId, internalId)';
    END IF;
END $$;

DROP INDEX IF EXISTS ChildrenIndex;  -- replaced by ChildrenIndex2 but no need to uninstall ChildrenIndex2 when downgrading


-- other changes performed in PrepareIndex.sql:
  -- add ChildCount tables and triggers