Skip to content

Commit

Permalink
add postgres+postgis container in docker compose
Browse files Browse the repository at this point in the history
postgres+postgis is required to run mosaic server
  • Loading branch information
kalenikaliaksandr committed Apr 14, 2023
1 parent 8aa6367 commit b59de77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ services:
- ./index.js:/app/index.js
- ./newrelic.js:/app/newrelic.js
- ./package.json:/app/package.json
postgres:
build:
context: ./postgres
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
worker:
extends: app
environment:
Expand All @@ -45,9 +50,11 @@ services:
depends_on:
- mongo
- register
- postgres
links:
- mongo
- register
- postgres
volumes:
- ./bin:/app/bin
- ./controllers:/app/controllers
Expand Down
3 changes: 3 additions & 0 deletions postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgis/postgis:14-3.3

COPY schema.sql /docker-entrypoint-initdb.d/
30 changes: 16 additions & 14 deletions schema.sql → postgres/schema.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CREATE EXTENSION btree_gist;

-- STEP1 create table layers
DROP TABLE IF EXISTS public.layers;
CREATE TABLE public.layers (
DROP TABLE IF EXISTS layers;
CREATE TABLE layers (
id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
public_id text NOT NULL,
"name" text NULL,
Expand All @@ -18,7 +20,7 @@ CREATE TABLE public.layers (
properties jsonb NULL,
is_dirty bool NULL,
zoom_visibility_rules jsonb NULL,
geom public.geometry NULL,
geom geometry NULL,
is_visible bool NULL DEFAULT false,
feature_properties jsonb NULL,
api_key varchar NULL,
Expand All @@ -31,11 +33,11 @@ CREATE TABLE public.layers (
CONSTRAINT layers_pkey PRIMARY KEY (id),
CONSTRAINT layers_public_id_key UNIQUE (public_id)
);
CREATE INDEX layers_geom_idx ON public.layers USING gist (geom);
CREATE INDEX layers_geom_idx ON layers USING gist (geom);


-- STEP2 populate table layers with feature for openaerialmap
insert into public.layers(
insert into layers(
public_id,
name,
url,
Expand Down Expand Up @@ -70,20 +72,20 @@ select


-- STEP3 creating table layers_features
DROP TABLE IF EXISTS public.layers_features;
CREATE TABLE public.layers_features (
DROP TABLE IF EXISTS layers_features;
CREATE TABLE layers_features (
feature_id text NOT NULL,
layer_id int4 NOT NULL,
properties jsonb NULL,
geom public.geometry NULL,
geom geometry NULL,
last_updated timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
zoom int4 NULL DEFAULT 999,
CONSTRAINT layers_features_feature_id_layer_id_zoom_key UNIQUE (feature_id, layer_id, zoom)
);
CREATE INDEX layers_features_3857_idx ON public.layers_features USING gist (st_transform(geom, 3857));
CREATE INDEX layers_features_layer_id_3857_idx ON public.layers_features USING gist (layer_id, st_transform(geom, 3857));
CREATE INDEX layers_features_layer_id_geom_idx ON public.layers_features USING gist (layer_id, geom);
CREATE INDEX layers_features_layer_id_zoom_geom_idx ON public.layers_features USING gist (layer_id, zoom, geom);
CREATE INDEX layers_features_zoom_idx ON public.layers_features USING btree (zoom);
CREATE INDEX layers_features_3857_idx ON layers_features USING gist (st_transform(geom, 3857));
CREATE INDEX layers_features_layer_id_3857_idx ON layers_features USING gist (layer_id, st_transform(geom, 3857));
CREATE INDEX layers_features_layer_id_geom_idx ON layers_features USING gist (layer_id, geom);
CREATE INDEX layers_features_layer_id_zoom_geom_idx ON layers_features USING gist (layer_id, zoom, geom);
CREATE INDEX layers_features_zoom_idx ON layers_features USING btree (zoom);

ALTER TABLE public.layers_features ADD CONSTRAINT layers_features_layer_id_fkey FOREIGN KEY (layer_id) REFERENCES public.layers(id) ON DELETE CASCADE;
ALTER TABLE layers_features ADD CONSTRAINT layers_features_layer_id_fkey FOREIGN KEY (layer_id) REFERENCES layers(id) ON DELETE CASCADE;

0 comments on commit b59de77

Please sign in to comment.