Skip to content

Commit

Permalink
Merge pull request #80 from DPIclimate/master
Browse files Browse the repository at this point in the history
V2 DB
  • Loading branch information
dajtxx authored Jun 12, 2024
2 parents fce4894 + 51d47ef commit 6cb9993
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 219 deletions.
2 changes: 1 addition & 1 deletion compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.1'

services:
db:
image: postgres:14.2
image: postgis/postgis:14-3.4
logging:
driver: local
options:
Expand Down
14 changes: 6 additions & 8 deletions db/init.d/init_db.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
CREATE EXTENSION postgis;
CREATE EXTENSION pgcrypto;

create table if not exists sources (
source_name text primary key not null
);
Expand All @@ -6,7 +9,7 @@ create table if not exists physical_devices (
uid integer generated always as identity primary key,
source_name text not null references sources,
name text not null,
location point,
location geometry('POINT', 4283),
last_seen timestamptz,
-- Store only top level key value pairs here; it is used
-- for quickly finding a device using information carried
Expand Down Expand Up @@ -72,7 +75,7 @@ create table if not exists device_blobs (
create table if not exists logical_devices (
uid integer generated always as identity primary key,
name text not null,
location point,
location geometry('POINT', 4283),
last_seen timestamptz,
properties jsonb not null default '{}'
);
Expand Down Expand Up @@ -107,9 +110,4 @@ create table if not exists version (
create index if not exists pd_src_id_idx on physical_devices using GIN (source_ids);

insert into sources values ('ttn'), ('greenbrain'), ('wombat'), ('ydoc'), ('ict_eagleio');
insert into version values (1);

-- Enable the PostGIS extensions
-- CREATE EXTENSION postgis;
-- CREATE EXTENSION postgis_raster;
-- CREATE EXTENSION postgis_sfcgal;
insert into version values (2);
17 changes: 17 additions & 0 deletions db/upgrade/002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE EXTENSION postgis;
CREATE EXTENSION pgcrypto;

SELECT AddGeometryColumn('logical_devices','geom',4283,'POINT',2);
SELECT AddGeometryColumn('physical_devices','geom',4283,'POINT',2);

UPDATE logical_devices SET geom = ST_MakePoint(location[1], location[0]) WHERE location IS NOT NULL;
UPDATE physical_devices SET geom = ST_MakePoint(location[1], location[0]) WHERE location IS NOT NULL;

ALTER TABLE logical_devices DROP COLUMN location;
ALTER TABLE physical_devices DROP COLUMN location;

ALTER TABLE logical_devices RENAME COLUMN geom TO location;
ALTER TABLE physical_devices RENAME COLUMN geom TO location;

TRUNCATE version;
insert into version values (2);
Loading

0 comments on commit 6cb9993

Please sign in to comment.