]> git.evergreen-ils.org Git - working/Evergreen.git/blob - 1.6/admin/migratingdata.xml
Found more typos.
[working/Evergreen.git] / 1.6 / admin / migratingdata.xml
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
4         <info>          \r
5         <title>Migrating Data</title>\r
6                 <abstract>\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
10                 </abstract>\r
11         </info>    \r
12         <section xml:id="migratingpatrons">\r
13                 <title>Migrating Patron Data</title>\r
14                 <para>\r
15                 This section will explain the task of migrating your patron data from Comma Delimited Files into Evergreen. It does not deal with the process of exporting from the non-Evergreen \r
16                 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
17                 academic records.               \r
18                 </para>\r
19                 <para>When importing records into Evergreen you will need to populate 3 tables in your Evergreen database:</para>\r
20                 <itemizedlist>\r
21                         <listitem><link linkend="actor.table.usr">actor.usr</link> - This is the main table for user data</listitem>\r
22                         <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
23                         <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
24                 </itemizedlist>\r
25                 <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
26                 for data to include \r
27                 in your import. It is important to understand the data types and constraints of the fields.</para>\r
28                 <procedure>\r
29                         <step>\r
30                                 <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 the records should \r
31                                 use Unicode (UTF8) character encoding.</para>\r
32                         </step>\r
33                         <step>\r
34                                 <para>Create a staging table. A staging table will allow you to tweak the data before importing. Here is an example sql statement:</para>\r
35 <programlisting language="sql">\r
36 CREATE TABLE students (\r
37         student_id int, barcode text, last_name text, first_name text, program_number text, program_name text, email text, address_type text, street1 text, street2 text, city text, province text, \r
38         country text, postal_code text, phone text, profile int, ident_type int, home_ou int, claims_returned_count int DEFAULT 0, usrname text, net_access_level int DEFAULT 2, password text\r
39 ); \r
40 </programlisting>\r
41                                 <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 NULL values where \r
42                                 fields are required in Evergreen.</para>\r
43                         </step>\r
44                         <step>\r
45                                 <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
46                                 table top fit the evergreen field:</para>\r
47 <programlisting language="sql">\r
48 UPDATE students phone = replace(replace(replace(rpad(substring(phone from 1 for 9), 10, '-') || substring(phone from 10), '(', ''), ')', ''), ' ', '-');\r
49 </programlisting>\r
50                                 <para>Data <quote>massaging</quote> may be required to fit formats used in Evergreen.</para>\r
51                         </step>\r
52                         <step>\r
53                                 <para>Insert records from the staging table into the <link linkend="actor.table.usr">actor.usr</link> Evergreen table:</para>\r
54 <programlisting language="sql">\r
55  INSERT INTO actor.usr (\r
56         profile, usrname, email, passwd, ident_type, ident_value, first_given_name, family_name, day_phone, home_ou, claims_returned_count, net_access_level) SELECT profile, students.usrname, \r
57         email, student_id, ident_type, student_id, first_name, last_name, phone, home_ou, claims_returned_count, net_access_level FROM students;\r
58 </programlisting>                       \r
59                         </step>\r
60                         <step>\r
61                                 <para>insert records into <link linkend="actor.table.card">actor.card</link> from <link linkend="actor.table.usr">actor.usr</link>.</para>\r
62 <programlisting language="sql">\r
63 INSERT INTO actor.card (usr, barcode) \r
64         SELECT actor.usr.id, students.barcode \r
65         FROM students \r
66                 INNER JOIN actor.usr \r
67                         ON students.usrname = actor.usr.usrname;\r
68 </programlisting>               \r
69                                 <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
70                         </step>\r
71                         <step>\r
72                                 <para>Update actor.usr.card field with actor.card.id to associate active card with the user:</para>\r
73 <programlisting language="sql">\r
74 UPDATE actor.usr \r
75         SET card = actor.card.id \r
76         FROM actor.card \r
77         WHERE actor.card.usr = actor.usr.id;\r
78 </programlisting>                       \r
79                         </step>\r
80                         <step>\r
81                                 <para>Insert records into actor.usr_address to add address information for users:</para>\r
82 <programlisting language="sql">\r
83 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code) \r
84         SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, students.country, students.postal_code \r
85         FROM students \r
86         INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;\r
87 </programlisting>                       \r
88                         </step>\r
89                         <step>\r
90                                 <para>update actor.usr.address with address id from address table.</para>\r
91 <programlisting language="sql">\r
92 UPDATE actor.usr \r
93         SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id \r
94         FROM actor.usr_address \r
95         WHERE actor.usr.id = actor.usr_address.usr;\r
96 </programlisting>       \r
97                         <para>This assumes 1 address per student. More complex scenarios may require more sophisticated SQL.</para>             \r
98                         </step>\r
99                 </procedure>\r
100                 <simplesect>\r
101                         <title>Creating an sql Script for Importing Patrons</title>\r
102                         <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
103                 \r
104                         <procedure>\r
105                                 <step>\r
106                                         <para>Create an new file and name it <filename>import.sql</filename></para>\r
107 \r
108                                 </step>\r
109 \r
110                                 <step>\r
111                                         <para>Edit the file to look similar to this:</para>\r
112 <programlisting>\r
113 BEGIN;\r
114 \r
115 -- Create staging table.\r
116 CREATE TABLE students (\r
117         student_id int, barcode text, last_name text, first_name text, program_number text, program_name text, email text, address_type text, street1 text, street2 text, city text, province text, \r
118         country text, postal_code text, phone text, profile int, ident_type int, home_ou int, claims_returned_count int DEFAULT 0, usrname text, net_access_level int DEFAULT 2, password text\r
119 ); \r
120 \r
121 \r
122 --Insert records from the staging table into the actor.usr table.\r
123 INSERT INTO actor.usr (\r
124         profile, usrname, email, passwd, ident_type, ident_value, first_given_name, family_name, day_phone, home_ou, claims_returned_count, net_access_level) SELECT profile, students.usrname, \r
125         email, student_id, ident_type, student_id, first_name, last_name, phone, home_ou, claims_returned_count, net_access_level FROM students;\r
126 \r
127 --Insert records from the staging table into the actor.usr table.\r
128 INSERT INTO actor.card (usr, barcode) \r
129         SELECT actor.usr.id, students.barcode \r
130         FROM students \r
131                 INNER JOIN actor.usr \r
132                         ON students.usrname = actor.usr.usrname;\r
133 \r
134 --Update actor.usr.card field with actor.card.id to associate active card with the user:\r
135 UPDATE actor.usr \r
136         SET card = actor.card.id \r
137         FROM actor.card \r
138         WHERE actor.card.usr = actor.usr.id;\r
139 \r
140 --INSERT records INTO actor.usr_address from staging table.\r
141 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code) \r
142         SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, students.country, students.postal_code \r
143         FROM students \r
144         INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;\r
145 \r
146 \r
147 --Update actor.usr mailing address with id from actor.usr_address table.:\r
148 UPDATE actor.usr \r
149         SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id \r
150         FROM actor.usr_address \r
151         WHERE actor.usr.id = actor.usr_address.usr;\r
152 \r
153 COMMIT;\r
154 </programlisting>\r
155                                         <para>Placing the sql statements between <code>BEGIN;</code> and <code>COMMIT;</code> creates a transaction block so that if any statements fail, the \r
156                                         entire process is canceled and the database is rolled back to its original state. Lines beginning with <emphasis>--</emphasis> are comments to let you you what \r
157                                         each sql statement is doing and are not processed.</para> \r
158                                 </step>\r
159                         </procedure>\r
160                 </simplesect>\r
161                 <simplesect>\r
162                         <title>Batch Updating Patron Data</title>\r
163                         <para>For academic libraries, doing batch updates to add new patrons to the Evergreen database is a critical task. The above procedures and \r
164                         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
165                         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
166                         inactive patrons may also be desired depending on the requirements of the institution.</para>\r
167                         <para>After developing the scripts to import and update patrons have been created, another important task of library staff is to develop an strategy and schedule \r
168                         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
169                         the convenience of patron loads and the cost of processing these loads vs staff adding patrons as needed.</para>   \r
170                </simplesect> \r
171         </section>\r
172 </chapter>\r