boundary
boundary copied to clipboard
refact(session connection): remove session connection state table
WIP
This PR removes the session_connection_state table, replacing it with the new field connected_time_range on session_connection
Database schema diff between main and irindos-session-connection-states @ 25816ce909da21252adeed40d3b4f92131afbac5
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/check_connection_state_transition.sql b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/check_connection_state_transition.sql
new file mode 100644
index 000000000..62b36e6b8
--- /dev/null
+++ b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/check_connection_state_transition.sql
@@ -0,0 +1,51 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- authorized state
+ if new.connected_time_range is null then
+ return new;
+ end if;
+ -- if the old state was authorized, any transition is valid
+ if old.connected_time_range is null then
+ return new;
+ end if;
+ -- prevent transitions from connected to connected
+ if upper(old.connected_time_range) = 'infinity' and upper(new.connected_time_range) = 'infinity' then
+ raise exception 'invalid state transition from connected to connected';
+ end if;
+ -- prevent transitions from closed to connected
+ if lower(new.connected_time_range) >= upper(old.connected_time_range) then
+ raise exception 'invalid state transition from closed to connected';
+ end if;
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/insert_new_connection_state.sql b/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/insert_new_connection_state.sql
deleted file mode 100644
index 085e9652a..000000000
--- a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/insert_new_connection_state.sql
+++ /dev/null
@@ -1,38 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_new_connection_state() returns trigger
- language plpgsql
- as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
- return new;
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/insert_session_connection_state.sql b/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/update_connected_time_range_on_closed_reason.sql b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/update_connected_time_range_on_closed_reason.sql
new file mode 100644
index 000000000..f6d6e3a5c
--- /dev/null
+++ b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/update_connected_time_range_on_closed_reason.sql
@@ -0,0 +1,44 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
+--
+
+create function public.update_connected_time_range_on_closed_reason() returns trigger
+ language plpgsql
+ as $$
+ begin
+ if new.closed_reason is not null then
+ update session_connection
+ set connected_time_range = tstzrange(lower(connected_time_range), now())
+ where public_id = new.public_id
+ -- connection is either authorized or connected
+ and (connected_time_range is null
+ or connected_time_range = tstzrange(lower(connected_time_range), 'infinity'::timestamptz)
+ );
+ end if;
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/update_session_state_on_termination_reason.sql
index 856ccd00a..1bb4a2465 100644
--- a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/update_session_state_on_termination_reason.sql
@@ -25,42 +25,27 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
perform from
session_state ss
where
- ss.session_id = new.public_id and
+ ss.session_id = new.public_id and
ss.state = 'terminated';
- if found then
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/wh_insert_session_connection.sql b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/wh_insert_session_connection_state.sql b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/wh_insert_session_connection_state.sql
index 35fdd0b3b..7c583260c 100644
--- a/.schema-diff/funcs_d788c9fd9d5968e7d83449e708d6394cdffc6867/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/wh_insert_session_connection_state.sql
@@ -23,37 +23,46 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/public session_connection_state.sql b/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/public session_connection_state_enm.sql b/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection.sql b/.schema-diff/tables_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection.sql
+++ b/.schema-diff/tables_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state.sql b/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm.sql b/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
Unchanged
Triggers
diff --git a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..44d1ed1f4 100644
--- a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_7ef4c93c41603741a6e1b27cc116d5acf7a29a93/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state immutable_columns.sql b/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_pkey.sql b/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_d788c9fd9d5968e7d83449e708d6394cdffc6867/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ eed3c42f623fde71d6b7c54ba2c5b64e7b4c6f82
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/check_connection_state_transition.sql b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/check_connection_state_transition.sql
new file mode 100644
index 000000000..63518b6b6
--- /dev/null
+++ b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/check_connection_state_transition.sql
@@ -0,0 +1,51 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- prevent invalid bounds (-infinity)
+ if lower(new.connected_time_range) = '-infinity' or upper(new.connected_time_range) ='-infinity' then
+ raise exception 'invalid connected_time_range bounds: cannot be -infinity';
+ end if;
+ -- if the old state was authorized, any transition is valid
+ if old.connected_time_range is null then
+ return new;
+ end if;
+ -- prevent transitions from connected to connected
+ if upper(old.connected_time_range) = 'infinity' and upper(new.connected_time_range) = 'infinity' then
+ raise exception 'invalid state transition from connected to connected';
+ end if;
+ -- prevent transitions from closed to connected
+ if lower(new.connected_time_range) >= upper(old.connected_time_range) then
+ raise exception 'invalid state transition from closed to connected';
+ end if;
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/insert_session_connection_state.sql b/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/insert_new_connection_state.sql b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/update_connected_time_range_on_closed_reason.sql
similarity index 52%
rename from .schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/insert_new_connection_state.sql
rename to .schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/update_connected_time_range_on_closed_reason.sql
index 085e9652a..a4486a326 100644
--- a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or old.connected_time_range = tstzrange(lower(old.connected_time_range), 'infinity'::timestamptz) then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/update_session_state_on_termination_reason.sql
index 856ccd00a..c585b434d 100644
--- a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/wh_insert_session_connection.sql b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/wh_insert_session_connection_state.sql b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/wh_insert_session_connection_state.sql
index 35fdd0b3b..7c583260c 100644
--- a/.schema-diff/funcs_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_ce164163c8428d3cf5545c06190d1d3d58641ab8/wh_insert_session_connection_state.sql
@@ -23,37 +23,46 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/public session_connection_state.sql b/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/public session_connection_state_enm.sql b/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection.sql b/.schema-diff/tables_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection.sql
+++ b/.schema-diff/tables_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state.sql b/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm.sql b/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
Unchanged
Triggers
diff --git a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_ce164163c8428d3cf5545c06190d1d3d58641ab8/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state immutable_columns.sql b/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_pkey.sql b/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_e2872275dc2ca727a4d9b57c5d1554b1d690ce7d/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 987245b0f7446bcfc08ecbc1cf7a6a09b3b339ca
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/check_connection_state_transition.sql b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/check_connection_state_transition.sql
new file mode 100644
index 000000000..67963a891
--- /dev/null
+++ b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/check_connection_state_transition.sql
@@ -0,0 +1,52 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and upper(new.connected_time_range) != 'infinity' then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_session_connection_state.sql b/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_new_connection_state.sql b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/update_connected_time_range_on_closed_reason.sql
similarity index 52%
rename from .schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_new_connection_state.sql
rename to .schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/update_connected_time_range_on_closed_reason.sql
index 085e9652a..a4486a326 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or old.connected_time_range = tstzrange(lower(old.connected_time_range), 'infinity'::timestamptz) then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/update_session_state_on_termination_reason.sql
index 856ccd00a..c585b434d 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection.sql b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection_state.sql b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/wh_insert_session_connection_state.sql
index 35fdd0b3b..7c583260c 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_62c6858bf42e1088c9a666f7882f3c7d497abe9b/wh_insert_session_connection_state.sql
@@ -23,37 +23,46 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state_enm.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection.sql b/.schema-diff/tables_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection.sql
+++ b/.schema-diff/tables_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
Unchanged
Triggers
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_62c6858bf42e1088c9a666f7882f3c7d497abe9b/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state immutable_columns.sql b/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_pkey.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ aa064860ca35c4c992d5bd42c9ca3dd64b4b9ca1
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/check_connection_state_transition.sql b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/check_connection_state_transition.sql
new file mode 100644
index 000000000..67963a891
--- /dev/null
+++ b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/check_connection_state_transition.sql
@@ -0,0 +1,52 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and upper(new.connected_time_range) != 'infinity' then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_session_connection_state.sql b/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_new_connection_state.sql b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/update_connected_time_range_on_closed_reason.sql
similarity index 52%
rename from .schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_new_connection_state.sql
rename to .schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/update_connected_time_range_on_closed_reason.sql
index 085e9652a..a4486a326 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or old.connected_time_range = tstzrange(lower(old.connected_time_range), 'infinity'::timestamptz) then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/update_session_state_on_termination_reason.sql
index 856ccd00a..c585b434d 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection.sql b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection_state.sql b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/wh_insert_session_connection_state.sql
index 35fdd0b3b..7c583260c 100644
--- a/.schema-diff/funcs_92b2d4490e19d9989349295adf13b5b730613a20/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_5a845241c6c4d0f7c45453447129cf055f77d014/wh_insert_session_connection_state.sql
@@ -23,37 +23,46 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (
+ select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ -- returning *;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state_enm.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection.sql b/.schema-diff/tables_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection.sql
+++ b/.schema-diff/tables_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm.sql b/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
Unchanged
Triggers
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_5a845241c6c4d0f7c45453447129cf055f77d014/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state immutable_columns.sql b/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_pkey.sql b/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_92b2d4490e19d9989349295adf13b5b730613a20/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 0dbddf04f1691e44141cd078a538bb2d3d819b2a
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/check_connection_state_transition.sql b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_session_connection_state.sql b/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_new_connection_state.sql b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_new_connection_state.sql
rename to .schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection.sql b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection_state.sql b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_5cc4823685410a96ebdd262c14db7ecac9d92b92/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state_enm.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection.sql b/.schema-diff/tables_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection.sql
+++ b/.schema-diff/tables_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
Unchanged
Triggers
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_5cc4823685410a96ebdd262c14db7ecac9d92b92/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state immutable_columns.sql b/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_pkey.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 2b39d1bbc6895b61d3b6faf93763f8d553211cd9
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/check_connection_state_transition.sql b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_session_connection_state.sql b/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_new_connection_state.sql b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_new_connection_state.sql
rename to .schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection.sql b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection_state.sql b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_80abefda1bfe1811f6bad1a8c749b0f500e1603e/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_78845c273742ef18e65cc31d7f2a639222a28ae3/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state_enm.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection.sql b/.schema-diff/tables_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection.sql
+++ b/.schema-diff/tables_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm.sql b/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
Unchanged
Triggers
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_78845c273742ef18e65cc31d7f2a639222a28ae3/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state immutable_columns.sql b/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_pkey.sql b/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_80abefda1bfe1811f6bad1a8c749b0f500e1603e/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 04a4b4ad59a50de9374ce9dd05222f80c60f78a8
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/check_connection_state_transition.sql b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/insert_session_connection_state.sql b/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/insert_new_connection_state.sql b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/insert_new_connection_state.sql
rename to .schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/wh_insert_session_connection.sql b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/wh_insert_session_connection_state.sql b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_603719aa9b748b102bc29bd9f4151c272cc3acf9/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_a02f6553e2d6eaf296544005f7afc457e4ab98cd/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/public session_connection_state.sql b/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/public session_connection_state_enm.sql b/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection.sql b/.schema-diff/tables_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection.sql
+++ b/.schema-diff/tables_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state.sql b/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm.sql b/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
diff --git a/.schema-diff/views_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection_with_status_view.sql b/.schema-diff/views_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection_with_status_view.sql
new file mode 100644
index 000000000..719c23a45
--- /dev/null
+++ b/.schema-diff/views_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection_with_status_view.sql
@@ -0,0 +1,49 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: session_connection_with_status_view; type: view; schema: public; owner: -
+--
+
+create view public.session_connection_with_status_view as
+ select session_connection.public_id,
+ session_connection.session_id,
+ session_connection.client_tcp_address,
+ session_connection.client_tcp_port,
+ session_connection.endpoint_tcp_address,
+ session_connection.endpoint_tcp_port,
+ session_connection.bytes_up,
+ session_connection.bytes_down,
+ session_connection.closed_reason,
+ session_connection.version,
+ session_connection.create_time,
+ session_connection.update_time,
+ session_connection.user_client_ip,
+ session_connection.worker_id,
+ case
+ when (session_connection.connected_time_range is null) then 'authorized'::text
+ when (upper(session_connection.connected_time_range) > now()) then 'connected'::text
+ else 'closed'::text
+ end as status
+ from public.session_connection;
+
+
+--
+-- postgresql database dump complete
+--
+
Triggers
diff --git a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_a02f6553e2d6eaf296544005f7afc457e4ab98cd/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state immutable_columns.sql b/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_pkey.sql b/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_603719aa9b748b102bc29bd9f4151c272cc3acf9/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 7495a9b93cad20b58d0d1ad3f2b59e19375f6f63
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/check_connection_state_transition.sql b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_session_connection_state.sql b/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_new_connection_state.sql b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_new_connection_state.sql
rename to .schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection.sql b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection_state.sql b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state_enm.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection.sql b/.schema-diff/tables_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection.sql
+++ b/.schema-diff/tables_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
diff --git a/.schema-diff/views_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection_with_status_view.sql b/.schema-diff/views_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection_with_status_view.sql
new file mode 100644
index 000000000..719c23a45
--- /dev/null
+++ b/.schema-diff/views_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection_with_status_view.sql
@@ -0,0 +1,49 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: session_connection_with_status_view; type: view; schema: public; owner: -
+--
+
+create view public.session_connection_with_status_view as
+ select session_connection.public_id,
+ session_connection.session_id,
+ session_connection.client_tcp_address,
+ session_connection.client_tcp_port,
+ session_connection.endpoint_tcp_address,
+ session_connection.endpoint_tcp_port,
+ session_connection.bytes_up,
+ session_connection.bytes_down,
+ session_connection.closed_reason,
+ session_connection.version,
+ session_connection.create_time,
+ session_connection.update_time,
+ session_connection.user_client_ip,
+ session_connection.worker_id,
+ case
+ when (session_connection.connected_time_range is null) then 'authorized'::text
+ when (upper(session_connection.connected_time_range) > now()) then 'connected'::text
+ else 'closed'::text
+ end as status
+ from public.session_connection;
+
+
+--
+-- postgresql database dump complete
+--
+
Triggers
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_9c24e4bbe7ab096ad00068257fc9e8b3512adefb/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state immutable_columns.sql b/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_pkey.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 53fc8ade66f92186a891a311e5fad57a8b0c9fa0
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/check_connection_state_transition.sql b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_session_connection_state.sql b/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_new_connection_state.sql b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_new_connection_state.sql
rename to .schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection.sql b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection_state.sql b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_c25f9804656524ae5f7a06cbc612199da74f7256/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state_enm.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection.sql b/.schema-diff/tables_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection.sql
+++ b/.schema-diff/tables_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm.sql b/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
diff --git a/.schema-diff/views_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection_with_status_view.sql b/.schema-diff/views_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection_with_status_view.sql
new file mode 100644
index 000000000..719c23a45
--- /dev/null
+++ b/.schema-diff/views_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection_with_status_view.sql
@@ -0,0 +1,49 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: session_connection_with_status_view; type: view; schema: public; owner: -
+--
+
+create view public.session_connection_with_status_view as
+ select session_connection.public_id,
+ session_connection.session_id,
+ session_connection.client_tcp_address,
+ session_connection.client_tcp_port,
+ session_connection.endpoint_tcp_address,
+ session_connection.endpoint_tcp_port,
+ session_connection.bytes_up,
+ session_connection.bytes_down,
+ session_connection.closed_reason,
+ session_connection.version,
+ session_connection.create_time,
+ session_connection.update_time,
+ session_connection.user_client_ip,
+ session_connection.worker_id,
+ case
+ when (session_connection.connected_time_range is null) then 'authorized'::text
+ when (upper(session_connection.connected_time_range) > now()) then 'connected'::text
+ else 'closed'::text
+ end as status
+ from public.session_connection;
+
+
+--
+-- postgresql database dump complete
+--
+
Triggers
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_c25f9804656524ae5f7a06cbc612199da74f7256/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state immutable_columns.sql b/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
Unchanged
Constraints
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_pkey.sql b/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_f7bbe08c0ca85175b4dc30ae465d8d3b88c17e22/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 4f6e44c6812bfa96a37ca13ae861a28966ca556f
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/check_connection_state_transition.sql b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_session_connection_state.sql b/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_new_connection_state.sql b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_new_connection_state.sql
rename to .schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection.sql b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection_state.sql b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_13add5e7f0a368dadf0540b7fce8b8049330434e/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state_enm.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection.sql b/.schema-diff/tables_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection.sql
+++ b/.schema-diff/tables_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
diff --git a/.schema-diff/views_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection_with_status_view.sql b/.schema-diff/views_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection_with_status_view.sql
new file mode 100644
index 000000000..719c23a45
--- /dev/null
+++ b/.schema-diff/views_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection_with_status_view.sql
@@ -0,0 +1,49 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: session_connection_with_status_view; type: view; schema: public; owner: -
+--
+
+create view public.session_connection_with_status_view as
+ select session_connection.public_id,
+ session_connection.session_id,
+ session_connection.client_tcp_address,
+ session_connection.client_tcp_port,
+ session_connection.endpoint_tcp_address,
+ session_connection.endpoint_tcp_port,
+ session_connection.bytes_up,
+ session_connection.bytes_down,
+ session_connection.closed_reason,
+ session_connection.version,
+ session_connection.create_time,
+ session_connection.update_time,
+ session_connection.user_client_ip,
+ session_connection.worker_id,
+ case
+ when (session_connection.connected_time_range is null) then 'authorized'::text
+ when (upper(session_connection.connected_time_range) > now()) then 'connected'::text
+ else 'closed'::text
+ end as status
+ from public.session_connection;
+
+
+--
+-- postgresql database dump complete
+--
+
Triggers
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_13add5e7f0a368dadf0540b7fce8b8049330434e/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state immutable_columns.sql b/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
diff --git a/.schema-diff/indexes_13add5e7f0a368dadf0540b7fce8b8049330434e/connected_time_range_idx.sql b/.schema-diff/indexes_13add5e7f0a368dadf0540b7fce8b8049330434e/connected_time_range_idx.sql
new file mode 100644
index 000000000..66f077ff7
--- /dev/null
+++ b/.schema-diff/indexes_13add5e7f0a368dadf0540b7fce8b8049330434e/connected_time_range_idx.sql
@@ -0,0 +1,31 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+set default_tablespace = '';
+
+--
+-- name: connected_time_range_idx; type: index; schema: public; owner: -
+--
+
+create index connected_time_range_idx on public.session_connection using btree (connected_time_range);
+
+
+--
+-- postgresql database dump complete
+--
+
Constraints
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_pkey.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 1f819d430618f7f3bb8458d1f2e1e53e306ef7d8
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/check_connection_state_transition.sql b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_session_connection_state.sql b/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_new_connection_state.sql b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_new_connection_state.sql
rename to .schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection.sql b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection_state.sql b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_1be0e5d41370d84d8b0d38602bba73063213b9d4/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_fde2273541890cc80583dd9429e0fa1d52cd79aa/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state_enm.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection.sql b/.schema-diff/tables_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection.sql
+++ b/.schema-diff/tables_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm.sql b/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
diff --git a/.schema-diff/views_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection_with_status_view.sql b/.schema-diff/views_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection_with_status_view.sql
new file mode 100644
index 000000000..719c23a45
--- /dev/null
+++ b/.schema-diff/views_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection_with_status_view.sql
@@ -0,0 +1,49 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: session_connection_with_status_view; type: view; schema: public; owner: -
+--
+
+create view public.session_connection_with_status_view as
+ select session_connection.public_id,
+ session_connection.session_id,
+ session_connection.client_tcp_address,
+ session_connection.client_tcp_port,
+ session_connection.endpoint_tcp_address,
+ session_connection.endpoint_tcp_port,
+ session_connection.bytes_up,
+ session_connection.bytes_down,
+ session_connection.closed_reason,
+ session_connection.version,
+ session_connection.create_time,
+ session_connection.update_time,
+ session_connection.user_client_ip,
+ session_connection.worker_id,
+ case
+ when (session_connection.connected_time_range is null) then 'authorized'::text
+ when (upper(session_connection.connected_time_range) > now()) then 'connected'::text
+ else 'closed'::text
+ end as status
+ from public.session_connection;
+
+
+--
+-- postgresql database dump complete
+--
+
Triggers
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_fde2273541890cc80583dd9429e0fa1d52cd79aa/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state immutable_columns.sql b/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
diff --git a/.schema-diff/indexes_fde2273541890cc80583dd9429e0fa1d52cd79aa/connected_time_range_idx.sql b/.schema-diff/indexes_fde2273541890cc80583dd9429e0fa1d52cd79aa/connected_time_range_idx.sql
new file mode 100644
index 000000000..66f077ff7
--- /dev/null
+++ b/.schema-diff/indexes_fde2273541890cc80583dd9429e0fa1d52cd79aa/connected_time_range_idx.sql
@@ -0,0 +1,31 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+set default_tablespace = '';
+
+--
+-- name: connected_time_range_idx; type: index; schema: public; owner: -
+--
+
+create index connected_time_range_idx on public.session_connection using btree (connected_time_range);
+
+
+--
+-- postgresql database dump complete
+--
+
Constraints
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_pkey.sql b/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_1be0e5d41370d84d8b0d38602bba73063213b9d4/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 6a95a45a046be2b06731280bb4febb067e380a24
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/check_connection_state_transition.sql b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_session_connection_state.sql b/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_new_connection_state.sql b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_new_connection_state.sql
rename to .schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection.sql b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection_state.sql b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_89a2f72929edc4fe8aa8f2ba572326227f9345ad/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state_enm.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection.sql b/.schema-diff/tables_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection.sql
+++ b/.schema-diff/tables_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
diff --git a/.schema-diff/views_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection_with_status_view.sql b/.schema-diff/views_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection_with_status_view.sql
new file mode 100644
index 000000000..719c23a45
--- /dev/null
+++ b/.schema-diff/views_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection_with_status_view.sql
@@ -0,0 +1,49 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: session_connection_with_status_view; type: view; schema: public; owner: -
+--
+
+create view public.session_connection_with_status_view as
+ select session_connection.public_id,
+ session_connection.session_id,
+ session_connection.client_tcp_address,
+ session_connection.client_tcp_port,
+ session_connection.endpoint_tcp_address,
+ session_connection.endpoint_tcp_port,
+ session_connection.bytes_up,
+ session_connection.bytes_down,
+ session_connection.closed_reason,
+ session_connection.version,
+ session_connection.create_time,
+ session_connection.update_time,
+ session_connection.user_client_ip,
+ session_connection.worker_id,
+ case
+ when (session_connection.connected_time_range is null) then 'authorized'::text
+ when (upper(session_connection.connected_time_range) > now()) then 'connected'::text
+ else 'closed'::text
+ end as status
+ from public.session_connection;
+
+
+--
+-- postgresql database dump complete
+--
+
Triggers
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_89a2f72929edc4fe8aa8f2ba572326227f9345ad/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state immutable_columns.sql b/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
diff --git a/.schema-diff/indexes_89a2f72929edc4fe8aa8f2ba572326227f9345ad/connected_time_range_idx.sql b/.schema-diff/indexes_89a2f72929edc4fe8aa8f2ba572326227f9345ad/connected_time_range_idx.sql
new file mode 100644
index 000000000..7d4a537e2
--- /dev/null
+++ b/.schema-diff/indexes_89a2f72929edc4fe8aa8f2ba572326227f9345ad/connected_time_range_idx.sql
@@ -0,0 +1,31 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+set default_tablespace = '';
+
+--
+-- name: connected_time_range_idx; type: index; schema: public; owner: -
+--
+
+create index connected_time_range_idx on public.session_connection using gist (connected_time_range);
+
+
+--
+-- postgresql database dump complete
+--
+
Constraints
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_pkey.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;
Database schema diff between main and irindos-session-connection-states @ 9aca523a341a8f17105c52c5c7236dddb1d562e3
To understand how these diffs are generated and some limitations see the documentation of the script.
Functions
diff --git a/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/check_connection_state_transition.sql b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/check_connection_state_transition.sql
new file mode 100644
index 000000000..2e277cab1
--- /dev/null
+++ b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/check_connection_state_transition.sql
@@ -0,0 +1,54 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: check_connection_state_transition(); type: function; schema: public; owner: -
+--
+
+create function public.check_connection_state_transition() returns trigger
+ language plpgsql
+ as $$
+ begin
+ -- if old state was authorized, allow transition to connected or closed
+ if old.connected_time_range is null then
+ return new;
+ end if;
+
+ -- if old state was closed, no transitions are allowed
+ if upper(old.connected_time_range) < 'infinity' and old.connected_time_range != new.connected_time_range then
+ raise exception 'invalid state transition from closed';
+ end if;
+
+ -- if old state was connected, allow transition to closed
+ if upper(old.connected_time_range) = 'infinity' and
+ upper(new.connected_time_range) != 'infinity' and
+ lower(old.connected_time_range) = lower(new.connected_time_range) then
+ return new;
+ else
+ raise exception 'invalid state transition from connected';
+ end if;
+
+ return new;
+ end;
+ $$;
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_session_connection_state.sql b/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_session_connection_state.sql
deleted file mode 100644
index e163e94a9..000000000
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_session_connection_state.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: insert_session_connection_state(); type: function; schema: public; owner: -
---
-
-create function public.insert_session_connection_state() returns trigger
- language plpgsql
- as $$
- begin
-
- update session_connection_state
- set end_time = now()
- where connection_id = new.connection_id
- and end_time is null;
-
- if not found then
- new.previous_end_time = null;
- new.start_time = now();
- new.end_time = null;
- return new;
- end if;
-
- new.previous_end_time = now();
- new.start_time = now();
- new.end_time = null;
- return new;
-
- end;
- $$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_new_connection_state.sql b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/update_connected_time_range_on_closed_reason.sql
similarity index 54%
rename from .schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_new_connection_state.sql
rename to .schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/update_connected_time_range_on_closed_reason.sql
index 085e9652a..4ac9443ac 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/insert_new_connection_state.sql
+++ b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/update_connected_time_range_on_closed_reason.sql
@@ -17,18 +17,20 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: insert_new_connection_state(); type: function; schema: public; owner: -
+-- name: update_connected_time_range_on_closed_reason(); type: function; schema: public; owner: -
--
-create function public.insert_new_connection_state() returns trigger
+create function public.update_connected_time_range_on_closed_reason() returns trigger
language plpgsql
as $$
- begin
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'authorized');
+ begin
+ if new.closed_reason is not null then
+ if old.connected_time_range is null or upper(old.connected_time_range) = 'infinity'::timestamptz then
+ new.connected_time_range = tstzrange(lower(old.connected_time_range), now(), '[]');
+ end if;
+ end if;
return new;
- end;
+ end;
$$;
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_connection_state_on_closed_reason.sql b/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_connection_state_on_closed_reason.sql
deleted file mode 100644
index f4ed4be97..000000000
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_connection_state_on_closed_reason.sql
+++ /dev/null
@@ -1,48 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: update_connection_state_on_closed_reason(); type: function; schema: public; owner: -
---
-
-create function public.update_connection_state_on_closed_reason() returns trigger
- language plpgsql
- as $$
- begin
- if new.closed_reason is not null then
- -- check to see if there's a closed state already, before inserting a new one.
- perform from
- session_connection_state cs
- where
- cs.connection_id = new.public_id and
- cs.state = 'closed';
- if not found then
- insert into session_connection_state (connection_id, state)
- values
- (new.public_id, 'closed');
- end if;
- end if;
- return new;
- end;
-$$;
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_session_state_on_termination_reason.sql b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/update_session_state_on_termination_reason.sql
index 856ccd00a..1026c0011 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/update_session_state_on_termination_reason.sql
+++ b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/update_session_state_on_termination_reason.sql
@@ -25,42 +25,26 @@ create function public.update_session_state_on_termination_reason() returns trig
as $$
begin
if new.termination_reason is not null then
- perform from
- session
- where
- public_id = new.public_id and
- public_id not in (
- select session_id
- from session_connection
- where
- public_id in (
- select connection_id
- from session_connection_state
- where
- state != 'closed' and
- end_time is null
- )
- );
- if not found then
- raise 'session %s has open connections', new.public_id;
- end if;
-
+ perform
+ from session_connection
+ where session_id = new.public_id
+ and upper(connected_time_range) = 'infinity'::timestamptz;
+ if found then
+ raise 'session %s has open connections', new.public_id;
+ end if;
-- check to see if there's a terminated state already, before inserting a
-- new one.
- perform from
- session_state ss
- where
- ss.session_id = new.public_id and
- ss.state = 'terminated';
- if found then
+ perform
+ from session_state ss
+ where ss.session_id = new.public_id and
+ ss.state = 'terminated';
+ if found then
return new;
end if;
-
- insert into session_state (session_id, state)
- values
- (new.public_id, 'terminated');
- end if;
- return new;
+ insert into session_state (session_id, state)
+ values (new.public_id, 'terminated');
+ end if;
+ return new;
end;
$$;
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection.sql b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/wh_insert_session_connection.sql
index 99baf668b..eca77642e 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection.sql
+++ b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/wh_insert_session_connection.sql
@@ -23,57 +23,57 @@ set row_security = off;
create function public.wh_insert_session_connection() returns trigger
language plpgsql
as $$
-declare
+ declare
new_row wh_session_connection_accumulating_fact%rowtype;
-begin
-with
- authorized_timestamp (date_dim_key, time_dim_key, ts) as (
- select wh_date_key(start_time), wh_time_key(start_time), start_time
- from session_connection_state
- where connection_id = new.public_id
- and state = 'authorized'
- ),
- session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
+ begin
+ with
+ authorized_timestamp (date_dim_key, time_dim_key, ts) as (
+ select wh_date_key(create_time), wh_time_key(create_time), create_time
+ from session_connection
+ where public_id = new.public_id
+ and connected_time_range is null
+ ),
+ session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as (
select host_key, user_key, credential_group_key
- from wh_session_accumulating_fact
- where session_id = new.session_id
+ from wh_session_accumulating_fact
+ where session_id = new.session_id
+ )
+ insert into wh_session_connection_accumulating_fact (
+ connection_id,
+ session_id,
+ host_key,
+ user_key,
+ credential_group_key,
+ connection_authorized_date_key,
+ connection_authorized_time_key,
+ connection_authorized_time,
+ client_tcp_address,
+ client_tcp_port_number,
+ endpoint_tcp_address,
+ endpoint_tcp_port_number,
+ bytes_up,
+ bytes_down
)
-insert into wh_session_connection_accumulating_fact (
- connection_id,
- session_id,
- host_key,
- user_key,
- credential_group_key,
- connection_authorized_date_key,
- connection_authorized_time_key,
- connection_authorized_time,
- client_tcp_address,
- client_tcp_port_number,
- endpoint_tcp_address,
- endpoint_tcp_port_number,
- bytes_up,
- bytes_down
- )
-select new.public_id,
- new.session_id,
- session_dimension.host_dim_key,
- session_dimension.user_dim_key,
- session_dimension.credential_group_dim_key,
- authorized_timestamp.date_dim_key,
- authorized_timestamp.time_dim_key,
- authorized_timestamp.ts,
- new.client_tcp_address,
- new.client_tcp_port,
- new.endpoint_tcp_address,
- new.endpoint_tcp_port,
- new.bytes_up,
- new.bytes_down
-from authorized_timestamp,
- session_dimension
- returning * into strict new_row;
-return null;
-end;
-$$;
+ select new.public_id,
+ new.session_id,
+ session_dimension.host_dim_key,
+ session_dimension.user_dim_key,
+ session_dimension.credential_group_dim_key,
+ authorized_timestamp.date_dim_key,
+ authorized_timestamp.time_dim_key,
+ authorized_timestamp.ts,
+ new.client_tcp_address,
+ new.client_tcp_port,
+ new.endpoint_tcp_address,
+ new.endpoint_tcp_port,
+ new.bytes_up,
+ new.bytes_down
+ from authorized_timestamp,
+ session_dimension
+ returning * into strict new_row;
+ return null;
+ end;
+ $$;
--
diff --git a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection_state.sql b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/wh_insert_session_connection_state.sql
index 35fdd0b3b..98aa54722 100644
--- a/.schema-diff/funcs_85f98a4a678cb56286a5862c2fb76d34abbb12cc/wh_insert_session_connection_state.sql
+++ b/.schema-diff/funcs_477519b0ecd46d23d27aa6774519e4be4ca548ae/wh_insert_session_connection_state.sql
@@ -23,37 +23,42 @@ set row_security = off;
create function public.wh_insert_session_connection_state() returns trigger
language plpgsql
as $$
- declare
- date_col text;
- time_col text;
- ts_col text;
- q text;
- connection_row wh_session_connection_accumulating_fact%rowtype;
- begin
- if new.state = 'authorized' then
- -- the authorized state is the first state which is handled by the
- -- wh_insert_session_connection trigger. the update statement in this
- -- trigger will fail for the authorized state because the row for the
- -- session connection has not yet been inserted into the
- -- wh_session_connection_accumulating_fact table.
+ declare
+ state text;
+ date_col text;
+ time_col text;
+ ts_col text;
+ q text;
+ connection_row wh_session_connection_accumulating_fact%rowtype;
+ begin
+ if new.connected_time_range is null then
+ -- indicates authorized connection. the update statement in this
+ -- trigger will fail for the authorized state because the row for the
+ -- session connection has not yet been inserted into the
+ -- wh_session_connection_accumulating_fact table.
+ return null;
+ end if;
+
+ if upper(new.connected_time_range) = 'infinity'::timestamptz then
+ update wh_session_connection_accumulating_fact
+ set (connection_connected_date_key,
+ connection_connected_time_key,
+ connection_connected_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ else
+ update wh_session_connection_accumulating_fact
+ set (connection_closed_date_key,
+ connection_closed_time_key,
+ connection_closed_time) = (select wh_date_key(new.update_time),
+ wh_time_key(new.update_time),
+ new.update_time::timestamptz)
+ where connection_id = new.public_id;
+ end if;
+
return null;
- end if;
-
- date_col = 'connection_' || new.state || '_date_key';
- time_col = 'connection_' || new.state || '_time_key';
- ts_col = 'connection_' || new.state || '_time';
-
- q = format('update wh_session_connection_accumulating_fact
- set (%i, %i, %i) = (select wh_date_key(%l), wh_time_key(%l), %l::timestamptz)
- where connection_id = %l
- returning *',
- date_col, time_col, ts_col,
- new.start_time, new.start_time, new.start_time,
- new.connection_id);
- execute q into strict connection_row;
-
- return null;
- end;
+ end;
$$;
Tables
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state_enm.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state_enm.sql
deleted file mode 100644
index 267d87acc..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/public session_connection_state_enm.sql
+++ /dev/null
@@ -1,22 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection.sql b/.schema-diff/tables_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection.sql
index 4fa262e61..8c9fe5bda 100644
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection.sql
+++ b/.schema-diff/tables_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection.sql
@@ -39,6 +39,7 @@ create table public.session_connection (
update_time public.wt_timestamp,
user_client_ip inet,
worker_id public.wt_public_id,
+ connected_time_range tstzrange,
constraint bytes_down_must_be_null_or_a_non_negative_number check (((bytes_down is null) or (bytes_down >= 0))),
constraint bytes_up_must_be_null_or_a_non_negative_number check (((bytes_up is null) or (bytes_up >= 0))),
constraint client_tcp_port_must_be_greater_than_0 check ((client_tcp_port > 0)),
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state.sql
deleted file mode 100644
index 77da8eba7..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state.sql
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state (
- connection_id public.wt_public_id not null,
- state text not null,
- previous_end_time timestamp with time zone,
- start_time timestamp with time zone default current_timestamp not null,
- end_time timestamp with time zone,
- constraint end_times_in_sequence check ((previous_end_time <> end_time)),
- constraint previous_end_time_and_start_time_in_sequence check ((previous_end_time <= start_time)),
- constraint start_and_end_times_in_sequence check ((start_time <= end_time))
-);
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm.sql b/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm.sql
deleted file mode 100644
index 3821fb56b..000000000
--- a/.schema-diff/tables_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm.sql
+++ /dev/null
@@ -1,36 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
-set default_tablespace = '';
-
-set default_table_access_method = heap;
-
---
--- name: session_connection_state_enm; type: table; schema: public; owner: -
---
-
-create table public.session_connection_state_enm (
- name text not null,
- constraint only_predefined_session_connection_states_allowed check ((name = any (array['authorized'::text, 'connected'::text, 'closed'::text])))
-);
-
-
---
--- postgresql database dump complete
---
-
Views
diff --git a/.schema-diff/views_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection_with_status_view.sql b/.schema-diff/views_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection_with_status_view.sql
new file mode 100644
index 000000000..719c23a45
--- /dev/null
+++ b/.schema-diff/views_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection_with_status_view.sql
@@ -0,0 +1,49 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: session_connection_with_status_view; type: view; schema: public; owner: -
+--
+
+create view public.session_connection_with_status_view as
+ select session_connection.public_id,
+ session_connection.session_id,
+ session_connection.client_tcp_address,
+ session_connection.client_tcp_port,
+ session_connection.endpoint_tcp_address,
+ session_connection.endpoint_tcp_port,
+ session_connection.bytes_up,
+ session_connection.bytes_down,
+ session_connection.closed_reason,
+ session_connection.version,
+ session_connection.create_time,
+ session_connection.update_time,
+ session_connection.user_client_ip,
+ session_connection.worker_id,
+ case
+ when (session_connection.connected_time_range is null) then 'authorized'::text
+ when (upper(session_connection.connected_time_range) > now()) then 'connected'::text
+ else 'closed'::text
+ end as status
+ from public.session_connection;
+
+
+--
+-- postgresql database dump complete
+--
+
Triggers
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection insert_new_connection_state.sql b/.schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection check_connection_state_transition.sql
similarity index 64%
rename from .schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection insert_new_connection_state.sql
rename to .schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection check_connection_state_transition.sql
index b419a571d..d04aaa87c 100644
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection insert_new_connection_state.sql
+++ b/.schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection check_connection_state_transition.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection insert_new_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection check_connection_state_transition; type: trigger; schema: public; owner: -
--
-create trigger insert_new_connection_state after insert on public.session_connection for each row execute function public.insert_new_connection_state();
+create trigger check_connection_state_transition before update of connected_time_range on public.session_connection for each row execute function public.check_connection_state_transition();
--
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection update_connection_state_on_closed_reason.sql b/.schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection update_connected_time_range_closed_reason.sql
similarity index 62%
rename from .schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection update_connection_state_on_closed_reason.sql
rename to .schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection update_connected_time_range_closed_reason.sql
index d6b961a23..684ab2326 100644
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection update_connection_state_on_closed_reason.sql
+++ b/.schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection update_connected_time_range_closed_reason.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection update_connection_state_on_closed_reason; type: trigger; schema: public; owner: -
+-- name: session_connection update_connected_time_range_closed_reason; type: trigger; schema: public; owner: -
--
-create trigger update_connection_state_on_closed_reason after update of closed_reason on public.session_connection for each row execute function public.update_connection_state_on_closed_reason();
+create trigger update_connected_time_range_closed_reason before update of closed_reason on public.session_connection for each row execute function public.update_connected_time_range_on_closed_reason();
--
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state wh_insert_session_connection_state.sql b/.schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection wh_insert_session_connection_state.sql
similarity index 64%
rename from .schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state wh_insert_session_connection_state.sql
rename to .schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection wh_insert_session_connection_state.sql
index 346694078..19b1be247 100644
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state wh_insert_session_connection_state.sql
+++ b/.schema-diff/triggers_477519b0ecd46d23d27aa6774519e4be4ca548ae/session_connection wh_insert_session_connection_state.sql
@@ -17,10 +17,10 @@ set client_min_messages = warning;
set row_security = off;
--
--- name: session_connection_state wh_insert_session_connection_state; type: trigger; schema: public; owner: -
+-- name: session_connection wh_insert_session_connection_state; type: trigger; schema: public; owner: -
--
-create trigger wh_insert_session_connection_state after insert on public.session_connection_state for each row execute function public.wh_insert_session_connection_state();
+create trigger wh_insert_session_connection_state after update of connected_time_range on public.session_connection for each row execute function public.wh_insert_session_connection_state();
--
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state immutable_columns.sql b/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state immutable_columns.sql
deleted file mode 100644
index c8546492b..000000000
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state immutable_columns.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state immutable_columns; type: trigger; schema: public; owner: -
---
-
-create trigger immutable_columns before update on public.session_connection_state for each row execute function public.immutable_columns('connection_id', 'state', 'start_time', 'previous_end_time');
-
-
---
--- postgresql database dump complete
---
-
diff --git a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state insert_session_connection_state.sql b/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state insert_session_connection_state.sql
deleted file mode 100644
index 392218f31..000000000
--- a/.schema-diff/triggers_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state insert_session_connection_state.sql
+++ /dev/null
@@ -1,29 +0,0 @@
---
--- postgresql database dump
---
-
--- dumped from database version 13.15
--- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
-
-set statement_timeout = 0;
-set lock_timeout = 0;
-set idle_in_transaction_session_timeout = 0;
-set client_encoding = 'utf8';
-set standard_conforming_strings = on;
-select pg_catalog.set_config('search_path', '', false);
-set check_function_bodies = false;
-set xmloption = content;
-set client_min_messages = warning;
-set row_security = off;
-
---
--- name: session_connection_state insert_session_connection_state; type: trigger; schema: public; owner: -
---
-
-create trigger insert_session_connection_state before insert on public.session_connection_state for each row execute function public.insert_session_connection_state();
-
-
---
--- postgresql database dump complete
---
-
Indexes
diff --git a/.schema-diff/indexes_477519b0ecd46d23d27aa6774519e4be4ca548ae/connected_time_range_idx.sql b/.schema-diff/indexes_477519b0ecd46d23d27aa6774519e4be4ca548ae/connected_time_range_idx.sql
new file mode 100644
index 000000000..66f077ff7
--- /dev/null
+++ b/.schema-diff/indexes_477519b0ecd46d23d27aa6774519e4be4ca548ae/connected_time_range_idx.sql
@@ -0,0 +1,31 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+set default_tablespace = '';
+
+--
+-- name: connected_time_range_idx; type: index; schema: public; owner: -
+--
+
+create index connected_time_range_idx on public.session_connection using btree (connected_time_range);
+
+
+--
+-- postgresql database dump complete
+--
+
diff --git a/.schema-diff/indexes_477519b0ecd46d23d27aa6774519e4be4ca548ae/connected_time_range_upper_idx.sql b/.schema-diff/indexes_477519b0ecd46d23d27aa6774519e4be4ca548ae/connected_time_range_upper_idx.sql
new file mode 100644
index 000000000..928422166
--- /dev/null
+++ b/.schema-diff/indexes_477519b0ecd46d23d27aa6774519e4be4ca548ae/connected_time_range_upper_idx.sql
@@ -0,0 +1,31 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+set default_tablespace = '';
+
+--
+-- name: connected_time_range_upper_idx; type: index; schema: public; owner: -
+--
+
+create index connected_time_range_upper_idx on public.session_connection using btree (upper(connected_time_range));
+
+
+--
+-- postgresql database dump complete
+--
+
Constraints
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_end_time_uq.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_end_time_uq.sql
deleted file mode 100644
index 144fc4c80..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_end_time_uq unique (connection_id, end_time);
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_uq.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_uq.sql
deleted file mode 100644
index bc22838ee..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_uq.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_uq; type: constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_uq unique (connection_id, previous_end_time);
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_pkey.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_pkey.sql
deleted file mode 100644
index 969d9a67c..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state_enm session_connection_state_enm_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_enm_pkey primary key (name);
diff --git a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_pkey.sql b/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_pkey.sql
deleted file mode 100644
index 7e3c2d4e5..000000000
--- a/.schema-diff/constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_pkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_pkey; type: constraint; schema: public; owner: -
- add constraint session_connection_state_pkey primary key (connection_id, start_time);
Foreign Key Constraints
diff --git a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_fkey.sql b/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_fkey.sql
deleted file mode 100644
index cf978ee15..000000000
--- a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_fkey foreign key (connection_id) references public.session_connection(public_id) on update cascade on delete cascade;
diff --git a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_fkey.sql b/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_fkey.sql
deleted file mode 100644
index 3ba011432..000000000
--- a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_connection_id_previous_end_time_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_connection_id_previous_end_time_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_connection_id_previous_end_time_fkey foreign key (connection_id, previous_end_time) references public.session_connection_state(connection_id, end_time);
diff --git a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_state_fkey.sql b/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_state_fkey.sql
deleted file mode 100644
index ab6be27b9..000000000
--- a/.schema-diff/fk_constraints_85f98a4a678cb56286a5862c2fb76d34abbb12cc/session_connection_state_enm_state_fkey.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- name: session_connection_state session_connection_state_enm_state_fkey; type: fk constraint; schema: public; owner: -
- add constraint session_connection_state_enm_state_fkey foreign key (state) references public.session_connection_state_enm(name) on update cascade on delete restrict;