Upgrading
=========

From 1.8.0 to 1.8.1
-------------------

1. Drop foreign keys from the "Sessions" table:

`ALTER TABLE Sessions DROP FOREIGN KEY Sessions_ibfk_1;` should work in most
cases. Otherwise, check the output of `SHOW CREATE TABLE Sessions;` and use the
foreign key name shown there.

2. Run the following MySQL statements:

----
ALTER TABLE Sessions
	ADD FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE;
ALTER TABLE PackageDepends
	ADD FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE,
	ADD FOREIGN KEY (DepPkgID) REFERENCES Packages(ID) ON DELETE CASCADE;
ALTER TABLE PackageSources
	ADD FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE;
ALTER TABLE TU_VoteInfo
	ADD FOREIGN KEY (SubmitterID) REFERENCES Users(ID) ON DELETE CASCADE;
ALTER TABLE TU_Votes
	ADD FOREIGN KEY (VoteID) REFERENCES TU_VoteInfo(ID) ON DELETE CASCADE,
	ADD FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE;
ALTER TABLE PackageComments
	MODIFY DelUsersID INTEGER UNSIGNED NULL DEFAULT NULL;
UPDATE PackageComments SET DelUsersID = NULL WHERE DelUsersID = 0;
ALTER TABLE Packages
	MODIFY SubmitterUID INTEGER UNSIGNED NULL DEFAULT NULL,
	MODIFY MaintainerUID INTEGER UNSIGNED NULL DEFAULT NULL;
UPDATE Packages SET SubmitterUID = NULL WHERE SubmitterUID = 0;
UPDATE Packages SET MaintainerUID = NULL WHERE MaintainerUID = 0;
----

3. (optional) If you converted your database from MyISAM to InnoDB during the
upgrade process from 1.7.0 to 1.8.0 or from 1.8.0 to 1.8.1 without completely
rebuilding the database from the MySQL schema, you should additionally run the
following MySQL statements to add missing foreign keys:

----
ALTER TABLE Users
	ADD FOREIGN KEY (AccountTypeID) REFERENCES AccountTypes(ID) ON DELETE NO ACTION;
ALTER TABLE Packages
	ADD FOREIGN KEY (CategoryID) REFERENCES PackageCategories(ID) ON DELETE NO ACTION,
	ADD FOREIGN KEY (SubmitterUID) REFERENCES Users(ID) ON DELETE NO ACTION,
	ADD FOREIGN KEY (MaintainerUID) REFERENCES Users(ID) ON DELETE NO ACTION;
ALTER TABLE PackageVotes
	ADD FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE,
	ADD FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE;
ALTER TABLE PackageComments
	ADD FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE,
	ADD FOREIGN KEY (DelUsersID) REFERENCES Users(ID) ON DELETE CASCADE,
	ADD FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE;
ALTER TABLE CommentNotify
	ADD FOREIGN KEY (PkgID) REFERENCES Packages(ID) ON DELETE CASCADE,
	ADD FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE;
----

4. Merge "web/lib/config.inc.proto" with "web/lib/config.inc".

From 1.7.0 to 1.8.0
-------------------

1. Run the following MySQL statements:

----
ALTER TABLE Packages ADD OutOfDateTS BIGINT UNSIGNED NULL DEFAULT NULL;
UPDATE Packages SET OutOfDateTS = UNIX_TIMESTAMP() WHERE OutOfDate = 1;
ALTER TABLE Packages DROP OutOfDate, DROP FSPath, DROP URLPath, DROP LocationID;
DROP TABLE PackageLocations, PackageContents;
ALTER TABLE AccountTypes MODIFY AccountType VARCHAR(32) NOT NULL DEFAULT '';
ALTER TABLE Users MODIFY Username VARCHAR(32) NOT NULL,
	MODIFY Email VARCHAR(64) NOT NULL,
	MODIFY RealName VARCHAR(64) NOT NULL DEFAULT '',
	MODIFY LangPreference VARCHAR(5) NOT NULL DEFAULT 'en',
	MODIFY IRCNick VARCHAR(32) NOT NULL DEFAULT '';
ALTER TABLE PackageCategories MODIFY Category VARCHAR(32) NOT NULL;
ALTER TABLE Packages MODIFY Name VARCHAR(64) NOT NULL,
	MODIFY Version VARCHAR(32) NOT NULL DEFAULT '',
	MODIFY Description VARCHAR(255) NOT NULL DEFAULT "An Arch Package",
	MODIFY URL VARCHAR(255) NOT NULL DEFAULT "http://www.archlinux.org",
	MODIFY License VARCHAR(40) NOT NULL DEFAULT '';
ALTER TABLE PackageSources
	MODIFY Source VARCHAR(255) NOT NULL DEFAULT "/dev/null";
ALTER TABLE TU_VoteInfo
	MODIFY User VARCHAR(32) collate latin1_general_ci NOT NULL;
CREATE TABLE PackageBlacklist (
	ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
	Name VARCHAR(64) NOT NULL,
	PRIMARY KEY (ID),
	UNIQUE (Name)
);
----

2. Drop all fulltext indexes from the "Packages" table:

Please do this with care. `ALTER TABLE Packages DROP INDEX Name;` will work in
most cases but might remove the wrong index if your indexes have been created
in a non-standard order (e.g. during some update process). You'd better run
`SHOW INDEX FROM Packages;` before to ensure that your setup doesn't use a
different naming.

3. You will need to update all packages which are stored in the incoming dir as
in 1.8.0, source tarballs are no longer extracted automatically and PKGBUILDs
are from now on located in the same subdirectories as the tarballs themselves.
The following script will do the conversion automatically when being run inside
"$INCOMING_DIR":

----
#!/bin/bash

for pkg in *; do
	if [ -d "${pkg}" -a ! -f "${pkg}/PKGBUILD" ]; then
		pkgbuild_file=$(find -P "${pkg}" -name PKGBUILD)
		[ -n "${pkgbuild_file}" ] && \
			cp "${pkgbuild_file}" "${pkg}/PKGBUILD"
	fi
done
----

4. (optional): 1.8.0 includes a helper utility called "aurblup" that can be
used to prevent users from uploading source packages with names identical to
packages in predefined binary repos, e.g. the official repositories of your
distribution. In order to build and install aurblup, enter the following
commands:

	cd scripts/aurblup/
	make config.h
	$EDITOR config.h
	make install  # as root

Add something like "0 * * * * /usr/local/bin/aurblup" to root's crontab to make
aurblup update the package blacklist every hour.

NOTE: You can run aurblup as non-privileged user as well. Make sure that the
user has read-write access to "/var/lib/aurblup/" (or whatever you defined with
"ALPM_DBPATH") tho.

5. (optional): As of 1.8.0, all MySQL tables should be InnoDB compatible. To
convert a table, you can use this statement: `ALTER TABLE $foo ENGINE=InnoDB;`.
If you want to stick with MyISAM or another storage engine that doesn't support
transactions, you will need to disable the "MYSQL_USE_TRANSACTIONS" setting in
"config.h" when setting up aurblup.

From 1.6.0 to 1.7.0
-------------------
ALTER TABLE Users ADD Salt CHAR(32) NOT NULL DEFAULT '';
ALTER TABLE Users ADD ResetKey CHAR(32) NOT NULL DEFAULT '';
ALTER TABLE Users MODIFY LangPreference CHAR(5) NOT NULL DEFAULT 'en';


From 1.5.2 to 1.5.3
-------------------
1. Ensure this appears in config.inc:
   define("DEFAULT_LANG", "en");


From 1.5.1 to 1.5.2
-------------------
1. Ensure Pear and File/Find.php are in the path. See web/README.txt.

2. Update your running copy of support/scripts/newpackage-notify.

3. Run this in web/lib:
<?php

# Run the script from within lib
include('config.inc');
include('aur.inc');

$query = "UPDATE Packages SET " .
         "FSPath = CONCAT('" . INCOMING_DIR . "', Name, '/', Name,
'.tar.gz'), " .
         "URLPath = CONCAT('" . URL_DIR . "', Name, '/', Name, '.tar.gz') " .
         "WHERE DummyPKG = 0 AND LocationID = 2;";

$dbh = db_connect();
db_query($query, $dbh);

$query = "ALTER TABLE Packages DROP COLUMN AURMaintainerUID;";
db_query($query, $dbh);


1.3.0
-----
ALTER TABLE PackageDepends ADD COLUMN DepCondition VARCHAR(20) AFTER DepPkgID;
ALTER TABLE Packages ADD License CHAR(40) NOT NULL DEFAULT '';


1.2.10
------
ALTER TABLE Packages MODIFY Description CHAR(255) NOT NULL DEFAULT "An Arch Package";


longerpkgname
-------------
ALTER TABLE Packages MODIFY Name CHAR(64) NOT NULL;