Next / Previous / Contents / NM Tech homepage

8. Conversion from the old MySQL database

The previous database schema has been unchanged since 1998. This database currently exists as a MySQL database, and will provide the initial values for the current (Postgresql) version.

The initial setup of the Postgresql database proceeds in these steps.

  1. The script described in Section 7, “The staticloader script: Populate the static tables” drops any existing tables, recreates the database, and then populates the nations and regions tables.

  2. Section 9, “transloader: Copy over the MySQL database” describes the script that populates the rest of the tables from the MySQL database.

8.1. Schema of the 1998 database

The old MySQL database had a very different structure, and was poorly normalized. In particular, there was an unnecessary level of relation in the stnd table, which mapped a key called count ID to a circle, and three other tables used the count ID to link to the stnd table, rather than directly to the circle table. The count ID is a composite of two different fields, and has two different formats depending on the route the data took to get into the database originally:

Count yearCount ID format
001090 YYYNNNNX
091–present YYYSSKK

The YYY portion is the count year, with left zero fill. The rest of this field is the “year key” discussed in Section 3.5, “Year key”.

The part of this key after the YYY part is preserved in the new database, in the year_key column of the efforts table.

Here, then, is an entity-relationship model for the old database. The count ID is used as the key for all the relations shown here, except that the relation from stnd to cir uses the lat_lon column.

Note the two one-to-one relationships. There is one stnd row for each circle-year, and there is no compelling reason to distribute the attributes of a circle-year over two other tables (aspub and eff). So, converting the old schema to the new will lump the old stnd, aspub, and eff tables into the new efforts table.

Refer to the 1998 database specification for a general description of the older schema. Here is a table showing the actual MySQL column names and types.

Table nameColumn nameColumn type
cir lat_lonCHAR(9)
physioVARCHAR(4)
waterCHAR(1)
oddCHAR(1)
regionsVARCHAR(6)
nameVARCHAR(80)
stnd lat_lonCHAR(9)
count_idCHAR(8)
aspub count_idCHAR(8)
as_lat_lonCHAR(9)
as_regionsVARCHAR(6)
as_nameVARCHAR(80)
eff count_idCHAR(8)
yyyymmddCHAR(8)
n_obsINT
ph_totDECIMAL(5,1)
ph_footDECIMAL(5,1)
ph_carDECIMAL(5,1)
ph_oDECIMAL(5,1)
h_fdDECIMAL(5,1)
h_owlDECIMAL(5,1)
pm_totDECIMAL(5,1)
pm_fDECIMAL(5,1)
pm_cDECIMAL(5,1)
pm_oDECIMAL(5,1)
m_owlDECIMAL(5,1)
cen count_idCHAR(8)
seq_noCHAR(3)
formCHAR(6)
relCHAR(1)
alt_formCHAR(6)
ageCHAR(1)
sexCHAR(1)
plusCHAR(1)
qCHAR(1)
censusINT