This script will destroy the entire database and rebuild it. Exercise caution with live databases!
This standalone script starts out by dropping all the tables in
the Postgresql database and recreating them according to the new
schema. Then it loads up the nations, regions, and physios tables from the
static files displayed in Section 10, “Static data files”.
The current design assumes that these tables are essentially static. However, keep in mind that one province, Nunavut, was added as recently as 1999.
Once the rest of the database has been loaded, this script cannot be rerun: dropping the nations and regions tables would break foreign key constraints. If a nation, region or physiographic stratum must be added or changed, it will be necessary to write either a quick one-off script to do that, or perhaps write a GUI application to maintain these tables.
The script starts off with the usual line to make it
self-executing under Linux. The sys
module is imported for input and output, and the
pycbc module to connect to the database.
#!/usr/bin/env python
#================================================================
# staticloader: Load the 'nations' and 'regions' tables.
# For documentation, see:
# http://www.nmt.edu/~shipman/z/cbc/pycbc/
#----------------------------------------------------------------
#================================================================
# Imports
#----------------------------------------------------------------
from timer import Timer
t0 = Timer('Imports')
import sys
import pycbc
print t0
Constants include the name of the file where the password lives, and the name of the data files for the nations and regions.
#================================================================ # Manifest constants #---------------------------------------------------------------- PASS_FILE = 'pspass' NATIONS_FILE = 'nationlist' REGIONS_FILE = 'regionlist' PHYSIOS_FILE = 'physiolist'