-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refact(session connection): remove session connection state table #4617
Conversation
internal/db/schema/migrations/oss/postgres/87/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
17b5bc3
to
ea418af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to review the go code, but I have a few comments/requests on the sql.
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/sqltest/tests/session/session_connection_state_transition.sql
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still reviewing the go changes, but I have some comments on the sql if you want to take a look at those first.
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
internal/db/schema/migrations/oss/postgres/88/01_remove_session_connection_state.up.sql
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
987245b
to
aa06486
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
53fc8ad
to
4f6e44c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Database schema diff between To understand how these diffs are generated and some limitations see the Functionsdiff --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;
$$;
Tablesdiff --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
---
- Viewsdiff --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
+--
+ Triggersdiff --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
---
- Indexesdiff --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
+--
+ Constraintsdiff --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 Constraintsdiff --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; |
WIP
This PR removes the
session_connection_state
table, replacing it with the new fieldconnected_time_range
onsession_connection