deleçao de contas web

This commit is contained in:
2026-10-30 23:25:38 -03:00
parent 61fde19133
commit f0560b1be4
16 changed files with 1250 additions and 10 deletions

View File

@@ -0,0 +1,35 @@
-- Permite excluir contas do painel sem perder a auditoria.
-- Sessões da conta são apagadas junto; auditoria e configurações perdem só o
-- vínculo, e a auditoria guarda o nome da conta em actor_account_name.
-- +goose Up
ALTER TABLE audit_logs ADD COLUMN actor_account_name text;
UPDATE audit_logs a SET actor_account_name = wa.username::text
FROM web_accounts wa WHERE wa.id = a.actor_account;
ALTER TABLE web_sessions DROP CONSTRAINT web_sessions_account_id_fkey;
ALTER TABLE web_sessions ADD CONSTRAINT web_sessions_account_id_fkey
FOREIGN KEY (account_id) REFERENCES web_accounts(id) ON DELETE CASCADE;
ALTER TABLE audit_logs DROP CONSTRAINT audit_logs_actor_account_fkey;
ALTER TABLE audit_logs ADD CONSTRAINT audit_logs_actor_account_fkey
FOREIGN KEY (actor_account) REFERENCES web_accounts(id) ON DELETE SET NULL;
ALTER TABLE app_settings DROP CONSTRAINT app_settings_updated_by_account_fkey;
ALTER TABLE app_settings ADD CONSTRAINT app_settings_updated_by_account_fkey
FOREIGN KEY (updated_by_account) REFERENCES web_accounts(id) ON DELETE SET NULL;
-- +goose Down
ALTER TABLE app_settings DROP CONSTRAINT app_settings_updated_by_account_fkey;
ALTER TABLE app_settings ADD CONSTRAINT app_settings_updated_by_account_fkey
FOREIGN KEY (updated_by_account) REFERENCES web_accounts(id);
ALTER TABLE audit_logs DROP CONSTRAINT audit_logs_actor_account_fkey;
ALTER TABLE audit_logs ADD CONSTRAINT audit_logs_actor_account_fkey
FOREIGN KEY (actor_account) REFERENCES web_accounts(id);
ALTER TABLE web_sessions DROP CONSTRAINT web_sessions_account_id_fkey;
ALTER TABLE web_sessions ADD CONSTRAINT web_sessions_account_id_fkey
FOREIGN KEY (account_id) REFERENCES web_accounts(id);
ALTER TABLE audit_logs DROP COLUMN actor_account_name;