Files
threshold/internal/db/sqltest/tests/wh/session/update_state.sql
T
Timothy Messier a2ef14283b fix(org): Address bug that prevented deleting an org (#2465)
The schema changes introduced in 0.10.2 introduced a bug where an org
could not be deleted if there was a session for an org scoped user. It
would result in an error like:

    scope.(Service).deleteFromRepo: unable to delete scope: \
        iam.(Repository).DeleteScope: failed for o_VkNy46KwfS: \
        iam.(Repository).delete: db.DoTx: iam.(Repository).delete: \
        db.Delete: insert or update on table "session" violates foreign key constraint "target_fkey": integrity violation: error #1003

A worker around would be to first delete all projects in the org, then
finally delete the org.

This fix adds a regression test to the sqltests and updates several
constraints on the session table to be deferrable. Since the org delete
is a single transaction, this allows all of the necessary resources to
be deleted before attempting to enforce these constrains.

See: https://www.postgresql.org/docs/current/sql-set-constraints.html
Blame: 3a28ab614
2022-09-19 09:47:52 -04:00

25 lines
1.3 KiB
PL/PgSQL

begin;
select plan(8);
select is(count(*), 1::bigint) from wh_session_accumulating_fact where session_id = 's1_____clare';
select is(total_bytes_up, null) from wh_session_accumulating_fact where session_id = 's1_____clare';
select is(total_bytes_down, null) from wh_session_accumulating_fact where session_id = 's1_____clare';
select is(session_terminated_time, 'infinity'::wh_timestamp) from wh_session_accumulating_fact where session_id = 's1_____clare';
update session_connection set
bytes_up = 10,
bytes_down = 5,
closed_reason = 'closed by end-user'
where public_id = 'sc1_____clare';
update session set
termination_reason = 'closed by end-user'
where public_id = 's1_____clare';
select is(count(*), 1::bigint) from wh_session_accumulating_fact where session_id = 's1_____clare';
select is(total_bytes_up, 10::wh_bytes_transmitted) from wh_session_accumulating_fact where session_id = 's1_____clare';
select is(total_bytes_down, 5::wh_bytes_transmitted) from wh_session_accumulating_fact where session_id = 's1_____clare';
select is(session_terminated_time, now()::wh_timestamp) from wh_session_accumulating_fact where session_id = 's1_____clare';
select * from finish();
rollback;