1 <?xml version='1.0' encoding='UTF-8'?>
\r
2 <chapter xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"
\r
3 xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:id="migratingdata" >
\r
5 <title>Migrating Data</title>
\r
7 <para>Migrating data into Evergreen can be one of the most daunting tasks for an administrator. This chapter will explain some procedures to help to migrate
\r
8 bibliographic records, copies and patrons into the Evergreen system. This chapter requires advanced ILS Administration experience, knowledge of Evergreen data structures,
\r
9 as well as knowledge of how to export data from your current system or access to data export files from your current system.</para>
\r
12 <section xml:id="migratingpatrons">
\r
13 <title>Migrating Patron Data</title>
\r
15 This section will explain the task of migrating your patron data from comma delimited files<indexterm><primary>comma delimited files</primary></indexterm> into Evergreen.
\r
16 It does not deal with the process of exporting from the non-Evergreen
\r
17 system since this process may vary depending on where you are extracting your patron records. Patron could come from an ILS or it could come from a student database in the case of
\r
20 <para>When importing records into Evergreen you will need to populate 3 tables in your Evergreen database:</para>
\r
22 <listitem><link linkend="actor.table.usr">actor.usr</link> - The main table for user data</listitem>
\r
23 <listitem><link linkend="actor.table.card">actor.card</link> - Stores the barcode for users; Users can have more than 1 card but only 1 can be active at a given time;</listitem>
\r
24 <listitem><link linkend="actor.table.usr-address">actor.usr_address</link> - Used for storing address information; A user can have more than one address.</listitem>
\r
26 <para>Before following the procedures below to import patron data into Evergreen, it is a good idea to examine the fields in these tables in order to decide on a strategy
\r
27 for data to include
\r
28 in your import. It is important to understand the data types and constraints on each field.</para>
\r
31 <para>Export the patron data from your existing ILS or from another source into a comma delimited file. The comma delimited file used for importing
\r
32 the records should use Unicode (UTF8) <indexterm><primary>Unicode</primary></indexterm> character encoding.</para>
\r
35 <para>Create a staging table.<indexterm><primary>staging table</primary></indexterm> A staging table will allow you to tweak the data before importing.
\r
36 Here is an example sql statement:</para>
\r
37 <indexterm><primary>sql</primary></indexterm>
\r
38 <programlisting language="sql">
\r
39 CREATE TABLE students (
\r
40 student_id int, barcode text, last_name text, first_name text, program_number text, program_name text, email text, address_type text, street1 text,
\r
41 street2 text, city text, province text, country text, postal_code text, phone text, profile int, ident_type int, home_ou int,
\r
42 claims_returned_count int DEFAULT 0, usrname text, net_access_level int DEFAULT 2, password text
\r
45 <para>Note the <varname>DEFAULT</varname> variables. These allow you to set default for your library or to populate required fields if you data allows
\r
46 <systemitem>NULL</systemitem> values where fields are required in Evergreen.</para>
\r
49 <para>Formatting of some fields to fit Evergreen filed formatting may be required. Here is an example of sql to adjust phone numbers in the staging
\r
50 table to fit the evergreen field:</para>
\r
51 <programlisting language="sql">
\r
52 UPDATE students phone = replace(replace(replace(rpad(substring(phone from 1 for 9), 10, '-') || substring(phone from 10), '(', ''), ')', ''), ' ', '-');
\r
54 <para>Data <quote>massaging</quote> may be required to fit formats used in Evergreen.</para>
\r
57 <para>Insert records from the staging table into the <link linkend="actor.table.usr">actor.usr</link> Evergreen table:</para>
\r
58 <programlisting language="sql">
\r
59 INSERT INTO actor.usr (
\r
60 profile, usrname, email, passwd, ident_type, ident_value, first_given_name, family_name, day_phone, home_ou, claims_returned_count,
\r
62 SELECT profile, students.usrname, email, student_id, ident_type, student_id, first_name, last_name, phone, home_ou, claims_returned_count,
\r
68 <para>insert records into <link linkend="actor.table.card">actor.card</link> from <link linkend="actor.table.usr">actor.usr</link>.</para>
\r
69 <programlisting language="sql">
\r
70 INSERT INTO actor.card (usr, barcode)
\r
71 SELECT actor.usr.id, students.barcode
\r
73 INNER JOIN actor.usr
\r
74 ON students.usrname = actor.usr.usrname;
\r
76 <para>This assumes a one to one card patron relationship. If your patron data import has multiple cards assigned to one patron more complex import scripts may be required which look for inactive or active flags.</para>
\r
79 <para>Update actor.usr.card field with actor.card.id to associate active card with the user:</para>
\r
80 <programlisting language="sql">
\r
82 SET card = actor.card.id
\r
84 WHERE actor.card.usr = actor.usr.id;
\r
88 <para>Insert records into <link linkend="actor.table.usr-address">actor.usr_address</link> to add address information for users:</para>
\r
89 <programlisting language="sql">
\r
90 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code)
\r
91 SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, students.country, students.postal_code
\r
93 INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;
\r
97 <para>update <link linkend="actor.table.usr-address">actor.usr.address</link> with address id from address table.</para>
\r
98 <programlisting language="sql">
\r
100 SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id
\r
101 FROM actor.usr_address
\r
102 WHERE actor.usr.id = actor.usr_address.usr;
\r
104 <para>This assumes 1 address per patron. More complex scenarios may require more sophisticated SQL.</para>
\r
108 <title>Creating an sql Script for Importing Patrons</title>
\r
109 <para>The procedure for importing patron can be automated with the help of an sql script. Follow these steps to create an import script:</para>
\r
113 <para>Create an new file and name it <filename>import.sql</filename></para>
\r
118 <para>Edit the file to look similar to this:</para>
\r
122 -- Create staging table.
\r
123 CREATE TABLE students (
\r
124 student_id int, barcode text, last_name text, first_name text, program_number text, program_name text, email text, address_type text,
\r
125 street1 text, street2 text, city text, province text, country text, postal_code text, phone text, profile int, ident_type int, home_ou int,
\r
126 claims_returned_count int DEFAULT 0, usrname text, net_access_level int DEFAULT 2, password text
\r
130 --Insert records from the staging table into the actor.usr table.
\r
131 INSERT INTO actor.usr (
\r
132 profile, usrname, email, passwd, ident_type, ident_value, first_given_name, family_name, day_phone, home_ou, claims_returned_count,
\r
134 SELECT profile, students.usrname, email, student_id, ident_type, student_id, first_name, last_name, phone, home_ou, claims_returned_count,
\r
135 net_access_level FROM students;
\r
137 --Insert records from the staging table into the actor.usr table.
\r
138 INSERT INTO actor.card (usr, barcode)
\r
139 SELECT actor.usr.id, students.barcode
\r
141 INNER JOIN actor.usr
\r
142 ON students.usrname = actor.usr.usrname;
\r
144 --Update actor.usr.card field with actor.card.id to associate active card with the user:
\r
146 SET card = actor.card.id
\r
148 WHERE actor.card.usr = actor.usr.id;
\r
150 --INSERT records INTO actor.usr_address from staging table.
\r
151 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code)
\r
152 SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, students.country, students.postal_code
\r
154 INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;
\r
157 --Update actor.usr mailing address with id from actor.usr_address table.:
\r
159 SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id
\r
160 FROM actor.usr_address
\r
161 WHERE actor.usr.id = actor.usr_address.usr;
\r
165 <para>Placing the sql statements between <code>BEGIN;</code> and <code>COMMIT;</code> creates a transaction block so that if any sql statements fail, the
\r
166 entire process is canceled and the database is rolled back to its original state. Lines beginning with <code>--</code> are comments to let you you what
\r
167 each sql statement is doing and are not processed.</para>
\r
172 <title>Batch Updating Patron Data</title>
\r
173 <para>For academic libraries, doing batch updates to add new patrons to the Evergreen database is a critical task. The above procedures and
\r
174 import script can be easily adapted to create an update script for importing new patrons from external databases. If the data import file contains only new patrons, then,
\r
175 the above procedures will work well to insert those patrons. However, if the data load contains all patrons, a second staging table and a procedure to remove existing patrons from that second staging table may be required before importing the new patrons. Moreover, additional steps to update address information and perhaps delete
\r
176 inactive patrons may also be desired depending on the requirements of the institution.</para>
\r
177 <para>After developing the scripts to import and update patrons have been created, another important task for library staff is to develop an import strategy and schedule
\r
178 which suits the needs of the library. This could be determined by registration dates of your institution in the case of academic libraries. It is important to balance
\r
179 the convenience of patron loads and the cost of processing these loads vs staff adding patrons manually.</para>
\r