commit e14cf80e1aaa232dfba94e07d4bf4d94bbd4143a (tree)
parent 4682cdb31de385551eb890c1e344f4550b6eb5f8
Author: Motiejus Jakštys <desired.mta@gmail.com>
Date: Sat, 26 Oct 2019 15:12:18 +0300
WIP schemas
Diffstat:
5 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/MTM/task4-straipsnis/import.sql b/MTM/task4-straipsnis/import.sql
diff --git a/MTM/task4-straipsnis/init.sql b/MTM/task4-straipsnis/init.sql
@@ -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);
diff --git a/MTM/task4-straipsnis/managedb b/MTM/task4-straipsnis/managedb
@@ -5,12 +5,8 @@ if [[ $1 == init ]]; then
mkdir -p db && initdb db
pg_ctl -D db -l db/logfile start
- psql postgres \
- -c 'CREATE DATABASE airportgames;' \
- -c 'CREATE USER airportgames;' \
- -c 'GRANT ALL PRIVILEGES ON DATABASE airportgames to airportgames;'
- psql -d airportgames \
- -c 'CREATE EXTENSION postgis'
+ psql -c 'CREATE EXTENSION postgis;'
+ psql < init.sql
fi
if [[ $1 == start ]]; then
diff --git a/MTM/task4-straipsnis/schema.sql b/MTM/task4-straipsnis/schema.sql
@@ -9,6 +9,11 @@ CREATE TABLE airports (
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)
diff --git a/MTM/task4-straipsnis/straipsnis.md b/MTM/task4-straipsnis/straipsnis.md
@@ -37,15 +37,14 @@ Susidarys iš kelių dalių:
- Duomenų importavimas.
- 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
-psql airportgames < init.sql
+$ ./managedb init
```
-Atsisiųskime oro uostų informaciją [airports.dat][3] faile ir importuokime į duomenų bazę:
-
[1]: https://en.wikipedia.org/wiki/International_Air_Transport_Association_code