Skip to content

Commit

Permalink
JSON based generated database fields instead of imports (#1155)
Browse files Browse the repository at this point in the history
migrated to using JSONB columns to store data instead of string columns
  • Loading branch information
CommanderStorm authored May 7, 2024
1 parent 1941e5f commit 93e6a80
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 199 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Add down migration script here
-- was never used
create table rooms
(
key text primary key not null,
tumonline_org_id integer not null,
tumonline_calendar_id integer not null,
tumonline_room_id integer not null,
last_scrape timestamp without time zone not null
);

-- migrating to
DROP TABLE en;
create table en
(
key text not null
primary key
references de,
name text not null,
tumonline_room_nr integer,
type text not null,
type_common_name text not null,
lat double precision not null,
lon double precision not null,
data text not null,
last_calendar_scrape_at timestamp with time zone
);
comment on column en.last_calendar_scrape_at is 'the last time the calendar was scraped for this room';

DROP TABLE de;
create table de
(
key text not null primary key,
name text not null,
tumonline_room_nr integer,
type text not null,
type_common_name text not null,
lat double precision not null,
lon double precision not null,
data text not null,
last_calendar_scrape_at timestamp with time zone
);
comment on column de.last_calendar_scrape_at is 'the last time the calendar was scraped for this room';
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Add up migration script here
-- was never used
DROP TABLE rooms;

-- migrating to using the json type instead of having elaborate insertion logic
alter table de alter column data type jsonb using data::jsonb;
alter table de drop column lat;
alter table de add column lat FLOAT NOT NULL GENERATED ALWAYS AS (CAST (data->'coords'->>'lat' AS FLOAT)) STORED;
alter table de drop column lon;
alter table de add column lon FLOAT NOT NULL GENERATED ALWAYS AS (CAST (data->'coords'->>'lon' AS FLOAT)) STORED;
alter table de drop column name;
alter table de add column name TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'name' AS TEXT)) STORED;
alter table de drop column type_common_name;
alter table de add column type_common_name TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type_common_name' AS TEXT)) STORED;
alter table de drop column type;
alter table de add column type TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type' AS TEXT)) STORED;
alter table de add column calendar_url TEXT GENERATED ALWAYS AS (CAST (data->'props'->>'calendar_url' AS TEXT)) STORED;
alter table de drop column tumonline_room_nr;
alter table de add column tumonline_room_nr INTEGER GENERATED ALWAYS AS (CAST (data->'props'->>'tumonline_room_nr' AS INTEGER)) STORED;

alter table en alter column data type jsonb using data::jsonb;
alter table en drop column lat;
alter table en add column lat FLOAT NOT NULL GENERATED ALWAYS AS (CAST (data->'coords'->>'lat' AS FLOAT)) STORED;
alter table en drop column lon;
alter table en add column lon FLOAT NOT NULL GENERATED ALWAYS AS (CAST (data->'coords'->>'lon' AS FLOAT)) STORED;
alter table en drop column name;
alter table en add column name TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'name' AS TEXT)) STORED;
alter table en drop column type_common_name;
alter table en add column type_common_name TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type_common_name' AS TEXT)) STORED;
alter table en drop column type;
alter table en add column type TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type' AS TEXT)) STORED;
alter table en add column calendar_url TEXT GENERATED ALWAYS AS (CAST (data->'props'->>'calendar_url' AS TEXT)) STORED;
alter table en drop column tumonline_room_nr;
alter table en add column tumonline_room_nr INTEGER GENERATED ALWAYS AS (CAST (data->'props'->>'tumonline_room_nr' AS INTEGER)) STORED;
Loading

0 comments on commit 93e6a80

Please sign in to comment.