feat: add bin/services.sh
This commit is contained in:
parent
47b344a62e
commit
7a7be30523
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
echo "Started..."
|
||||
#Started...
|
||||
#
|
||||
# special variable $# is the number of arguments
|
||||
if [ $# -lt 3 ] ; then
|
||||
echo 'Call ./<script> <db name> <db user> <db 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}"
|
||||
#
|
||||
psql -h localhost -p 5432 -U $DB_USER -f ./sql/service.sql -d $DB_NAME -v schema=$DB_SCHEMA
|
||||
#
|
||||
echo "Done."
|
||||
#done.
|
|
@ -3,6 +3,6 @@
|
|||
CREATE SCHEMA IF NOT EXISTS :schema;
|
||||
SET search_path to :schema, public;
|
||||
|
||||
---create view
|
||||
-- create view
|
||||
CREATE OR REPLACE VIEW :schema.vw_route_count AS
|
||||
SELECT count(DISTINCT rts.route_id) AS route_count, rts.agency_id, gncy.agency_name FROM :schema.routes AS rts LEFT JOIN :schema.agency AS gncy ON rts.agency_id = gncy.agency_id GROUP BY rts.agency_id, gncy.agency_name ORDER BY route_count DESC;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS :schema;
|
||||
SET search_path to :schema, public;
|
||||
|
||||
-- create table
|
||||
DROP TABLE IF EXISTS :schema.services;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS :schema.services
|
||||
(
|
||||
service_id text NOT NULL,
|
||||
dates text,
|
||||
CONSTRAINT services_service_id_fkey FOREIGN KEY (service_id) REFERENCES :schema.calendar(service_id)
|
||||
);
|
||||
|
Loading…
Reference in New Issue