Difference between revisions of "Adding a Field to a Live Repository"

From EPrints Documentation
Jump to: navigation, search
m (appears out of date and needing an update)
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''For Eprints 2.x'''
+
[[Category:Manual]]
 +
[[Category:Metadata Fields]]
 +
[[Category: Out of Date]]
  
 
To add a field to a live eprints archive you have to modify the SQL tables.
 
To add a field to a live eprints archive you have to modify the SQL tables.
Line 9: Line 11:
 
Adding fields of type "name" is beyond the scope of these instructions.
 
Adding fields of type "name" is beyond the scope of these instructions.
  
== Recipe ==  
+
== Recipe (for Eprints 3.x) ==
  
=== Step 1 - Shut down apache ===
+
This is much the same as for Eprints 2.x except that the names have been changed to protect the innocent.
Shut down the web server. You don't want people using it while you make this change.
 
  
=== Step 2 - Add configuration ===
+
* Define your new fields in <tt>archives/ARCHIVEID/cfg/cfg.d/eprint_fields.pl</tt> for EPrint-level metadata, <tt>.../document_fields.pl</tt> for document-level metadata (this file doesn't exist by default, but is honoured), <tt>.../user_fields.pl</tt> for user metadata, etc etc.
Add the configuration for this field to MetadataFieldsConfig.pm - take note of which field you add this new field after. (from now on I'll refer to the previous field as ''prevfield''.  
 
  
=== Step 3 - Add fields to database ===
+
=== EPrints 3.0 ===
  
Find out the SQL type of the field you are adding.  
+
* Add the new columns to the appropriate tables. There are no longer four separate tables for eprints as there were in EP2 (<tt>archive</tt>, <tt>buffer</tt> etc), so it's simpler.
 +
** For a field defined in <tt>eprint_fields.pl</tt>, the tables are <tt>eprint</tt> and <tt>eprint__ordervalues_en</tt> (replacing <tt>en</tt> with your language as required).
 +
** For a field defined in <tt>document_fields.pl</tt>, you want <tt>document</tt> and <tt>document__ordervalues_en</tt>.
 +
** And so on.
 +
* The column types are the same as for EP2, ie in <tt>eprint</tt> you want a type appropriate to the type of your field exactly as described in the Recipe for EP2 above, while in <tt>eprint__ordervalues_en</tt> you want <tt>text</tt> irrespective of your field type.
  
boolean
+
=== EPrints 3.1+ ===
:: '''SET('TRUE','FALSE')'''
 
date
 
:: '''DATE'''
 
year, int
 
:: '''INTEGER'''
 
longtext
 
:: '''TEXT'''
 
subject,set,url,email,pagerange,text
 
:: '''VARCHAR(255)'''
 
  
Note that if the field is type multiple then this step is different.
+
Once you have added your new field definitions to the appropriate configuration file you can run the update_database_structure [[API:bin/epadmin|epadmin]] method from the shell:
  
For both steps the following replacements must be applied to the MySQL code given:
+
./bin/epadmin update_database_structure ARCHIVEID
  
* Replace ''type'' with the SQL type appropriate to the field you are adding.  
+
In EPrints 3.3+ you can use ''update'' as a synonym of ''update_database_structure''.
* Replace ''newfieldname'' with the name of the field you're adding
 
* Replace ''prevfield'' with the name of the (non-multiple) field proceeding the field you are adding. If prevfield is a multiple then use the first non-multiple field proceeding your new field. (not used for multiple fields)
 
 
 
''Now only do step 3a or 3b depending if this field is multiple or not''
 
 
 
==== Step 3a - Adding a normal field ====
 
 
 
In the database (log into CommandLineMySQL) do the following:
 
 
 
 
 
If this is confusing see the example at the end of the page.
 
 
 
 
 
ALTER TABLE archive ADD ''newfieldname'' ''type'' default NULL AFTER ''prevfield'';
 
ALTER TABLE buffer ADD ''newfieldname'' ''type'' default NULL AFTER ''prevfield'';
 
ALTER TABLE inbox ADD ''newfieldname'' ''type'' default NULL AFTER ''prevfield'';
 
ALTER TABLE deletion ADD ''newfieldname'' ''type'' default NULL AFTER ''prevfield'';
 
 
 
==== Step 3b - Adding a "multiple" field ====
 
 
 
Multiple fields need their own table, so the syntax is different.
 
 
 
Please note that these commands have been split over multiple lines for readability.
 
 
 
CREATE TABLE archive_''newfieldname'' ( eprintid INT NOT NULL, pos INT,
 
    ''newfieldname'' ''type'' default NULL, KEY eprintid (eprintid), KEY pos (pos) ); 
 
 
 
CREATE TABLE buffer_''newfieldname'' ( eprintid INT NOT NULL, pos INT,
 
    ''newfieldname'' ''type'' default NULL, KEY eprintid (eprintid), KEY pos (pos) );
 
 
 
CREATE TABLE inbox_''newfieldname'' ( eprintid INT NOT NULL, pos INT,
 
    ''newfieldname'' ''type'' default NULL, KEY eprintid (eprintid), KEY pos (pos) ); 
 
 
 
CREATE TABLE deletion_''newfieldname'' ( eprintid INT NOT NULL, pos INT,
 
    ''newfieldname'' ''type'' default NULL, KEY eprintid (eprintid), KEY pos (pos) ); 
 
 
 
=== Step 4 - Modify the ordervalues tables ===
 
 
 
The ordervalues table is used to store a "dumbed down" version of the value in your field used for sorting, but never rendered.
 
 
 
The same replacement values apply as for step 3 with one difference. The ''prevfield'' is the previous field in ArchiveMetadataFieldsConfig.pm even if it is a multiple field.
 
 
 
Notes:
 
* there are two underline characters before "ordervalues".
 
* this assumes you are not running a multilanguage or non-english archive. If you ''are'' then repeat the 4 commands below and replace 'en' with each of your archive's languages in turn.
 
 
 
ALTER TABLE archive__ordervalues_en ADD ''fieldname'' TEXT AFTER ''prevfield'';
 
ALTER TABLE buffer__ordervalues_en ADD ''fieldname'' TEXT AFTER ''prevfield'';
 
ALTER TABLE inbox__ordervalues_en ADD ''fieldname'' TEXT AFTER ''prevfield'';
 
ALTER TABLE deletion__ordervalues_en ADD ''fieldname'' TEXT AFTER ''prevfield'';
 
 
 
=== Step 5 - Checking it works... ===
 
 
 
It should all be OK at this point, but it's worth checking. I suggest running generate_views on the archive to make sure it all works OK.
 
 
 
=== Step 6 - Finishing up ===
 
 
 
Add the config to metadata-types.xml and phrases.xml - see AddingFields
 
 
 
=== Step 7 - Restart apache ===
 
 
 
Everything should now be OK. restart the webserver
 
 
 
----
 
 
 
== Examples ==
 
 
 
 
 
=== Normal set field example ===
 
To add a field of type 'set' to eprints. We add this to ArchveMetadataFieldsConfig.pm
 
 
 
{ name => "foo", type => "set", input_rows => 1,
 
        options => [ "yesod", "hod", "chesed" ] },
 
 
 
The previous field is a (non-multiple) text field called 'bar')
 
 
 
then run the following SQL statements:
 
 
 
ALTER TABLE archive ADD foo VARCHAR(255) default NULL AFTER bar;
 
ALTER TABLE buffer ADD foo VARCHAR(255) default NULL AFTER bar;
 
ALTER TABLE inbox ADD foo VARCHAR(255) default NULL AFTER bar;
 
ALTER TABLE deletion ADD foo VARCHAR(255) default NULL AFTER bar;
 
 
 
ALTER TABLE archive__ordervalues_en ADD foo TEXT AFTER bar;
 
ALTER TABLE buffer__ordervalues_en ADD foo TEXT AFTER bar;
 
ALTER TABLE inbox__ordervalues_en ADD foo TEXT AFTER bar;
 
ALTER TABLE deletion__ordervalues_en ADD foo TEXT AFTER bar;
 

Revision as of 00:47, 12 September 2018


To add a field to a live eprints archive you have to modify the SQL tables.

Before you start this you may wish to BackupTheDatabase.

This assumes you are adding a field to the "eprint" fields, not the "user" fields. If you are changing "user" then anywhere we have 4 actions, one for each of buffer, deletion, archive and inbox, you instead need a single action for "users".

Adding fields of type "name" is beyond the scope of these instructions.

Recipe (for Eprints 3.x)

This is much the same as for Eprints 2.x except that the names have been changed to protect the innocent.

  • Define your new fields in archives/ARCHIVEID/cfg/cfg.d/eprint_fields.pl for EPrint-level metadata, .../document_fields.pl for document-level metadata (this file doesn't exist by default, but is honoured), .../user_fields.pl for user metadata, etc etc.

EPrints 3.0

  • Add the new columns to the appropriate tables. There are no longer four separate tables for eprints as there were in EP2 (archive, buffer etc), so it's simpler.
    • For a field defined in eprint_fields.pl, the tables are eprint and eprint__ordervalues_en (replacing en with your language as required).
    • For a field defined in document_fields.pl, you want document and document__ordervalues_en.
    • And so on.
  • The column types are the same as for EP2, ie in eprint you want a type appropriate to the type of your field exactly as described in the Recipe for EP2 above, while in eprint__ordervalues_en you want text irrespective of your field type.

EPrints 3.1+

Once you have added your new field definitions to the appropriate configuration file you can run the update_database_structure epadmin method from the shell:

./bin/epadmin update_database_structure ARCHIVEID

In EPrints 3.3+ you can use update as a synonym of update_database_structure.