deleçao de contas web
This commit is contained in:
35
backend/db/migrations/00003_web_account_delete.sql
Normal file
35
backend/db/migrations/00003_web_account_delete.sql
Normal 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;
|
||||
Reference in New Issue
Block a user