+# There is a small issue here with the blocks_db and lines_db
+# targets. Each of these requires that the database exists, and might
+# therefore depend on the newdb target. However, if /each/ of them
+# depends on newdb, the database will be dropped twice and the data
+# from one of {blocks, lines} would be lost.
+#
+# We therefore assume that the database already exists when blocks_db
+# or lines_db are initiated.
+blocks_db: data blocks_table
+# All Blocks
+#
+# The table already exists, so we can append to it, and we don't have
+# to create the GiST index.
+ for state in data/census2000/*; do \
+ $(SHP2PGSQL) \
+ -a \
+ -s $(TIGER_SRID) \
+ -D \
+ $$state/blocks/*.shp \
+ tiger_blocks \
+ | psql -U $(DB_USER) -d $(DB_NAME); \
+ done;
+
+# Summary File 1
+#
+# Run all of the geo (uf1) files through the import script. This has
+# to happen after the blocks import since we impose a foreign key
+# restriction.
+ for state in data/census2000/*; do \
+ bin/sf1blocks2sql $$state/sf1/*.uf1 sf1_blocks \
+ | psql -U $(DB_USER) -d $(DB_NAME) \
+ > /dev/null; \
+ done;
+
+# Run the query to combine the two blocks tables, and drop the
+# constituents.
+ psql -U $(DB_USER) \
+ -d $(DB_NAME) \
+ -f sql/combine-block-tables.sql
+
+
+lines_db: data tiger_lines_table
+# All Lines
+#
+# Since the table and index already exist, we can utilize -a,
+# and leave -I out.
+ for state in data/census2000/*; do \
+ for shapefile in $$state/lines/*.shp; do \
+ echo "Importing $$shapefile."; \
+ $(SHP2PGSQL) \
+ -a \
+ -s $(TIGER_SRID) \
+ $$shapefile \
+ tiger_lines \
+ | bin/filter-transactions \
+ | psql -U $(DB_USER) -d $(DB_NAME) \
+ > /dev/null; \
+ done; \
+ done;
+
+
+
+# This imports the Tiger data using shp2pgsql. The shapefiles
+# should exist, since this task depends on the "data" task, which
+# downloads said shapefiles.
+#
+# After the TIGER import is done, we use the sf1blocks2sql script to
+# parse and import the geographic header record information.
+#
+db: newdb blocks_data lines_data
+ # Do nothing except fulfill our prerequisites.