diff --git a/README.md b/README.md deleted file mode 100644 index 10f5c86..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# rgncycle-db - -db for regional cycle \ No newline at end of file diff --git a/doc/connect2db.md b/doc/connect2db.md new file mode 100644 index 0000000..8592ff3 --- /dev/null +++ b/doc/connect2db.md @@ -0,0 +1,8 @@ +* establisch a SSH tunnel like this:\ +``` +ssh -L :: -p @ +``` +* connect to database using pgsl CLI tool like this:\ +``` +psql -h localhost -p 5432 -U -d +``` diff --git a/doc/create-db.md b/doc/create-db.md new file mode 100644 index 0000000..44f174c --- /dev/null +++ b/doc/create-db.md @@ -0,0 +1,4 @@ +* create `entities` table +``` +./script/create-entities-table.sh +``` diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..766bfc2 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +* connect to database like [this](./doc/connect2db.md) + +* create initial database like [this](./doc/create-db.md) \ No newline at end of file diff --git a/script/create-entities-table.sh b/script/create-entities-table.sh new file mode 100755 index 0000000..1dc393b --- /dev/null +++ b/script/create-entities-table.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# +echo "Started..." +#Started... +DB_NAME="osm_poi" +DB_USER="osm_poi" +HIS_HOST="zvbn-his.de" +HIS_USER="zvbn_steckbrief" +HIS_DB="his" +# +#import P+R and B+R data from HIS into tabelle infra.brpr +psql -d $DB_NAME -U $DB_USER -c "DELETE FROM infra.brpr;" +psql -h $HIS_HOST -U $HIS_USER -d $HIS_DB -f /home/${DB_USER}/sql/poi/export_pr_br_02.sql| psql -U $DB_USER -d $DB_NAME -c "COPY infra.brpr(id,kat,name,strasse,plz,gemeinde_his,gemeinde,landkreis,x_gk3,y_gk3,anlage_erkennbar,stellplaetze,emob,betreiber,linien) FROM STDIN WITH DELIMITER AS '|' CSV ;" +# +psql -U $DB_USER -f /home/${DB_USER}/sql/poi/vw_poi_fahrplaner_17.sql -d $DB_NAME +psql -U $DB_USER -c 'DROP VIEW IF EXISTS public.vw_export_poi;' -d $DB_NAME +psql -U $DB_USER -c 'DROP TABLE IF EXISTS public.tbl_poi_fahrplaner;' -d $DB_NAME +psql -U $DB_USER -c 'CREATE TABLE tbl_poi_fahrplaner AS SELECT * FROM vw_poi_fahrplaner;' -d $DB_NAME +#TODO What is the reason for the following instruction? +psql -U $DB_USER -c 'CREATE INDEX ind_gemeinde ON public.tbl_poi_fahrplaner USING btree (gemeinde)' -d $DB_NAME +# +#create VIEW public.vw_export_poi for the POI export(OSM, BR, PR, VVK) +psql -U $DB_USER -d $DB_NAME -f /home/${DB_USER}/sql/poi/gesamtexport_poi_br_pr_vv_10.sql +# +#create exports (second call is for Leaflet map view which uses different separators) +psql -U $DB_USER -d $DB_NAME -c "COPY (SELECT * FROM public.vw_export_poi) TO STDOUT WITH DELIMITER AS ';' CSV HEADER NULL '' QUOTE '\"';" -o /home/${DB_USER}/osm_poi/osm_poi.csv +#TODO Required? psql -U $DB_USER -d $DB_NAME -c "COPY (SELECT * FROM public.vw_export_poi) TO STDOUT WITH DELIMITER AS '^' CSV HEADER NULL '' QUOTE '\"' FORCE QUOTE website,oeffnungszeiten;" -o /home/${DB_USER}/osm_poi/osm_poi_ll.csv +# +#copy files from tmp folder to server main folger +cp /home/${DB_USER}/osm_poi/osm_poi.csv /var/www/poi_utf8_demo.csv +#TODO Required? cp /home/${DB_USER}/osm_poi/osm_poi_ll.csv /var/www/osm_poi_ll_utf8.csv +# +echo "Done." +#done. diff --git a/script/create-relation_roles-table.sh b/script/create-relation_roles-table.sh new file mode 100644 index 0000000..838ed52 --- /dev/null +++ b/script/create-relation_roles-table.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +echo "Started..." +#Started... +DB_NAME="todo" +DB_USER="todo" +# +psql -h localhost -p 5432 -U $DB_USER -f ./sql/create-relation_roles-table.sql -d $DB_NAME +# +echo "Done." +#Done. diff --git a/script/create-relations-table.sh b/script/create-relations-table.sh new file mode 100644 index 0000000..edbb52b --- /dev/null +++ b/script/create-relations-table.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +echo "Started..." +#Started... +DB_NAME="todo" +DB_USER="todo" +# +psql -h localhost -p 5432 -U $DB_USER -f ./sql/create-relations-table.sql -d $DB_NAME +# +echo "Done." +#Done. diff --git a/sql/create-entities-table.sql b/sql/create-entities-table.sql new file mode 100644 index 0000000..dfb7d23 --- /dev/null +++ b/sql/create-entities-table.sql @@ -0,0 +1,6 @@ +--- +DROP TABLE IF EXISTS entities; +--- +CREATE TABLE IF NOT EXISTS entities( + id BIGSERIAL PRIMARY KEY, + name TEXT NOT NULL); diff --git a/sql/create-relation_roles-table.sql b/sql/create-relation_roles-table.sql new file mode 100644 index 0000000..4285ffc --- /dev/null +++ b/sql/create-relation_roles-table.sql @@ -0,0 +1,13 @@ +--- +DROP TABLE IF EXISTS relation_roles; +--- +CREATE TABLE IF NOT EXISTS relation_roles( + id BIGSERIAL PRIMARY KEY, + name TEXT NOT NULL); +--- +DELETE FROM relation_roles; +INSERT INTO relation_roles (name) +VALUES +('supplier'), +('customer') +RETURNING *; diff --git a/sql/create-relations-table.sql b/sql/create-relations-table.sql new file mode 100644 index 0000000..4dd48a3 --- /dev/null +++ b/sql/create-relations-table.sql @@ -0,0 +1,11 @@ +--- +DROP TABLE IF EXISTS relations; +--- +CREATE TABLE IF NOT EXISTS relations( + id BIGSERIAL PRIMARY KEY, + relation_role BIGINT NOT NULL, + from_entity BIGINT NOT NULL, + to_entity BIGINT NOT NULL, + FOREIGN KEY(relation_role) REFERENCES relation_roles(id), + FOREIGN KEY(to_entity) REFERENCES entities(id), + FOREIGN KEY(from_entity) REFERENCES entities(id));