-- 
--  This file is part of the SavaPage project <https://www.savapage.org>.
--  Copyright (c) 2011-2020 Datraverse B.V.
--  Author: Rijk Ravestein.
-- 
--  SPDX-FileCopyrightText: 2011-2020 Datraverse B.V. <info@datraverse.com>
--  SPDX-License-Identifier: AGPL-3.0-or-later
-- 
--  This program is free software: you can redistribute it and/or modify
--  it under the terms of the GNU Affero General Public License as
--  published by the Free Software Foundation, either version 3 of the
--  License, or (at your option) any later version.
-- 
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU Affero General Public License for more details.
-- 
--  You should have received a copy of the GNU Affero General Public License
--  along with this program.  If not, see <https://www.gnu.org/licenses/>.
-- 
--  For more information, please contact Datraverse B.V. at this
--  address: info@datraverse.com
-- 

-- |--------------------------------------------------------------------------
-- | Schema Version 1.9 Upgrade Script - PostgreSQL
-- | 
-- | Upgrade from Application Version 1.0.0 to 1.1.0
-- | 
-- |--------------------------------------------------------------------------

-- +==========================================================================
-- | Set MINOR version
-- |
-- | Force "division by zero" error if current version is not 1.8
-- +==========================================================================

UPDATE TBL_CONFIG SET PROPERTY_VALUE = '9' 
WHERE PROPERTY_NAME = 'system.schema-version-minor'
  AND 1 = (SELECT 1 / COUNT(*) FROM TBL_CONFIG WHERE 
    PROPERTY_NAME = 'system.schema-version'
      AND PROPERTY_VALUE = '1')
  AND 1 = (SELECT 1 / COUNT(*) FROM TBL_CONFIG WHERE 
    PROPERTY_NAME = 'system.schema-version-minor'
      AND PROPERTY_VALUE = '8');

-- +==========================================================================
-- | DATA CHANGES
-- +==========================================================================

-- +--------------------------------------------------------
-- | tbl_user
-- +--------------------------------------------------------
create index ix_user_2 on tbl_user (full_name);

-- +--------------------------------------------------------
-- | tbl_user_group
-- +--------------------------------------------------------
ALTER TABLE tbl_user_group ADD COLUMN full_name varchar(255);

create index ix_user_group_1 on tbl_user_group (full_name);

-- +--------------------------------------------------------
-- | tbl_doc_log
-- +--------------------------------------------------------
create index ix_doc_log_7 on tbl_doc_log (ext_supplier, ext_id);
create index ix_doc_log_8 on tbl_doc_log (ext_id);

-- end-of-script

