Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions util/src/main/resources/cleanAccount-postgresql.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
CREATE OR REPLACE PROCEDURE cleanAccount(p_account_id varchar(36)) LANGUAGE plpgsql
AS $$
DECLARE
v_account_record_id bigint;
v_tenant_record_id bigint;

BEGIN
select record_id, tenant_record_id from accounts WHERE id = p_account_id into v_account_record_id, v_tenant_record_id;

call trimAccount(p_account_id);

DELETE FROM account_history WHERE target_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM accounts WHERE record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM audit_log WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_method_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_methods WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
END
$$;
CREATE OR REPLACE PROCEDURE cleanAccount(p_account_ids varchar(36)[]) LANGUAGE plpgsql
AS $$
DECLARE
v_account_record_id bigint;
v_tenant_record_id bigint;
BEGIN
FOREACH p_account_id IN ARRAY p_account_ids
LOOP
select record_id, tenant_record_id from accounts WHERE id = p_account_id into v_account_record_id, v_tenant_record_id;
call trimAccount(p_account_id);
DELETE FROM account_history WHERE target_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM accounts WHERE record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM audit_log WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_method_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_methods WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
END LOOP;
END
$$;
28 changes: 16 additions & 12 deletions util/src/main/resources/cleanAccount.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ CREATE PROCEDURE cleanAccount(p_account_id varchar(36))
BEGIN

DECLARE v_account_record_id bigint /*! unsigned */;
DECLARE v_tenant_record_id bigint /*! unsigned */;

select record_id, tenant_record_id from accounts WHERE id = p_account_id into v_account_record_id, v_tenant_record_id;

call trimAccount(p_account_id);

DELETE FROM account_history WHERE target_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM accounts WHERE record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM audit_log WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_method_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_methods WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;

CREATE PROCEDURE cleanAccount(p_account_ids varchar(36)[])
BEGIN
DECLARE v_account_record_id bigint /*! unsigned */;
DECLARE v_tenant_record_id bigint /*! unsigned */;
DECLARE i INT DEFAULT 0;
WHILE i < LENGTH(p_account_ids) DO
select record_id, tenant_record_id from accounts WHERE id = p_account_ids[i] into v_account_record_id, v_tenant_record_id;
call trimAccount(p_account_ids[i]);
DELETE FROM account_history WHERE target_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM accounts WHERE record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM audit_log WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_method_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_methods WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
SET i = i + 1;
END WHILE;
END;
END;
//
DELIMITER ;
89 changes: 46 additions & 43 deletions util/src/main/resources/trimAccount-postgresql.sql
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
CREATE OR REPLACE PROCEDURE trimAccount(p_account_id varchar(36)) LANGUAGE plpgsql
AS $$
CREATE OR REPLACE PROCEDURE trimAccount(p_account_ids varchar(36)[]) LANGUAGE plpgsql
AS $$
DECLARE
v_account_record_id bigint;
v_tenant_record_id bigint;

BEGIN
select record_id, tenant_record_id from accounts WHERE id = p_account_id into v_account_record_id, v_tenant_record_id;

DELETE FROM account_email_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM account_emails WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM audit_log WHERE table_name not in ('ACCOUNT_HISTORY', 'PAYMENT_METHOD_HISTORY') and account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM blocking_state_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM blocking_states WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM bundle_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM bundles WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM bus_events WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM bus_events_history WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM bus_ext_events WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM bus_ext_events_history WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM custom_field_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM custom_fields WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_billing_events WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_item_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_items WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_parent_children WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_payment_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_payments WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoices WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_tracking_id_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_tracking_ids WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_payment_control_plugin_auto_pay_off WHERE account_id = p_account_id;
DELETE FROM notifications WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM notifications_history WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM payment_attempt_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_attempts WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_transaction_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_transactions WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payments WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM rolled_up_usage WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscription_event_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscription_events WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscription_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscriptions WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM tag_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM tags WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;

FOREACH p_account_id IN ARRAY p_account_ids
LOOP
select record_id, tenant_record_id from accounts WHERE id = p_account_id into v_account_record_id, v_tenant_record_id;
DELETE FROM account_email_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM account_emails WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM audit_log WHERE table_name not in ('ACCOUNT_HISTORY', 'PAYMENT_METHOD_HISTORY') and account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM blocking_state_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM blocking_states WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM bundle_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM bundles WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM bus_events WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM bus_events_history WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM bus_ext_events WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM bus_ext_events_history WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM custom_field_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM custom_fields WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_billing_events WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_item_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_items WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_parent_children WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_payment_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_payments WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoices WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_tracking_id_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_tracking_ids WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM invoice_payment_control_plugin_auto_pay_off WHERE account_id = p_account_id;
DELETE FROM notifications WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM notifications_history WHERE search_key1 = v_account_record_id and search_key2 = v_tenant_record_id;
DELETE FROM payment_attempt_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_attempts WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_transaction_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payment_transactions WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM payments WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM rolled_up_usage WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscription_event_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscription_events WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscription_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM subscriptions WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM tag_history WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
DELETE FROM tags WHERE account_record_id = v_account_record_id and tenant_record_id = v_tenant_record_id;
END LOOP;
END
$$;
$$;
Loading