Skip to content

Commit f58fc92

Browse files
committed
[db] Adding support for PostgreSQL
1 parent ac25979 commit f58fc92

21 files changed

+842
-325
lines changed

config/FindSOCIPostgreSQL.cmake

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Find SOCI includes and library for core and PostgreSQL.
3+
# Following are the variables defined by the FindSOCI*.cmake macros:
4+
# SOCI_VERSION - The SOCI version, e.g, 300100
5+
# SOCI_LIB_VERSION - The SOCI library version, e.g., 3_1_0
6+
# SOCI_HUMAN_VERSION - The SOCI human-readable version, e.g., 3.1.0
7+
# SOCI_INCLUDE_DIR - Where to find soci.h, etc.
8+
# SOCI_LIBRARIES - List of libraries when using SOCI.
9+
# SOCI_FOUND - Whether SOCI has been found
10+
# SOCIPostgreSQL_INCLUDE_DIR - Where to find soci-postgresql.h, etc.
11+
# SOCIPostgreSQL_LIBRARIES - List of libraries when using SOCI PostgreSQL.
12+
# SOCIPostgreSQL_FOUND - Whether the SOCI PostgreSQL library has been found
13+
#
14+
# Note: it is assumed that the _required_version variable be set before
15+
# calling 'find_package (SOCIPostgreSQL)'
16+
17+
# First, check for SOCI core
18+
find_package (SOCI ${_required_version} REQUIRED)
19+
20+
# Check for SOCI PostgreSQL main header.
21+
set (CHECK_HEADERS soci/postgresql/soci-postgresql.h)
22+
if (SOCIPostgreSQL_INCLUDE_DIR)
23+
find_path (SOCIPostgreSQL_INCLUDE_DIR
24+
NAMES ${CHECK_HEADERS}
25+
PATHS ${SOCI_POSTGRESQL_INCLUDE_DIR}
26+
NO_DEFAULT_PATH)
27+
else (SOCIPostgreSQL_INCLUDE_DIR)
28+
find_path (SOCIPostgreSQL_INCLUDE_DIR
29+
NAMES ${CHECK_HEADERS}
30+
PATHS ${SOCI_INCLUDE_DIR})
31+
endif (SOCIPostgreSQL_INCLUDE_DIR)
32+
33+
# Check for SOCI PostgreSQL library
34+
set (CHECK_LIBRARIES soci_postgresql soci_postgresql-gcc-3_0)
35+
if (SOCIPostgreSQL_LIBRARY_DIR)
36+
find_library (SOCIPostgreSQL_LIBRARIES
37+
NAMES ${CHECK_LIBRARIES}
38+
PATHS ${SOCIPostgreSQL_LIBRARY_DIR}
39+
NO_DEFAULT_PATH)
40+
else (SOCIPostgreSQL_LIBRARY_DIR)
41+
find_library (SOCIPostgreSQL_LIBRARIES
42+
NAMES ${CHECK_LIBRARIES}
43+
PATH_SUFFIXES soci)
44+
endif (SOCIPostgreSQL_LIBRARY_DIR)
45+
46+
#
47+
include (FindPackageHandleStandardArgs)
48+
find_package_handle_standard_args (SOCIPostgreSQL
49+
REQUIRED_VARS SOCIPostgreSQL_LIBRARIES SOCIPostgreSQL_INCLUDE_DIR
50+
VERSION_VAR SOCI_HUMAN_VERSION)
51+
52+
if (SOCIPostgreSQL_FOUND)
53+
mark_as_advanced (SOCIPostgreSQL_FOUND SOCIPostgreSQL_LIBRARIES SOCIPostgreSQL_INCLUDE_DIR)
54+
else (SOCIPostgreSQL_FOUND)
55+
message (FATAL_ERROR "Could not find the SOCI PostgreSQL libraries! Please install the development-libraries and headers (e.g., 'soci-postgresql-devel' for Fedora/RedHat).")
56+
endif (SOCIPostgreSQL_FOUND)
57+

config/project_config_embeddable.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,20 @@ macro (get_soci)
949949
include_directories (${SOCI_INCLUDE_DIR})
950950
endif (SOCI_FOUND)
951951

952+
# SOCI PostgreSQL
953+
find_package (SOCIPostgreSQL ${_required_version} REQUIRED)
954+
if (SOCIPostgreSQL_FOUND)
955+
#
956+
message (STATUS "Found SOCI with PostgreSQL back-end support version:"
957+
" ${SOCI_HUMAN_VERSION}")
958+
959+
# Update the list of include directories for the project
960+
include_directories (${SOCIPostgreSQL_INCLUDE_DIR})
961+
962+
# Update the list of dependencies for the project
963+
list (APPEND PROJ_DEP_LIBS_FOR_LIB ${SOCI_LIBRARIES} ${SOCIPostgreSQL_LIBRARIES})
964+
endif (SOCIPostgreSQL_FOUND)
965+
952966
# SOCI MySQL
953967
find_package (SOCIMySQL ${_required_version} REQUIRED)
954968
if (SOCIMYSQL_FOUND)
@@ -2798,9 +2812,11 @@ macro (display_soci)
27982812
message (STATUS " - SOCI_LIB_VERSION .............. : ${SOCI_LIB_VERSION}")
27992813
message (STATUS " - SOCI_HUMAN_VERSION ............ : ${SOCI_HUMAN_VERSION}")
28002814
message (STATUS " - SOCI_INCLUDE_DIR .............. : ${SOCI_INCLUDE_DIR}")
2815+
message (STATUS " - SOCIPostgreSQL_INCLUDE_DIR .... : ${SOCIPostgreSQL_INCLUDE_DIR}")
28012816
message (STATUS " - SOCIMYSQL_INCLUDE_DIR ......... : ${SOCIMYSQL_INCLUDE_DIR}")
28022817
message (STATUS " - SOCISQLITE_INCLUDE_DIR ........ : ${SOCISQLITE_INCLUDE_DIR}")
28032818
message (STATUS " - SOCI_LIBRARIES ................ : ${SOCI_LIBRARIES}")
2819+
message (STATUS " - SOCIPostgreSQL_LIBRARIES ...... : ${SOCIPostgreSQL_LIBRARIES}")
28042820
message (STATUS " - SOCIMYSQL_LIBRARIES ........... : ${SOCIMYSQL_LIBRARIES}")
28052821
message (STATUS " - SOCISQLITE_LIBRARIES .......... : ${SOCISQLITE_LIBRARIES}")
28062822
endif (SOCI_FOUND)

data/CMakeLists.txt

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@ set (OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
1616
set (top_srcdir ${CMAKE_SOURCE_DIR} )
1717
set (srcdir ${CMAKE_CURRENT_SOURCE_DIR})
1818

19-
set (por_data_DIR por)
19+
set (por_data_DIR por)
20+
set (por_csv_data_DIR por/csv)
21+
set (por_pg_data_DIR por/pg)
22+
set (por_sqlite_data_DIR por/sqlite)
23+
set (por_mysql_data_DIR por/mysql)
24+
2025
set (OPENTREP_DATA_DIR ${OPENTREP_SAMPLE_DIR}/${por_data_DIR})
26+
set (OPENTREP_DATA_CSV_DIR ${OPENTREP_SAMPLE_DIR}/${por_csv_data_DIR})
27+
set (OPENTREP_DATA_PG_DIR ${OPENTREP_SAMPLE_DIR}/${por_pg_data_DIR})
28+
set (OPENTREP_DATA_SQLITE_DIR ${OPENTREP_SAMPLE_DIR}/${por_sqlite_data_DIR})
29+
set (OPENTREP_DATA_MYSQL_DIR ${OPENTREP_SAMPLE_DIR}/${por_mysql_data_DIR})
2130

2231
##
2332
# Installation of the documentation files (written in Markup Doc format)
@@ -26,17 +35,26 @@ install (DIRECTORY ${por_data_DIR} DESTINATION ${OPENTREP_SAMPLE_DIR}
2635

2736
##
2837
# Installation of the schemas (DDL) and data files (DML).
29-
install (DIRECTORY ${por_data_DIR} DESTINATION ${OPENTREP_SAMPLE_DIR}
30-
FILES_MATCHING PATTERN "*.sql")
31-
install (DIRECTORY ${por_data_DIR} DESTINATION ${OPENTREP_SAMPLE_DIR}
32-
FILES_MATCHING PATTERN "*.csv")
33-
install (DIRECTORY ${por_data_DIR} DESTINATION ${OPENTREP_SAMPLE_DIR}
34-
FILES_MATCHING PATTERN "*.csv.bz2")
35-
install (DIRECTORY ${por_data_DIR} DESTINATION ${OPENTREP_SAMPLE_DIR}
36-
FILES_MATCHING PATTERN "*.db")
37-
install (DIRECTORY ${por_data_DIR} DESTINATION ${OPENTREP_SAMPLE_DIR}
38-
FILES_MATCHING PATTERN "*.db.bz2")
38+
# CSV samples
39+
install (DIRECTORY ${por_csv_data_DIR}
40+
DESTINATION ${OPENTREP_DATA_DIR}
41+
FILES_MATCHING PATTERN "*.*")
42+
43+
# PostgreSQL admin scripts
44+
install (DIRECTORY ${por_pg_data_DIR}
45+
DESTINATION ${OPENTREP_DATA_DIR}
46+
FILES_MATCHING PATTERN "*.*")
47+
48+
# MySQL admin scripts
49+
install (DIRECTORY ${por_mysql_data_DIR}
50+
DESTINATION ${OPENTREP_DATA_DIR}
51+
FILES_MATCHING PATTERN "*.*")
52+
53+
# SQLite admin scripts
54+
install (DIRECTORY ${por_sqlite_data_DIR}
55+
DESTINATION ${OPENTREP_DATA_DIR}
56+
FILES_MATCHING PATTERN "*.*")
3957

4058
##
4159
# Installing database scripts
42-
# module_script_add (${por_data_DIR}/opentrep_create_db_user.sh)
60+
module_script_add (${por_data_DIR}/pg/opentrep-create-db-user.sh)

data/por/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
OpenTravelData (OPTD) POR Data
2-
------------------------------
2+
==============================
33

44
This directory contains POR (Points Of Reference) data files.
5-
The main data file is named `optd_por_public.csv`, whose master is located
5+
The main data file is named `optd_por_public.csv`, whose source is located
66
on the [OpenTravelData (OPTD) project on GitHub](https://github.com/opentraveldata/opentraveldata):
77
[`opentraveldata/optd_por_public.csv`](https://github.com/opentraveldata/opentraveldata/blob/master/opentraveldata/optd_por_public.csv).
88

9-
The data files are also available from https://transport-search.org/data/optd/por/
9+
The data files are also available from
10+
https://www2.transport-search.org/data/optd/por/
1011

1112
Good complementary tools are:
1213
* [OpenTravelData Python wrapper](https://github.com/opentraveldata/python-opentraveldata),
@@ -15,8 +16,7 @@ Good complementary tools are:
1516
(deprecating [GeoBase](https://opentraveldata.github.io/geobases)),
1617
a Python-based utility able to access to any transport-related data source
1718

18-
Licensing
19-
---------
19+
# Licensing
2020
The data in this directory and repository are governed by the
2121
[CC-BY-SA license](http://creativecommons.org/licenses/by-sa/3.0/).
2222

File renamed without changes.

data/por/opentrep_create_db_user.sh.in renamed to data/por/mysql/opentrep-create-db-user.sh.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
#
3+
# File: https://github.com/trep/opentrep/tree/master/data/por/mysql/opentrep-create-db-user.sh.in
24
#
35
# Two parameters are optional for this script:
46
# - the host server of the database
@@ -56,5 +58,5 @@ executeSQLScriptAsAdmin() {
5658
}
5759

5860
# Creating the 'trep' user and the corresponding 'trep_trep' database
59-
SQL_FILE="@INSTALL_DATA_DIR@/opentrep/data/por/create_trep_user_and_db.sql"
61+
SQL_FILE="@INSTALL_DATA_DIR@/opentrep/data/por/mysql/create-trep-user-and-db.sql"
6062
executeSQLScriptAsAdmin

data/por/pg/create-trep-tables.sql

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--
2+
-- File: https://github.com/trep/opentrep/tree/master/data/por/pg/create-trep-tables.sql
3+
--
4+
-- OPTD-maintained list of POR (points of reference, i.e., airports, cities,
5+
-- places, etc.)
6+
-- See http://github.com/opentraveldata/opentraveldata/tree/master/opentraveldata
7+
--
8+
9+
drop table if exists optd_por;
10+
create table optd_por (
11+
pk varchar(20) NOT NULL,
12+
location_type varchar(4) default NULL,
13+
iata_code varchar(3) default NULL,
14+
icao_code varchar(4) default NULL,
15+
faa_code varchar(4) default NULL,
16+
unlocode_code varchar(5) default NULL,
17+
is_geonames varchar(1) default NULL,
18+
geoname_id int default NULL,
19+
envelope_id int default NULL,
20+
date_from date default NULL,
21+
date_until date default NULL,
22+
serialised_place varchar(12000) default NULL
23+
);
24+
25+
--
26+
-- PostgreSQL standard load statement (however, there is no correspondance
27+
-- between the table and CSV file formats)
28+
--
29+
-- load data local infile 'optd_por_public.csv' replace into table optd_por
30+
-- character set utf8 columns terminated by '^' ignore 1 lines;
31+
32+
33+
--
34+
-- Indices
35+
--
36+
create unique index optd_por_pk on optd_por (pk);
37+
create index optd_por_iata_code on optd_por (iata_code asc);
38+
create index optd_por_iata_date on optd_por (iata_code asc, date_from asc, date_until asc);
39+
create index optd_por_icao_code on optd_por (icao_code asc);
40+
create index optd_por_geonameid on optd_por (geoname_id asc);
41+
create index optd_por_unlocode_code on optd_por (unlocode_code asc);

0 commit comments

Comments
 (0)