Skip to content

Commit

Permalink
condenses postgres sql, reverts statement_to_actor table desc on pg
Browse files Browse the repository at this point in the history
  • Loading branch information
invaliduser committed Sep 7, 2023
1 parent 5617323 commit 0d98a22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
8 changes: 1 addition & 7 deletions src/db/postgres/lrsql/postgres/record.clj
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,7 @@
(-update-actor! [_ tx input]
(update-actor! tx input))
(-delete-actor! [_ tx input]
(delete-actor-st2st tx input)
(delete-actor-st2activ tx input)
(delete-actor-attachments tx input)
(delete-actor-statements tx input)
(delete-actor-agent-profile tx input)
(delete-actor-state-document tx input)
(delete-actor-actor tx input))
(delete-actor-and-dependents! tx input))
(-query-actor [_ tx input]
(query-actor tx input))

Expand Down
4 changes: 1 addition & 3 deletions src/db/postgres/lrsql/postgres/sql/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ CREATE TABLE IF NOT EXISTS statement_to_actor (
actor_ifi VARCHAR(255) NOT NULL,
actor_type actor_type_enum NOT NULL,
CONSTRAINT statement_fk
FOREIGN KEY (statement_id) REFERENCES xapi_statement(statement_id)
ON DELETE CASCADE,
FOREIGN KEY (statement_id) REFERENCES xapi_statement(statement_id),
CONSTRAINT actor_fk
FOREIGN KEY (actor_ifi, actor_type) REFERENCES actor(actor_ifi, actor_type)
ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS stmt_actor_stmt_fk ON statement_to_actor(statement_id);
CREATE INDEX IF NOT EXISTS stmt_actor_actor_fk ON statement_to_actor(actor_ifi, actor_type);
Expand Down
36 changes: 10 additions & 26 deletions src/db/postgres/lrsql/postgres/sql/delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,44 +63,28 @@ AND secret_key = :secret-key
AND scope = :scope::scope_enum;

----------------------begin components of delete-actor-----
-- :name delete-actor-st2st
-- :name delete-actor-and-dependents!
-- :command :execute
-- :result :affected
DELETE FROM statement_to_statement
WHERE ancestor_id IN (SELECT statement_id FROM statement_to_actor
WHERE actor_ifi = :actor-ifi)
OR descendant_id IN (SELECT statement_id FROM statement_to_actor
WHERE actor_ifi = :actor-ifi)
WHERE actor_ifi = :actor-ifi);

-- :name delete-actor-st2activ
-- :command :execute
-- :result :affected
DELETE FROM statement_to_activity WHERE statement_id IN (SELECT statement_id FROM statement_to_actor
WHERE actor_ifi = :actor-ifi)
WHERE actor_ifi = :actor-ifi);

-- :name delete-actor-attachments
-- :command :execute
-- :result :affected
DELETE FROM attachment WHERE statement_id IN (SELECT statement_id FROM statement_to_actor
WHERE actor_ifi = :actor-ifi)
WHERE actor_ifi = :actor-ifi);

-- :name delete-actor-statements
-- :command :execute
-- :result :affected
DELETE FROM xapi_statement WHERE statement_id IN (SELECT statement_id FROM statement_to_actor
WHERE actor_ifi = :actor-ifi)
WHERE actor_ifi = :actor-ifi);

-- :name delete-actor-agent-profile
-- :command :execute
-- :result :affected
DELETE FROM agent_profile_document WHERE agent_ifi = :actor-ifi

-- :name delete-actor-state-document
-- :command :execute
-- :result :affected
DELETE FROM state_document WHERE agent_ifi = :actor-ifi
DELETE FROM agent_profile_document WHERE agent_ifi = :actor-ifi;

-- :name delete-actor-actor
-- :command :execute
-- :result :affected
DELETE FROM actor where actor_ifi = :actor-ifi
DELETE FROM state_document WHERE agent_ifi = :actor-ifi;

DELETE FROM actor where actor_ifi = :actor-ifi;
------------------end delete-actor--------------------

0 comments on commit 0d98a22

Please sign in to comment.