feat: add bin/update.sh
This commit is contained in:
parent
0384a5b8ba
commit
ddc1e9a5b1
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
echo "Started..."
|
||||
#Started...
|
||||
#
|
||||
# special variable $# is the number of arguments
|
||||
if [ $# -lt 4 ] ; then
|
||||
echo 'Call ./<script> <db name> <db user> <db schema> <db gtfs schema>'
|
||||
exit 1
|
||||
fi
|
||||
#
|
||||
DB_NAME="$1"
|
||||
echo "DB_NAME: $DB_NAME"
|
||||
DB_USER="$2"
|
||||
echo "DB_USER: $DB_USER"
|
||||
DB_SCHEMA="$3"
|
||||
echo "DB_SCHEMA: ${DB_SCHEMA}"
|
||||
DB_SCHEMA_GTFS="$4"
|
||||
echo "DB_SCHEMA_GTFS: ${DB_SCHEMA_GTFS}"
|
||||
#
|
||||
psql -h localhost -p 5432 -U $DB_USER -f ./sql/update.sql -d $DB_NAME -v schema_gtfs=$DB_SCHEMA_GTFS -v schema=$DB_SCHEMA
|
||||
#
|
||||
echo "Done."
|
||||
#done.
|
|
@ -0,0 +1,30 @@
|
|||
---clean up schema
|
||||
DROP SCHEMA IF EXISTS :schema CASCADE;
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS :schema;
|
||||
CREATE SCHEMA IF NOT EXISTS :schema_gtfs;
|
||||
SET search_path to :schema, :schema_gtfs, public;
|
||||
|
||||
---get subset of stops with location type 0
|
||||
|
||||
---create views
|
||||
CREATE OR REPLACE VIEW :schema.vw_stops_lt_0 AS
|
||||
SELECT * FROM :schema_gtfs.stops WHERE location_type=0;
|
||||
|
||||
---create tables
|
||||
CREATE TABLE IF NOT EXISTS :schema.tbl_stops_lt_0 AS SELECT stop_id,stop_name,stop_lat,stop_lon,the_geom FROM :schema.vw_stops_lt_0;
|
||||
|
||||
---get subset of stops that do not comply with a proper Global ID
|
||||
|
||||
---create views
|
||||
CREATE OR REPLACE VIEW :schema.vw_stops_not_dhid AS
|
||||
SELECT * FROM :schema_gtfs.stops WHERE stop_id NOT LIKE '%:%:%' ORDER BY stop_id;
|
||||
|
||||
CREATE OR REPLACE VIEW :schema.vw_stops_lt_0_not_dhid AS
|
||||
SELECT * FROM :schema.tbl_stops_lt_0 WHERE stop_id NOT LIKE '%:%:%' ORDER BY stop_id;
|
||||
|
||||
---create tables
|
||||
CREATE TABLE IF NOT EXISTS :schema.tbl_stops_not_dhid AS SELECT stop_id,stop_name,stop_lat,stop_lon,the_geom FROM :schema.vw_stops_not_dhid;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS :schema.tbl_stops_lt_0_not_dhid AS SELECT stop_id,stop_name,stop_lat,stop_lon,the_geom FROM :schema.vw_stops_lt_0_not_dhid;
|
||||
|
Loading…
Reference in New Issue