WIP schemas

This commit is contained in:
Motiejus Jakštys 2019-10-26 15:12:18 +03:00
parent 4682cdb31d
commit e14cf80e1a
5 changed files with 39 additions and 11 deletions

View File

View File

@ -0,0 +1,28 @@
-- schema
CREATE TABLE airports (
gid SERIAL NOT NULL PRIMARY KEY,
name TEXT,
city TEXT,
country TEXT,
iata TEXT,
icao TEXT,
geom GEOMETRY,
latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION,
altitude DOUBLE PRECISION,
timezone TEXT,
dst TEXT,
tz TEXT,
type TEXT,
source TEXT,
CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2),
CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POINT'::text OR geom IS NULL),
CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326)
);
-- import data from airports.dat
\copy airports(gid, name, city, country, iata, icao, latitude, longitude, altitude, timezone, dst, tz, type, source) FROM 'airports.dat' DELIMITERS ',' CSV;
-- put lat/lon to the real GIS "geom" field
UPDATE airports
SET geom = ST_SetSRID(ST_Point(longitude, latitude),4326);

View File

@ -5,12 +5,8 @@ if [[ $1 == init ]]; then
mkdir -p db && initdb db mkdir -p db && initdb db
pg_ctl -D db -l db/logfile start pg_ctl -D db -l db/logfile start
psql postgres \ psql -c 'CREATE EXTENSION postgis;'
-c 'CREATE DATABASE airportgames;' \ psql < init.sql
-c 'CREATE USER airportgames;' \
-c 'GRANT ALL PRIVILEGES ON DATABASE airportgames to airportgames;'
psql -d airportgames \
-c 'CREATE EXTENSION postgis'
fi fi
if [[ $1 == start ]]; then if [[ $1 == start ]]; then

View File

@ -9,6 +9,11 @@ CREATE TABLE airports (
latitude DOUBLE PRECISION, latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION, longitude DOUBLE PRECISION,
altitude DOUBLE PRECISION, altitude DOUBLE PRECISION,
timezone TEXT,
dst TEXT,
tz TEXT,
type TEXT,
source TEXT,
CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2), CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2),
CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POINT'::text OR geom IS NULL), CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POINT'::text OR geom IS NULL),
CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326) CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326)

View File

@ -37,15 +37,14 @@ Susidarys iš kelių dalių:
- Duomenų importavimas. - Duomenų importavimas.
- Užklausos. - Užklausos.
Duomenų bazės sukūrimui galite naudoti skriptą: Oro uostų informaciją gausime iš [openflights.org][3]; `airports.dat` failas
jūsų patogumui yra šioje repositorijoje. Sukurkime ir importuokime duomenų bazę
(skriptai paprasti, rekomenduoju peržiūrėti):
``` ```
./managedb init $ ./managedb init
psql airportgames < init.sql
``` ```
Atsisiųskime oro uostų informaciją [airports.dat][3] faile ir importuokime į duomenų bazę:
[1]: https://en.wikipedia.org/wiki/International_Air_Transport_Association_code [1]: https://en.wikipedia.org/wiki/International_Air_Transport_Association_code