-- database-update.sql

-- ---------- version 5.2.1 -------------
-- Make confname a unique column
ALTER TABLE configs ADD UNIQUE(confname);

-- Delete db name, user, and password configs
DELETE FROM configs where confname="ol_dbname";
DELETE FROM configs where confname="ol_dbuser";
DELETE FROM configs where confname="ol_dbpass";

-- Add config option for server side error logging
INSERT IGNORE INTO configs(confname,confvalue) values('log_errors','0')

-- Update version number
UPDATE configs SET confvalue="5.2.1" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.2 -------------
-- Update version number
UPDATE configs SET confvalue="5.2.2" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.3 -------------
-- Update version number
UPDATE configs SET confvalue="5.2.3" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.4 -------------
-- Update version number
UPDATE configs SET confvalue="5.2.4" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.4.1 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.1" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.4.2 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.2" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.4.3 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.3" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.4.4 -----------
-- Update version number
UPDATE configs SET confvalue="5.2.4.4" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.2.5 -------------
-- Update version number
UPDATE configs SET confvalue="5.2.5" WHERE confname="ol_version";
-- --------------------------------------

-- ---------- version 5.3.0 -------------
-- Update version number
UPDATE configs SET confvalue="5.3.0" WHERE confname="ol_version";

-- Create the flagmap table
CREATE TABLE IF NOT EXISTS `flagmap` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `flagid` int(11) NOT NULL,
  `lognoteid` int(11) DEFAULT NULL,
  `maintformid` int(11) DEFAULT NULL,
  `notetemplateid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create the reflinks table
CREATE TABLE IF NOT EXISTS `reflinks` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `noteid` int(11) DEFAULT NULL,
  `templateid` int(11) DEFAULT NULL,
  `target` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------
