Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Container for running SQL jobs

Russ Garrettf85cfc83b731
diff --git a/.github/workflows/sql-jobs.yml b/.github/workflows/sql-jobs.yml
new file mode 100644
index 0000000..0c243cf
--- /dev/null
+++ b/.github/workflows/sql-jobs.yml
@@ -0,0 +1,32 @@
+name: Build SQL Jobs container
+
+on:
+ push:
+ branches:
+ - main
+ paths:
+ - 'schema/jobs/**'
+ - '.github/workflows/sql-jobs.yml'
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ - name: Login to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ - name: Build and push SQL Jobs image
+ id: docker_build
+ uses: docker/build-push-action@v6
+ with:
+ context: ./schema/jobs
+ file: ./schema/jobs/Dockerfile
+ push: true
+ tags: |
+ ghcr.io/openinframap/sql-jobs:${{ github.sha }}-${{ github.run_number }}
+ ghcr.io/openinframap/sql-jobs:latest
\ No newline at end of file
diff --git a/schema/jobs/Dockerfile b/schema/jobs/Dockerfile
new file mode 100644
index 0000000..947f578
--- /dev/null
+++ b/schema/jobs/Dockerfile
@@ -0,0 +1,4 @@
+FROM alpine/psql:17.4
+
+RUN mkdir /sql
+COPY update-stats.sql /sql/update-stats.sql
\ No newline at end of file
diff --git a/schema/jobs/README.md b/schema/jobs/README.md
new file mode 100644
index 0000000..c12c34d
--- /dev/null
+++ b/schema/jobs/README.md
@@ -0,0 +1 @@
+A container to run periodic SQL jobs
\ No newline at end of file
diff --git a/schema/jobs/update-stats.sql b/schema/jobs/update-stats.sql
new file mode 100644
index 0000000..63ad4e9
--- /dev/null
+++ b/schema/jobs/update-stats.sql
@@ -0,0 +1,29 @@
+-----------------------------
+-- Queries used to update the stats schema:
+
+INSERT INTO stats.power_line (time, country, voltage, length)
+ SELECT now() AS time, country_eez_sub."union" AS country, convert_voltage(voltage)::INTEGER AS voltage,
+ sum(ST_Length(ST_Transform(geometry, 4326)::geography)) AS length
+ FROM osm_power_line, countries.country_eez_sub
+ WHERE ST_Contains(country_eez_sub.geom, geometry)
+ AND "union" != 'Antarctica'
+ AND tags->'construction:power' IS NULL
+ GROUP BY country_eez_sub."union", convert_voltage(voltage);
+
+
+INSERT INTO stats.power_plant (time, country, source, count, output)
+ SELECT now() AS time, country_eez_sub."union", source, count(*), convert_power(output)
+ FROM power_plant, countries.country_eez_sub
+ WHERE ST_Contains(country_eez_sub.geom, geometry)
+ AND "union" != 'Antarctica'
+ AND tags->'construction:power' IS NULL
+ GROUP BY country_eez_sub."union", source, convert_power(output);
+
+
+INSERT INTO stats.power_generator (time, country, source, count, output)
+ SELECT now() AS time, country_eez_sub."union", source, count(*), convert_power(output)
+ FROM osm_power_generator, countries.country_eez_sub
+ WHERE ST_Contains(country_eez_sub.geom, geometry)
+ AND "union" != 'Antarctica'
+ AND tags->'construction:power' IS NULL
+ GROUP BY country_eez_sub."union", source, convert_power(output);
diff --git a/schema/stats.sql b/schema/stats.sql
index 07d9abf..e0f6a2f 100644
--- a/schema/stats.sql
+++ b/schema/stats.sql
@@ -26,35 +26,4 @@ CREATE TABLE stats.power_generator (
source TEXT,
count INTEGER,
output BIGINT
-);
-
-
------------------------------
--- Queries used to update the stats schema:
-
-INSERT INTO stats.power_line (time, country, voltage, length)
- SELECT now() AS time, country_eez_sub."union" AS country, convert_voltage(voltage)::INTEGER AS voltage,
- sum(ST_Length(ST_Transform(geometry, 4326)::geography)) AS length
- FROM osm_power_line, countries.country_eez_sub
- WHERE ST_Contains(country_eez_sub.geom, geometry)
- AND "union" != 'Antarctica'
- AND tags->'construction:power' IS NULL
- GROUP BY country_eez_sub."union", convert_voltage(voltage);
-
-
-INSERT INTO stats.power_plant (time, country, source, count, output)
- SELECT now() AS time, country_eez_sub."union", source, count(*), convert_power(output)
- FROM power_plant, countries.country_eez_sub
- WHERE ST_Contains(country_eez_sub.geom, geometry)
- AND "union" != 'Antarctica'
- AND tags->'construction:power' IS NULL
- GROUP BY country_eez_sub."union", source, convert_power(output);
-
-
-INSERT INTO stats.power_generator (time, country, source, count, output)
- SELECT now() AS time, country_eez_sub."union", source, count(*), convert_power(output)
- FROM osm_power_generator, countries.country_eez_sub
- WHERE ST_Contains(country_eez_sub.geom, geometry)
- AND "union" != 'Antarctica'
- AND tags->'construction:power' IS NULL
- GROUP BY country_eez_sub."union", source, convert_power(output);
+);
\ No newline at end of file