<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| MYSQL DB Upgrade from 3.0 to 3.1
|--------------------------------------------------------------------------
|
| DB changes for NADA 3.1
|
|
*/
$config['db-update'][] = "ALTER TABLE sitelogs MODIFY surveyid INT DEFAULT 0";

$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN abbreviation varchar(45) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN kindofdata varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN keywords text DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN ie_program varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN ie_project_id varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN ie_project_name varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN ie_project_uri varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN ie_team_leaders text";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN project_id varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN project_name varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN project_uri varchar(255) DEFAULT NULL";
$config['db-update'][] = "ALTER TABLE surveys ADD COLUMN link_da varchar(255) DEFAULT NULL";

//Fulltext index changes
$config['db-update'][] = "ALTER TABLE surveys DROP INDEX ft_all";
$config['db-update'][] = "CREATE FULLTEXT INDEX ft_all on SURVEYS(titl,authenty,geogcover,nation,topic,scope,sername,producer,sponsor,refno,abbreviation,kindofdata,keywords)";

$config['db-update'][] = "ALTER TABLE citations ADD COLUMN country varchar(100) DEFAULT NULL";

$config['db-update'][] = "ALTER TABLE repositories ADD COLUMN scan_lastrun int NOT NULL";
$config['db-update'][] = "ALTER TABLE repositories ADD COLUMN scan_interval int NOT NULL";
$config['db-update'][] = "ALTER TABLE repositories ADD COLUMN scan_nextrun int NOT NULL";
$config['db-update'][] = "ALTER TABLE repositories ADD COLUMN status varchar(255) NOT NULL";
$config['db-update'][] = "ALTER TABLE repositories ADD COLUMN surveys_found int NOT NULL";
$config['db-update'][] = "ALTER TABLE repositories ADD COLUMN changed int NOT NULL";

$config['db-update'][] = "ALTER TABLE repositories ADD PRIMARY KEY(id)";
$config['db-update'][] = "ALTER TABLE repositories ADD UNIQUE KEY ind_unq (repositoryid)";
$config['db-update'][] = "ALTER TABLE repositories ADD UNIQUE KEY ind_url(url)";

$config['db-update'][] = "ALTER TABLE users ADD COLUMN authtype varchar(40) DEFAULT NULL";

$config['db-update'][]="CREATE TABLE  user_site_roles (
						  id int NOT NULL AUTO_INCREMENT,
						  userid int NOT NULL,
						  siteid varchar(255) NOT NULL,
						  groupid int NOT NULL,
						  PRIMARY KEY (id),
						  KEY unq_user_site (userid,siteid)
						) ENGINE=InnoDB DEFAULT CHARSET=utf8;";


$config['db-update'][]="CREATE TABLE harvester_queue (
							  id int NOT NULL AUTO_INCREMENT,
							  repositoryid varchar(50) NOT NULL,
							  survey_url varchar(100) NOT NULL,
							  status varchar(45) NOT NULL,
							  ddi_local_path varchar(255) NOT NULL,
							  changed int NOT NULL,
							  title varchar(255) NOT NULL,
							  survey_timestamp int NOT NULL,
							  retries int(11) DEFAULT '0',
							  country varchar(255) DEFAULT NULL,
							  survey_year int DEFAULT NULL,
							  accesspolicy varchar(45) DEFAULT NULL,
							  checksum varchar(255) DEFAULT NULL,
							  surveyid varchar(200) DEFAULT NULL,
							  PRIMARY KEY (id),
							  UNIQUE KEY idx_unq (repositoryid,survey_url),
							  UNIQUE KEY idx_s_r (repositoryid,surveyid)
							) ENGINE=InnoDB DEFAULT CHARSET=utf8;";


$config['db-update'][]="DELETE from configurations WHERE name='cache_folder'";
$config['db-update'][]="INSERT INTO configurations (name, value, label, helptext, item_group) VALUES ('cache_default_expires', '7200', 'Cache expiry (in mili seconds)', NULL, NULL);";
$config['db-update'][]="INSERT INTO configurations (name, value, label, helptext, item_group) VALUES ('cache_disabled', '0', 'Enable/disable site caching', NULL, NULL);";
$config['db-update'][]="INSERT INTO configurations (name, value, label, helptext, item_group) VALUES ('cache_path', './cache', 'Site cache folder', NULL, NULL);";

$config['db-update'][]="INSERT INTO forms (formid, fname, model, path, iscustom) VALUES (5, 'Data available from external repository', 'remote', 'remote', '1');";


$config['db-update'][]="CREATE TABLE schema_version (
						  version int(3) DEFAULT NULL
						) ENGINE=InnoDB DEFAULT CHARSET=utf8;";

$config['db-update'][]="CREATE TABLE survey_collections (
						  uid int NOT NULL AUTO_INCREMENT,
						  sid int DEFAULT NULL,
						  tid int DEFAULT NULL,
						  PRIMARY KEY (uid)
						) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
