|
Task Description: Archival of Data and Database Preparation Document Modified: Task: Copy data into ‘historical’ tables for permanent storage and prepare tables for next trapping season. Rationale: To maintain a permanent copy of the trap data
and to clear the tables for a new set of data. Timeline: Annually, usually in early spring prior to
trapping season Brief Process Description:
PLACEMENT, MI_PLACEMENT, MI_PLACEMENT_CTY,
OMITTED_SITES, MI_OMITS, MI_OMITS_CTY, INSPECTION, MI_INSPECTION, MI_INSPECTION_CTY,
PEOPLE, BID_UNIT, SITE_LOCATIONS, SITE_LOCATIONS_CTY
Processes: ARCHIVE DATA The trap data are copied into tables where it will be permanently
stored. The PLACEMENT and OMITTED_SITES data will be copied to the
GM_HISTORICAL table, and the INSPECTION data will be copied to the
GM_HIST_INSPECT table. BEFORE you copy the data, make a FULL EXPORT of the database and run a
FULL OFFLINE DATABASE BACKUP to removable storage media (tape/CD/DVD). (Refer
to the task sheet on database export and offline backup for detailed
instructions.) Keep this backup as a permanent copy of the database at that
point in time. It is rare, but there may be a need to import objects from the
export file at a later date. For instance, you would be able to retrieve the
people table if someone needed information about one or more trappers. This
request has been made once or twice in the past. Copy Trap Placement/Omitted Sites Data: Copy all rows from the trap placement and omitted sites tables at
Virginia Tech and also from the snapshots that contain trap placement and
omitted sites data from MSU (both quad-based and county-based data) into the
GM_HISTORICAL table. The tables to copy are: OMITTED_SITES, PLACEMENT,
MI_OMITS, MI_PLACEMENT, MI_OMITS_CTY, MI_PLACEMENT_CTY.
The ID value is unique for every row in the GM_HISTORICAL table; it
is selected from a sequence as each row is inserted into the table. You will
create the ‘general_use’ sequence beginning one digit greater than the
maximum value in the ID column and then select from this sequence. The current year (format ‘YYYY’) should be inserted into the YEAR
column. The INSERT statements are set up to insert into the columns in the
order shown in the following description. A NULL value must be inserted as a
placeholder for columns with no data. GM_HISTORICAL Table Description: ID NUMBER(6)
SELECT MAX(id) FROM gypsy.gm_historical;
DROP SEQUENCE general_use; (if sequence already
exists) CREATE SEQUENCE general_use START WITH ; (start
with value from the previous query +1)
INSERT INTO gypsy.gm_historical SELECT general_use.nextval, NULL, O.site,
O.utm_east, O.utm_north, O.grid, O.day, NULL, O.county, O.state, O.agency,
NULL, ‘OMIT’, L.initials, NULL, O.utm_east, O.utm_north, NULL, O.project,
O.quad, NULL, 2006, O.gps_data, O.entry_type, O.why, NULL, NULL, NULL,
O.utm_zone, O.elevation FROM gypsy.omitted_sites O, gypsy.people L WHERE (O.state = L.state AND O.trapper = L.id);
INSERT INTO gypsy.gm_historical SELECT general_use.nextval, NULL, P.site,
P.utm_east, P.utm_north, P.grid, P.day, P.total_catch, P.county, P.state,
P.agency, NULL, P.trap_type, L.initials, NULL, P.gridnode_utme,
P.gridnode_utmn, P.sentinel, P.project, P.quad, NULL, 2006, P.gps_data,
P.entry_type, NULL, P.outside_target, P.distance_outside, NULL, P.utm_zone,
P.elevation FROM gypsy.placement P, gypsy.people L WHERE (P.state = L.state AND P.trapper = L.id);
INSERT INTO gypsy.gm_historical SELECT general_use.nextval, NULL, O.site,
O.utm_east, O.utm_north, O.grid, O.day, NULL, O.county, O.state, O.agency,
NULL, ‘OMIT’, L.initials, NULL, O.utm_east, O.utm_north, NULL, O.project,
O.quad, NULL, 2006, O.gps_data, O.entry_type, O.why, NULL, NULL, NULL,
O.utm_zone, O.elevation FROM gypsy.mi_omits O, gypsy.mi_people L WHERE (O.state = L.state AND O.trapper = L.id);
INSERT INTO gypsy.gm_historical SELECT general_use.nextval, NULL, P.site,
P.utm_east, P.utm_north, P.grid, P.day, P.total_catch, P.county, P.state,
P.agency, NULL, P.trap_type, L.initials, NULL, P.gridnode_utme,
P.gridnode_utmn, P.sentinel, P.project, P.quad, NULL, 2006, P.gps_data,
P.entry_type, NULL, P.outside_target, P.distance_outside, NULL, P.utm_zone,
P.elevation FROM gypsy.mi_placement P, gypsy.mi_people L WHERE (P.state = L.state AND P.trapper = L.id);
INSERT INTO gypsy.gm_historical SELECT general_use.nextval, NULL, O.site,
O.utm_east, O.utm_north, O.grid, O.day, NULL, O.county, O.state, O.agency,
NULL, ‘OMIT’, L.initials, NULL, O.utm_east, O.utm_north, NULL, O.project,
O.quad, NULL, 2006, O.gps_data, O.entry_type, O.why, NULL, NULL, O.block_id,
O.utm_zone, O.elevation FROM gypsy.mi_omits_cty O, gypsy.mi_people L WHERE (O.state = L.state AND O.trapper = L.id);
INSERT INTO gypsy.gm_historical SELECT general_use.nextval, NULL, P.site,
P.utm_east, P.utm_north, P.grid, P.day, P.total_catch, P.county, P.state,
P.agency, NULL, P.trap_type, L.initials, NULL, P.gridnode_utme,
P.gridnode_utmn, P.sentinel, P.project, P.quad, NULL, 2006, P.gps_data,
P.entry_type, NULL, P.outside_target, P.distance_outside, P.block_id,
P.utm_zone, P.elevation FROM gypsy.mi_placement_cty P, gypsy.mi_people L WHERE (P.state = L.state AND P.trapper = L.id); Copy Trap Inspection Data: Copy all rows from the trap inspection tables at Virginia Tech and
also from the snapshots that contain trap inspection data from MSU (both
quad-based and county-based data) into the GM_HIST_INSPECT table. The tables
to copy are: INSPECTION, MI_INSPECTION, MI_INSPECTION_CTY.
The ID value is unique for every row in the GM_HIST_INSPECT table; it
is selected from a sequence as each row is inserted into the table. You will
create the ‘general_use’ sequence beginning one digit greater than the
maximum value in the ID column and then select from this sequence. The current year (format ‘YYYY’) should be inserted into the YEAR
column. Since the inspection tables do not include a STATE column, we will
include a subquery to the PLACEMENT table to determine which inspection rows
belong to which state. The appropriate value will be included in the STATE
column as each row is inserted into the GM_HIST_INSPECT table. The INSERT statements are set up to insert into the columns in the
order shown in the following description. A NULL value must be inserted as a
placeholder for columns in which there is no data. GM_HIST_INSPECT Table Description: QUAD VARCHAR2(8)
SELECT MAX(id) FROM gypsy.gm_hist_inspect;
DROP SEQUENCE general_use; (if sequence already
exists) CREATE SEQUENCE general_use START WITH ; (start
with value from the previous query +1)
INSERT INTO gypsy.gm_hist_inspect SELECT A.quad, A.site, A.day, A.visit,
A.condition, A.catch, L.initials, general_use.nextval, NULL, A.field_check,
A.gps_data, A.qc_fail, A.utm_east, A.utm_north, A.entry_type, 2006, ‘KY’,
NULL, NULL, A.utm_zone, A.elevation FROM gypsy.inspection A, gypsy.people L WHERE (A.trapper = L.id) AND (EXISTS (SELECT * FROM gypsy.placement P WHERE
(P.state = ‘KY’) AND (A.quad = P.quad AND A.site = P.site AND A.state
= P.state))); Continue to insert records for each state by
changing the state abbreviation in the sub-query and re-running the INSERT
statement. Also be sure to change the state value appropriately in the INSERT
statement. Insert rows for each of the following states: KY, NC, OH, VA, WV.
INSERT INTO gypsy.gm_hist_inspect SELECT A.quad, A.site, A.day, A.visit,
A.condition, A.catch, L.initials, general_use.nextval, NULL, A.field_check,
A.gps_data, A.qc_fail, A.utm_east, A.utm_north, A.entry_type, 2006, ‘IN’,
NULL, NULL, A.utm_zone, A. elevation FROM gypsy.mi_inspection A, gypsy.mi_people L WHERE (A.trapper = L.id) AND (EXISTS (SELECT * FROM gypsy.mi_placement P
WHERE (P.state = ‘IN’) AND (A.quad = P.quad AND A.site = P.site AND A.state
= P.state))); Insert rows for each of the following states:
IN, MI, MN.
INSERT INTO gypsy.gm_hist_inspect SELECT A.quad, A.site, A.day, A.visit,
A.condition, A.catch, L.initials, general_use.nextval, NULL, A.field_check,
A.gps_data, A.qc_fail, A.utm_east, A.utm_north, A.entry_type, 2006, ‘IL’,
A.county, A.block_id, A. elevation FROM gypsy.mi_inspection_cty A, gypsy.mi_people
L WHERE (A.trapper = L.id) AND (EXISTS (SELECT * FROM gypsy.mi_placement_cty P
WHERE (P.state = ‘IL’) AND (A.state = P.state AND A.county = P.county AND
A.block_id = P.block_id AND A.site = P.site))); Repeat for CLEAR TABLES FOR NEW SURVEY DATA Use the TRUNCATE command to delete all rows from each table. Foreign
key constraints must be disabled before rows can be deleted. Re-enable
constraints after deleting rows. The following tables need to be cleared: BID_UNIT Quad-based Tables (at MSU and VT): Log in to SQL*Plus as GYPSY and execute the following commands: TRUNCATE TABLE site_locations; TRUNCATE TABLE omitted_sites; TRUNCATE TABLE inspection; TRUNCATE TABLE errors; TRUNCATE TABLE first_coordinates; TRUNCATE TABLE test_inspection; TRUNCATE TABLE test_placement; ALTER TABLE inspection DISABLE CONSTRAINT fk_inspect_qdsitest; TRUNCATE TABLE placement; ALTER TABLE inspection ENABLE CONSTRAINT fk_inspect_quad_site; ALTER TABLE site_locations DISABLE CONSTRAINT fk_siteloc_bidstate; TRUNCATE TABLE bid_unit; ALTER TABLE site_locations ENABLE CONSTRAINT fk_siteloc_bidstate; ALTER TABLE people DISABLE
CONSTRAINT fk_people_superid; ALTER TABLE placement DISABLE
CONSTRAINT fk_placement_trapper; ALTER TABLE placement_cty DISABLE
CONSTRAINT fk_place_cty_trapper; ALTER TABLE inspection DISABLE
CONSTRAINT fk_inspect_trapper; ALTER TABLE inspection_cty DISABLE
CONSTRAINT fk_insp_cty_trapper; ALTER TABLE bid_unit DISABLE
CONSTRAINT fk_bidunit_contractor; ALTER TABLE omitted_sites DISABLE
CONSTRAINT fk_omitted_trapper; ALTER TABLE omitted_sites_cty DISABLE
CONSTRAINT fk_omit_cty_trapper; ALTER TABLE site_locations DISABLE
CONSTRAINT fk_siteloc_trapper; ALTER TABLE site_locations DISABLE
CONSTRAINT fk_siteloc_supervisor; ALTER TABLE site_locations_cty DISABLE CONSTRAINT
fk_siteloc_cty_trapper; ALTER TABLE site_locations_cty DISABLE
CONSTRAINT fk_siteloc_cty_supervisor; TRUNCATE TABLE people; ALTER TABLE people ENABLE
CONSTRAINT fk_people_superid; ALTER TABLE placement ENABLE
CONSTRAINT fk_placement_trapper; ALTER TABLE placement_cty ENABLE
CONSTRAINT fk_place_cty_trapper; ALTER TABLE inspection ENABLE
CONSTRAINT fk_inspect_trapper; ALTER TABLE inspection_cty ENABLE
CONSTRAINT fk_insp_cty_trapper; ALTER TABLE bid_unit ENABLE
CONSTRAINT fk_bidunit_contractor; ALTER TABLE omitted_sites ENABLE
CONSTRAINT fk_omitted_trapper; ALTER TABLE omitted_sites_cty ENABLE
CONSTRAINT fk_omit_cty_trapper; ALTER TABLE site_locations ENABLE
CONSTRAINT fk_siteloc_trapper; ALTER TABLE site_locations ENABLE
CONSTRAINT fk_siteloc_supervisor; ALTER TABLE site_locations_cty ENABLE
CONSTRAINT fk_siteloc_cty_trapper; ALTER TABLE site_locations_cty ENABLE
CONSTRAINT fk_siteloc_cty_supervisor; NOTE: not
all constraints on placement_cty and inspect_cty are in place at VT. To house these functionalities at VT, these
need to be copied from MSU and enabled.
(fk_place_cty_trapper, fk_insp_cty_trapper, fk_omit_cty_trapper) County-based Tables (at VT): TRUNCATE TABLE site_locations_cty; County-based Tables (at MSU): TRUNCATE TABLE site_locations_cty; TRUNCATE TABLE omitted_sites_cty; TRUNCATE TABLE inspection_cty; TRUNCATE TABLE first_coordinates_cty; TRUNCATE TABLE test_inspection_cty; TRUNCATE TABLE test_placement_cty; ALTER TABLE inspection_cty DISABLE CONSTRAINT
fk_inspect_cty_blk_site; TRUNCATE TABLE placement_cty; ALTER TABLE inspection_cty ENABLE CONSTRAINT fk_inspect_cty_blk_site; LOAD DATA INTO REFERENCE TABLES Before trap data can be loaded into the database, reference data must
be inserted into the following tables: PEOPLE, SITE_LOCATIONS, SITE_LOCATIONS_CTY. If an agency assigns trapper
territories (a.k.a. bid units) and would like reports organized in this way,
then the BID_UNIT table will also need to be populated for that agency. The
PEOPLE and BID_UNIT tables are loaded just before trapping begins since
agencies usually do not have personnel hired until very close to the start of
the trapping season. There is a referential integrity constraint between the
CONTRACTOR column in the BID_UNIT table and the ID column in the PEOPLE
table, so the trapper data must be inserted into the PEOPLE table before rows
can be entered into the BID_UNIT table. Load Data Into SITE_LOCATIONS and SITE_LOCATIONS_CTY Tables: The predetermined sites are loaded into the SITE_LOCATIONS and
SITE_LOCATIONS_CTY tables. SQL*Loader is used to load all of the
predetermined sites into the tables at Virginia Tech. SELECT statements can
then be run at MSU to populate the SITE_LOCATIONS and SITE_LOCATIONS_CTY
tables there with the sites for IL, IN, MI, MN and WI. The control files for SQL*Loader are located on mothsbane: D:
\data_load\sites\yyyy (where yyyy = year of trapping season) Comma-separated files will be written from the GIS (currently by
Mannin Dodd) which can be loaded into the SITE_LOCATIONS and
SITE_LOCATIONS_CTY tables. Quad-based sites will be written separately from
the county-based sites so that each type can be loaded into the appropriate
table. Mannin will most likely send the ‘sites’ files via email. The files
should be copied to the directory on mothsbane where the control files are
located: SITE_LOCATIONS The control file ‘site_locations_2006.ctl’ is set up to load data from
the ‘sites’ file into the SITE_LOCATIONS table in the following order: UTM_EAST
PROJECT – monit2,
monit1, action, state
SITE_LOCATIONS_CTY The control file ‘site_locations_cty_06.ctl’ is set up to load data
from the ‘sites’ file into the SITE_LOCATIONS_CTY table in the following
order: UTM_EAST
PEOPLE Information about every trapper is stored in the PEOPLE table. A
sequence generates the ID value as each record is entered into the PEOPLE
table. This sequence, PEOPLE_SEQ, can be dropped and re-created before the
new trapper information is entered into the table. It is important that the
name remain unchanged if the sequence is re-created. A trigger executes and
selects the next value from the sequence PEOPLE_SEQ when a row is inserted
into the PEOPLE table. To re-create the sequence, log in to the database as
gypsy and type the following: DROP SEQUENCE
PEOPLE_SEQ; CREATE SEQUENCE
PEOPLE_SEQ START WITH 1; Information about trappers must be entered into the PEOPLE table
before trap data can be entered. The following items MUST be entered for each
trapper: INITIALS Other items such as address and telephone number are optional. BID_UNIT Agencies that assign trappers to specific territories (or bid units) will
provide that information prior to the beginning of the trapping season. The
trapper information must be entered into the PEOPLE table before rows can be
inserted into the BID_UNIT table. The following items must be entered for
each trapper territory: ID (territory number) After all site and trapper information has been loaded, the database
should be ready to accept new trap data. |