Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

#129-generate postgres table structure at db intialization #130

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docker-compose.postgis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "3"
services:
db-service:
image: postgis/postgis:13-3.2
build:
context: ../postgis_init
hostname: db-service
environment:
POSTGRES_USER: ${POSTGRES_USER}
Expand All @@ -13,7 +14,7 @@ services:

db-ui:
build:
context: ./pgadmin
context: ../pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
Expand Down
3 changes: 2 additions & 1 deletion minikube/docker-compose.postgis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "3"
services:
db-service:
image: postgis/postgis:13-3.2
build:
context: ../postgis_init
hostname: db-service
environment:
POSTGRES_USER: ${POSTGRES_USER}
Expand Down
4 changes: 4 additions & 0 deletions postgis_init/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM postgis/postgis:13-3.2


COPY ./entrypoint_initdb/. /docker-entrypoint-initdb.d/
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE attributes (
attribute_id VARCHAR NOT NULL,
attribute_type VARCHAR NOT NULL,
attribute_key VARCHAR NOT NULL,
name VARCHAR NOT NULL,
geo_data JSONB NOT NULL,
detail JSONB NOT NULL,
metadata JSONB NOT NULL,

created_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),

CONSTRAINT "attributes_PK" PRIMARY KEY (attribute_id)
);

CREATE TABLE region_attributes (
id UUID NOT NULL DEFAULT uuid_generate_v4(),
attribute_id VARCHAR NOT NULL references attributes(attribute_id),
feature_id VARCHAR NOT NULL,
feature_id_lvl VARCHAR NOT NULL,
value VARCHAR NOT NULL,
value_type VARCHAR NOT NULL,
date_ISO VARCHAR NOT NULL,
date_data VARCHAR NOT NULL,
MartinJurcoGlina marked this conversation as resolved.
Show resolved Hide resolved

created_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),

CONSTRAINT "attribute_UQ" UNIQUE (attribute_id, feature_id, feature_id_lvl, date_ISO)
);

CREATE TABLE point_attributes (
id UUID NOT NULL DEFAULT uuid_generate_v4(),
attribute_id VARCHAR NOT NULL references attributes(attribute_id),
geometry GEOMETRY NOT NULL,
properties JSONB NOT NULL,

created_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),

CONSTRAINT "pointAttribbute_PK" PRIMARY KEY (id)
);
EOSQL
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE layer_geo_data (
reference_id VARCHAR NOT NULL,
name VARCHAR NOT NULL,
format VARCHAR NOT NULL,
geo_data_url VARCHAR NOT NULL,
data JSONB NOT NULL,
metadata JSONB NOT NULL,

created_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),
CONSTRAINT "layergeodata_PK" PRIMARY KEY (reference_id)
);

CREATE TABLE map_layers (
reference_id VARCHAR NOT NULL,
geo_reference_id VARCHAR NOT NULL references layer_geo_data(reference_id),
layer_type VARCHAR NOT NULL,
category VARCHAR NOT NULL,
title VARCHAR NOT NULL,
attribute_id VARCHAR NOT NULL references attributes(attribute_id),
attribute_description JSONB NOT NULL,
styles JSONB NOT NULL,
legend JSONB NOT NULL,
layer_options JSONB NOT NULL,

created_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NOW(),
CONSTRAINT "maplayers_PK" PRIMARY KEY (reference_id)
);

EOSQL