Adding a new subject hierarchy to a live ePrints system

The basic instructions are here: <http://wiki.eprints.org/w/EPrints2/AddUniversityStructure>. This Wiki entry tells you how to set up the fields, etc., that are required in order to add the new subjects to ePrints. However, these instructions assume a non-live system, as you have to drop and re-create the database. This is not much use if you need to add a new subject tree to a repository that already contains data. There are instructions on how to do this here:<http://wiki.eprints.org/w/EPrints2/AddingLiveFields> but they are rather complex and require dangerous SQL hacking.

Fortunately, there is a relatively easy hack that solves the problem. In the file EPRINTS_HOME/perl_lib/EPrints/Database.pm, subroutine create_table, change the line that reads:

	my $sql = "CREATE TABLE $tablename (";

to:

	my $sql = "CREATE TABLE IF NOT EXISTS $tablename (";

You can then run:

	% bin/create_tables --force archivename

to create the tables. You probably will still get an error, but it will at least create the tables required for the new fields that you have created. After that the process is simple:

	% bin/import_subjects archivename
	% bin/generate_static archivename    (this may not be necessary?)
	% bin/generate_abstracts archivename
	% bin/generate_views archivename
	% apachectl stop
	% apachectl start

	(May also need to restart the indexer?)

Remember to roll back the change to Database.pm. It probably doesn't matter, but better to be safe...

Note: if you want the new subject hierarchy to be included in the list of editorial restrictions for users, edit ArchiveConfig.pm, and add the top-level field name for the hierarchy (which must be the same as the key for the top level item in the subjects file) to the list under editor_limit_fields.
