From: rsoulliere Date: Tue, 12 Apr 2011 13:54:19 +0000 (-0400) Subject: Update migrating patrons add a few missing steps and fix some types. X-Git-Tag: sprint4-merge-nov22~4203^2~191 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=84af16f73d653eb46d8ec47e7d4b70e490689dd6;p=working%2FEvergreen.git Update migrating patrons add a few missing steps and fix some types. --- diff --git a/1.6/admin/migratingdata_1.6.xml b/1.6/admin/migratingdata_1.6.xml index 94a8132369..26b96bba45 100644 --- a/1.6/admin/migratingdata_1.6.xml +++ b/1.6/admin/migratingdata_1.6.xml @@ -483,8 +483,20 @@ CREATE TABLE students ( net_access_level int DEFAULT 2, password text ); - Note the DEFAULT variables. These allow you to set default for your library or to populate required fields if you data allows - NULL values where fields are required in Evergreen. + Note the DEFAULT variables. These allow you to set default for your library or to populate required fields + if you data allows NULL values where fields are required in Evergreen. + The data field profile in the above SQL script refers to the user group and should be an + integer referencing the id field in + permission.grp_tree. + Setting this value will effect the permissions for the user. See the values in permission.grp_tree for + possibilities. + ident_type is the identification type used for identiying users. This is a integer value referencing + config.identification_type and should + match the id values of that table. The default values are 1 for Drivers License, 2for SSN or + 3for other. + home_ou is the home organizational unit for the user. This value needs to match the corresponding + id in the actor.org_unit + table. 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 @@ -507,6 +519,17 @@ substring(phone from 10), '(', ''), ')', ''), ' ', '-'); + Copy records into staging table from a comma delimited file. + +COPY students (student_id, last_name, first_name, email, address_type, street1, street2, city, province, country, postal_code, phone) + FROM '/home/opensrf/patrons.csv' + WITH CSV HEADER; + + The above script wil vary depending on the format of your patron load file (patrons.csv). You may want to review + PostgreSQL documentation. + + + insert records into actor.card from actor.usr. INSERT INTO actor.card (usr, barcode) @@ -515,7 +538,8 @@ INSERT INTO actor.card (usr, barcode) INNER JOIN actor.usr ON students.usrname = actor.usr.usrname; - 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. + 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. Update actor.usr.card field with actor.card.id to associate active card with the user: @@ -571,7 +595,12 @@ CREATE TABLE students ( ); ---Insert records from the staging table into the actor.usr table. +--Copy records from your import text file +COPY students (student_id, last_name, first_name, email, address_type, street1, street2, city, province, country, postal_code, phone) + FROM '/home/opensrf/patrons.csv' + WITH CSV HEADER; + +--Insert records from the staging table into the actor.usr table INSERT INTO actor.usr ( profile, usrname, email, passwd, ident_type, ident_value, first_given_name, family_name, day_phone, home_ou, claims_returned_count, net_access_level) diff --git a/2.0/admin/migratingdata_2.0.xml b/2.0/admin/migratingdata_2.0.xml index 40e9324785..2fd41c2b05 100644 --- a/2.0/admin/migratingdata_2.0.xml +++ b/2.0/admin/migratingdata_2.0.xml @@ -469,17 +469,38 @@ SELECT DISTINCT ou.id AS circ_lib, Create a staging table.staging table A staging table will allow you to tweak the data before importing. Here is an example sql statement: - sql +sql CREATE TABLE students ( student_id int, barcode text, last_name text, first_name text, email text, address_type text, street1 text, street2 text, - city text, province text, country text, postal_code text, phone text, profile int, + city text, province text, country text, postal_code text, phone text, profile int DEFAULT 2, ident_type int, home_ou int, claims_returned_count int DEFAULT 0, usrname text, net_access_level int DEFAULT 2, password text ); - Note the DEFAULT variables. These allow you to set default for your library or to populate required fields if you data allows - NULL values where fields are required in Evergreen. + Note the DEFAULT variables. These allow you to set default for your library or to populate required fields if you + data allows NULL values where fields are required in Evergreen. + The data field profile in the above SQL script refers to the user group and should be an + integer referencing the id field in + permission.grp_tree. + Setting this value will effect the permissions for the user. See the values in permission.grp_tree for + possibilities. + ident_type is the identification type used for identiying users. This is a integer value referencing + config.identification_type and should match the id values of that table. The default values are + 1 for Drivers License, 2for SSN or 3for other. + home_ou is the home organizational unit for the user. This value needs to match the corresponding + id in the actor.org_unit + table. + + + Copy records into staging table from a comma delimited file. + +COPY students (student_id, last_name, first_name, email, address_type, street1, street2, city, province, country, postal_code, phone) + FROM '/home/opensrf/patrons.csv' + WITH CSV HEADER; + + The above script wil vary depending on the format of your patron load file (patrons.csv). You may want to review + PostgreSQL documentation 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 @@ -488,10 +509,10 @@ CREATE TABLE students ( UPDATE students phone = replace(replace(replace(rpad(substring(phone from 1 for 9), 10, '-') || substring(phone from 10), '(', ''), ')', ''), ' ', '-'); - Data massaging may be required to fit formats used in Evergreen. + Data massaging will be required to fit formats used in Evergreen. - Insert records from the staging table into the actor.usr Evergreen table: + Insert records from the staging table into the actor.usr Evergreen table: INSERT INTO actor.usr ( profile, usrname, email, passwd, ident_type, ident_value, first_given_name, @@ -499,10 +520,11 @@ substring(phone from 10), '(', ''), ')', ''), ' ', '-'); SELECT profile, students.usrname, email, student_id, ident_type, student_id, first_name, last_name, phone, home_ou, claims_returned_count, net_access_level FROM students; - + - insert records into actor.card from actor.usr. + insert records into actor.card from + actor.usr . INSERT INTO actor.card (usr, barcode) SELECT actor.usr.id, students.barcode @@ -565,6 +587,11 @@ CREATE TABLE students ( net_access_level int DEFAULT 2, password text ); +--Copy records from your import text file +COPY students (student_id, last_name, first_name, email, address_type, street1, street2, city, province, country, postal_code, phone) + FROM '/home/opensrf/patrons.csv' + WITH CSV HEADER; + --Insert records from the staging table into the actor.usr table. INSERT INTO actor.usr (