Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

irenarindos
Copy link
Collaborator

WIP

This PR removes the session_connection_state table, replacing it with the new field connected_time_range on session_connection

Comment on lines 27 to 34
drop table session_connection_state;
drop table session_connection_state_enm;

-- If the connected_time_range is null, it means the connection is authorized but not connected.
-- If the upper value of connected_time_range is > now() (upper range is infinity) then the state is connected.
-- If the upper value of connected_time_range is <= now() then the connection is closed.
alter table session_connection
add column connected_time_range tstzrange;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add the column and migrate the data from session_connection_state?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth migrating? I'm assuming that the control plane would go down for maintenance, and if we regularly remove terminated sessions from the db it seems like we should be fine to drop that table because sessions should be in a terminated state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should migrate the data. We only delete the sessions after they have been terminated for an hour. So once the controllers are back up there will be an hour before the previous sessions are deleted, and I think we should report an accurate connection state for that time period.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a migration; unfortunately I can't add a migration test because of the code changes, but I've manually tested it.

@irenarindos irenarindos force-pushed the irindos-session-connection-states branch 5 times, most recently from 993b4b3 to 17b5bc3 Compare April 29, 2024 19:56
@irenarindos irenarindos force-pushed the irindos-session-connection-states branch from 17b5bc3 to ea418af Compare April 30, 2024 16:17
Copy link
Member

@tmessi tmessi left a 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.

@psekar psekar modified the milestones: deferred, 0.16.x May 16, 2024
@irenarindos irenarindos requested a review from tmessi June 10, 2024 19:39
@irenarindos irenarindos marked this pull request as ready for review June 11, 2024 12:17
Copy link

Database schema diff between main and irindos-session-connection-states @ 25816ce

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants