-db: data
- dropdb -U $(DB_USER) $(DB_NAME)
- createdb -U $(DB_USER) $(DB_NAME)
- createlang -U $(DB_USER) plpgsql $(DB_NAME)
-
- psql -d $(DB_NAME) \
- -U $(DB_USER) \
- -f /usr/share/postgresql/contrib/lwpostgis.sql
-
- psql -d $(DB_NAME) \
- -U $(DB_USER) \
- -f /usr/share/postgresql/contrib/spatial_ref_sys.sql
+db: data newdb tiger_blocks_table tiger_lines_table sf1_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 \
+ $(PG_BINDIR)/shp2pgsql \
+ -a \
+ -s $(TIGER_SRID) \
+ -D \
+ $$state/blocks/*.shp \
+ tiger_blocks \
+ | psql -U $(DB_USER) -d $(DB_NAME); \
+ done;
+
+# 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."; \
+ $(PG_BINDIR)/shp2pgsql \
+ -a \
+ -s $(TIGER_SRID) \
+ $$shapefile \
+ tiger_lines \
+ | bin/filter-transactions \
+ | psql -U $(DB_USER) -d $(DB_NAME) \
+ > /dev/null; \
+ done; \
+ 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 postgres -d $(DB_NAME) \
+ > /dev/null; \
+ done;